Mercurial > vim
annotate src/normal.c @ 13380:69517d67421f v8.0.1564
patch 8.0.1564: too many #ifdefs
commit https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 4 18:08:14 2018 +0100
patch 8.0.1564: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and
increases code size of tiny Vim by only 40 Kbyte.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 04 Mar 2018 18:15:08 +0100 |
parents | 244ff1b6d2ad |
children | 6740c499de13 |
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 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
172 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
|
173 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 174 |
1728 | 175 static char *e_noident = N_("E349: No identifier under cursor"); |
176 | |
7 | 177 /* |
178 * Function to be called for a Normal or Visual mode command. | |
179 * The argument is a cmdarg_T. | |
180 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
181 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 182 |
183 /* Values for cmd_flags. */ | |
184 #define NV_NCH 0x01 /* may need to get a second char */ | |
185 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
186 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
187 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
188 | |
189 #define NV_SS 0x10 /* may start selection */ | |
190 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
191 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
192 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
193 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
194 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
195 | |
196 /* | |
197 * Generally speaking, every Normal mode command should either clear any | |
198 * pending operator (with *clearop*()), or set the motion type variable | |
199 * oap->motion_type. | |
200 * | |
201 * When a cursor motion command is made, it is marked as being a character or | |
202 * line oriented motion. Then, if an operator is in effect, the operation | |
203 * becomes character or line oriented accordingly. | |
204 */ | |
205 | |
206 /* | |
207 * This table contains one entry for every Normal or Visual mode command. | |
208 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
209 * It is faster when all keys from zero to '~' are present. | |
210 */ | |
211 static const struct nv_cmd | |
212 { | |
213 int cmd_char; /* (first) command character */ | |
214 nv_func_T cmd_func; /* function for this command */ | |
215 short_u cmd_flags; /* NV_ flags */ | |
216 short cmd_arg; /* value for ca.arg */ | |
217 } nv_cmds[] = | |
218 { | |
219 {NUL, nv_error, 0, 0}, | |
220 {Ctrl_A, nv_addsub, 0, 0}, | |
221 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
222 {Ctrl_C, nv_esc, 0, TRUE}, | |
223 {Ctrl_D, nv_halfpage, 0, 0}, | |
224 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
225 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
226 {Ctrl_G, nv_ctrlg, 0, 0}, | |
227 {Ctrl_H, nv_ctrlh, 0, 0}, | |
228 {Ctrl_I, nv_pcmark, 0, 0}, | |
229 {NL, nv_down, 0, FALSE}, | |
230 {Ctrl_K, nv_error, 0, 0}, | |
231 {Ctrl_L, nv_clear, 0, 0}, | |
376 | 232 {Ctrl_M, nv_down, 0, TRUE}, |
7 | 233 {Ctrl_N, nv_down, NV_STS, FALSE}, |
234 {Ctrl_O, nv_ctrlo, 0, 0}, | |
235 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 236 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 237 {Ctrl_R, nv_redo, 0, 0}, |
238 {Ctrl_S, nv_ignore, 0, 0}, | |
239 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
240 {Ctrl_U, nv_halfpage, 0, 0}, | |
241 {Ctrl_V, nv_visual, 0, FALSE}, | |
242 {'V', nv_visual, 0, FALSE}, | |
243 {'v', nv_visual, 0, FALSE}, | |
244 {Ctrl_W, nv_window, 0, 0}, | |
245 {Ctrl_X, nv_addsub, 0, 0}, | |
246 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
247 {Ctrl_Z, nv_suspend, 0, 0}, | |
248 {ESC, nv_esc, 0, FALSE}, | |
249 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
250 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
251 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
252 {Ctrl__, nv_error, 0, 0}, | |
253 {' ', nv_right, 0, 0}, | |
254 {'!', nv_operator, 0, 0}, | |
255 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
256 {'#', nv_ident, 0, 0}, | |
257 {'$', nv_dollar, 0, 0}, | |
258 {'%', nv_percent, 0, 0}, | |
259 {'&', nv_optrans, 0, 0}, | |
260 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
261 {'(', nv_brace, 0, BACKWARD}, | |
262 {')', nv_brace, 0, FORWARD}, | |
263 {'*', nv_ident, 0, 0}, | |
264 {'+', nv_down, 0, TRUE}, | |
265 {',', nv_csearch, 0, TRUE}, | |
266 {'-', nv_up, 0, TRUE}, | |
267 {'.', nv_dot, NV_KEEPREG, 0}, | |
268 {'/', nv_search, 0, FALSE}, | |
269 {'0', nv_beginline, 0, 0}, | |
270 {'1', nv_ignore, 0, 0}, | |
271 {'2', nv_ignore, 0, 0}, | |
272 {'3', nv_ignore, 0, 0}, | |
273 {'4', nv_ignore, 0, 0}, | |
274 {'5', nv_ignore, 0, 0}, | |
275 {'6', nv_ignore, 0, 0}, | |
276 {'7', nv_ignore, 0, 0}, | |
277 {'8', nv_ignore, 0, 0}, | |
278 {'9', nv_ignore, 0, 0}, | |
279 {':', nv_colon, 0, 0}, | |
280 {';', nv_csearch, 0, FALSE}, | |
281 {'<', nv_operator, NV_RL, 0}, | |
282 {'=', nv_operator, 0, 0}, | |
283 {'>', nv_operator, NV_RL, 0}, | |
284 {'?', nv_search, 0, FALSE}, | |
285 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
286 {'A', nv_edit, 0, 0}, | |
287 {'B', nv_bck_word, 0, 1}, | |
288 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
289 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
290 {'E', nv_wordcmd, 0, TRUE}, | |
291 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
292 {'G', nv_goto, 0, TRUE}, | |
293 {'H', nv_scroll, 0, 0}, | |
294 {'I', nv_edit, 0, 0}, | |
295 {'J', nv_join, 0, 0}, | |
296 {'K', nv_ident, 0, 0}, | |
297 {'L', nv_scroll, 0, 0}, | |
298 {'M', nv_scroll, 0, 0}, | |
299 {'N', nv_next, 0, SEARCH_REV}, | |
300 {'O', nv_open, 0, 0}, | |
301 {'P', nv_put, 0, 0}, | |
302 {'Q', nv_exmode, NV_NCW, 0}, | |
303 {'R', nv_Replace, 0, FALSE}, | |
304 {'S', nv_subst, NV_KEEPREG, 0}, | |
305 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
306 {'U', nv_Undo, 0, 0}, | |
307 {'W', nv_wordcmd, 0, TRUE}, | |
308 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
309 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
310 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
311 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
312 {'\\', nv_error, 0, 0}, | |
313 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
314 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
315 {'_', nv_lineop, 0, 0}, | |
316 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
317 {'a', nv_edit, NV_NCH, 0}, | |
318 {'b', nv_bck_word, 0, 0}, | |
319 {'c', nv_operator, 0, 0}, | |
320 {'d', nv_operator, 0, 0}, | |
321 {'e', nv_wordcmd, 0, FALSE}, | |
322 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
323 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
324 {'h', nv_left, NV_RL, 0}, | |
325 {'i', nv_edit, NV_NCH, 0}, | |
326 {'j', nv_down, 0, FALSE}, | |
327 {'k', nv_up, 0, FALSE}, | |
328 {'l', nv_right, NV_RL, 0}, | |
329 {'m', nv_mark, NV_NCH_NOP, 0}, | |
330 {'n', nv_next, 0, 0}, | |
331 {'o', nv_open, 0, 0}, | |
332 {'p', nv_put, 0, 0}, | |
333 {'q', nv_record, NV_NCH, 0}, | |
334 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
335 {'s', nv_subst, NV_KEEPREG, 0}, | |
336 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
337 {'u', nv_undo, 0, 0}, | |
338 {'w', nv_wordcmd, 0, FALSE}, | |
339 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
340 {'y', nv_operator, 0, 0}, | |
341 {'z', nv_zet, NV_NCH_ALW, 0}, | |
342 {'{', nv_findpar, 0, BACKWARD}, | |
343 {'|', nv_pipe, 0, 0}, | |
344 {'}', nv_findpar, 0, FORWARD}, | |
345 {'~', nv_tilde, 0, 0}, | |
346 | |
347 /* pound sign */ | |
348 {POUND, nv_ident, 0, 0}, | |
349 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
350 {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
|
351 {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
|
352 {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
|
353 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 354 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
355 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
356 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
357 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
358 {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
|
359 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 360 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
361 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
362 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
363 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
364 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
365 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
366 {K_X1MOUSE, nv_mouse, 0, 0}, | |
367 {K_X1DRAG, nv_mouse, 0, 0}, | |
368 {K_X1RELEASE, nv_mouse, 0, 0}, | |
369 {K_X2MOUSE, nv_mouse, 0, 0}, | |
370 {K_X2DRAG, nv_mouse, 0, 0}, | |
371 {K_X2RELEASE, nv_mouse, 0, 0}, | |
372 #endif | |
819 | 373 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 374 {K_NOP, nv_nop, 0, 0}, |
7 | 375 {K_INS, nv_edit, 0, 0}, |
376 {K_KINS, nv_edit, 0, 0}, | |
377 {K_BS, nv_ctrlh, 0, 0}, | |
378 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
379 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
380 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
381 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
382 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
383 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
384 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
385 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
386 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
387 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
388 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
389 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
390 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
391 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
392 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
393 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
394 {K_S_END, nv_end, NV_SS, FALSE}, | |
395 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
396 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
397 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
398 {K_S_HOME, nv_home, NV_SS, 0}, | |
399 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
400 {K_DEL, nv_abbrev, 0, 0}, | |
401 {K_KDEL, nv_abbrev, 0, 0}, | |
402 {K_UNDO, nv_kundo, 0, 0}, | |
403 {K_HELP, nv_help, NV_NCW, 0}, | |
404 {K_F1, nv_help, NV_NCW, 0}, | |
405 {K_XF1, nv_help, NV_NCW, 0}, | |
406 {K_SELECT, nv_select, 0, 0}, | |
407 #ifdef FEAT_GUI | |
408 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
409 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
410 #endif | |
685 | 411 #ifdef FEAT_GUI_TABLINE |
412 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 413 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 414 #endif |
7 | 415 #ifdef FEAT_FKMAP |
9399
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
416 {K_F8, farsi_f8, 0, 0}, |
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
417 {K_F9, farsi_f9, 0, 0}, |
7 | 418 #endif |
419 #ifdef FEAT_NETBEANS_INTG | |
420 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
421 #endif | |
422 #ifdef FEAT_DND | |
423 {K_DROP, nv_drop, NV_STS, 0}, | |
424 #endif | |
819 | 425 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
426 {K_PS, nv_edit, 0, 0}, |
7 | 427 }; |
428 | |
429 /* Number of commands in nv_cmds[]. */ | |
430 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
431 | |
432 /* Sorted index of commands in nv_cmds[]. */ | |
433 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
434 | |
435 /* The highest index for which | |
436 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
437 static int nv_max_linear; | |
438 | |
439 /* | |
440 * Compare functions for qsort() below, that checks the command character | |
441 * through the index in nv_cmd_idx[]. | |
442 */ | |
443 static int | |
444 #ifdef __BORLANDC__ | |
445 _RTLENTRYF | |
446 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
447 nv_compare(const void *s1, const void *s2) |
7 | 448 { |
449 int c1, c2; | |
450 | |
451 /* The commands are sorted on absolute value. */ | |
452 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
453 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
454 if (c1 < 0) | |
455 c1 = -c1; | |
456 if (c2 < 0) | |
457 c2 = -c2; | |
458 return c1 - c2; | |
459 } | |
460 | |
461 /* | |
462 * Initialize the nv_cmd_idx[] table. | |
463 */ | |
464 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
465 init_normal_cmds(void) |
7 | 466 { |
467 int i; | |
468 | |
469 /* Fill the index table with a one to one relation. */ | |
1877 | 470 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 471 nv_cmd_idx[i] = i; |
472 | |
473 /* Sort the commands by the command character. */ | |
474 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
475 | |
476 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 477 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 478 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
479 break; | |
480 nv_max_linear = i - 1; | |
481 } | |
482 | |
483 /* | |
484 * Search for a command in the commands table. | |
485 * Returns -1 for invalid command. | |
486 */ | |
487 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
488 find_command(int cmdchar) |
7 | 489 { |
490 int i; | |
491 int idx; | |
492 int top, bot; | |
493 int c; | |
494 | |
495 #ifdef FEAT_MBYTE | |
496 /* A multi-byte character is never a command. */ | |
497 if (cmdchar >= 0x100) | |
498 return -1; | |
499 #endif | |
500 | |
501 /* We use the absolute value of the character. Special keys have a | |
502 * negative value, but are sorted on their absolute value. */ | |
503 if (cmdchar < 0) | |
504 cmdchar = -cmdchar; | |
505 | |
506 /* If the character is in the first part: The character is the index into | |
507 * nv_cmd_idx[]. */ | |
508 if (cmdchar <= nv_max_linear) | |
509 return nv_cmd_idx[cmdchar]; | |
510 | |
511 /* Perform a binary search. */ | |
512 bot = nv_max_linear + 1; | |
513 top = NV_CMDS_SIZE - 1; | |
514 idx = -1; | |
515 while (bot <= top) | |
516 { | |
517 i = (top + bot) / 2; | |
518 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
519 if (c < 0) | |
520 c = -c; | |
521 if (cmdchar == c) | |
522 { | |
523 idx = nv_cmd_idx[i]; | |
524 break; | |
525 } | |
526 if (cmdchar > c) | |
527 bot = i + 1; | |
528 else | |
529 top = i - 1; | |
530 } | |
531 return idx; | |
532 } | |
533 | |
534 /* | |
535 * Execute a command in Normal mode. | |
536 */ | |
537 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
538 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
539 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
540 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 541 { |
542 cmdarg_T ca; /* command arguments */ | |
543 int c; | |
544 int ctrl_w = FALSE; /* got CTRL-W command */ | |
545 int old_col = curwin->w_curswant; | |
546 #ifdef FEAT_CMDL_INFO | |
547 int need_flushbuf; /* need to call out_flush() */ | |
548 #endif | |
549 pos_T old_pos; /* cursor position before command */ | |
550 int mapped_len; | |
551 static int old_mapped_len = 0; | |
552 int idx; | |
1751 | 553 #ifdef FEAT_EVAL |
554 int set_prevcount = FALSE; | |
555 #endif | |
7 | 556 |
557 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
558 ca.oap = oap; | |
1692 | 559 |
560 /* Use a count remembered from before entering an operator. After typing | |
561 * "3d" we return from normal_cmd() and come back here, the "3" is | |
562 * remembered in "opcount". */ | |
7 | 563 ca.opcount = opcount; |
564 | |
565 /* | |
566 * If there is an operator pending, then the command we take this time | |
567 * will terminate it. Finish_op tells us to finish the operation before | |
568 * returning this time (unless the operation was cancelled). | |
569 */ | |
570 #ifdef CURSOR_SHAPE | |
571 c = finish_op; | |
572 #endif | |
573 finish_op = (oap->op_type != OP_NOP); | |
574 #ifdef CURSOR_SHAPE | |
575 if (finish_op != c) | |
576 { | |
577 ui_cursor_shape(); /* may show different cursor shape */ | |
578 # ifdef FEAT_MOUSESHAPE | |
579 update_mouseshape(-1); | |
580 # endif | |
581 } | |
582 #endif | |
583 | |
1692 | 584 /* When not finishing an operator and no register name typed, reset the |
585 * count. */ | |
7 | 586 if (!finish_op && !oap->regname) |
1751 | 587 { |
7 | 588 ca.opcount = 0; |
1751 | 589 #ifdef FEAT_EVAL |
590 set_prevcount = TRUE; | |
591 #endif | |
592 } | |
7 | 593 |
1692 | 594 /* Restore counts from before receiving K_CURSORHOLD. This means after |
595 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
596 * "3 * 2". */ | |
597 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
598 { | |
599 ca.opcount = oap->prev_opcount; | |
600 ca.count0 = oap->prev_count0; | |
601 oap->prev_opcount = 0; | |
602 oap->prev_count0 = 0; | |
603 } | |
604 | |
7 | 605 mapped_len = typebuf_maplen(); |
606 | |
607 State = NORMAL_BUSY; | |
608 #ifdef USE_ON_FLY_SCROLL | |
609 dont_scroll = FALSE; /* allow scrolling here */ | |
610 #endif | |
611 | |
2667 | 612 #ifdef FEAT_EVAL |
613 /* Set v:count here, when called from main() and not a stuffed | |
614 * command, so that v:count can be used in an expression mapping | |
5649 | 615 * when there is no count. Do set it for redo. */ |
616 if (toplevel && readbuf1_empty()) | |
2667 | 617 set_vcount_ca(&ca, &set_prevcount); |
618 #endif | |
619 | |
7 | 620 /* |
621 * Get the command character from the user. | |
622 */ | |
623 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
624 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 625 |
626 /* | |
627 * If a mapping was started in Visual or Select mode, remember the length | |
628 * of the mapping. This is used below to not return to Insert mode for as | |
629 * long as the mapping is being executed. | |
630 */ | |
631 if (restart_edit == 0) | |
632 old_mapped_len = 0; | |
633 else if (old_mapped_len | |
819 | 634 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 635 old_mapped_len = typebuf_maplen(); |
636 | |
637 if (c == NUL) | |
638 c = K_ZERO; | |
639 | |
640 /* | |
641 * In Select mode, typed text replaces the selection. | |
642 */ | |
643 if (VIsual_active | |
644 && VIsual_select | |
645 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
646 { | |
275 | 647 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
648 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
649 * restart automatically. | |
1051 | 650 * Insert the typed character in the typeahead buffer, so that it can |
651 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 652 ins_char_typebuf(c); |
275 | 653 if (restart_edit != 0) |
654 c = 'd'; | |
655 else | |
656 c = 'c'; | |
695 | 657 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 658 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 659 } |
660 | |
661 #ifdef FEAT_CMDL_INFO | |
662 need_flushbuf = add_to_showcmd(c); | |
663 #endif | |
664 | |
665 getcount: | |
666 if (!(VIsual_active && VIsual_select)) | |
667 { | |
668 /* | |
669 * Handle a count before a command and compute ca.count0. | |
670 * Note that '0' is a command and not the start of a count, but it's | |
671 * part of a count after other digits. | |
672 */ | |
673 while ( (c >= '1' && c <= '9') | |
674 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
675 { | |
676 if (c == K_DEL || c == K_KDEL) | |
677 { | |
678 ca.count0 /= 10; | |
679 #ifdef FEAT_CMDL_INFO | |
680 del_from_showcmd(4); /* delete the digit and ~@% */ | |
681 #endif | |
682 } | |
683 else | |
684 ca.count0 = ca.count0 * 10 + (c - '0'); | |
685 if (ca.count0 < 0) /* got too large! */ | |
686 ca.count0 = 999999999L; | |
1425 | 687 #ifdef FEAT_EVAL |
688 /* Set v:count here, when called from main() and not a stuffed | |
689 * command, so that v:count can be used in an expression mapping | |
5649 | 690 * right after the count. Do set it for redo. */ |
691 if (toplevel && readbuf1_empty()) | |
2667 | 692 set_vcount_ca(&ca, &set_prevcount); |
1425 | 693 #endif |
7 | 694 if (ctrl_w) |
695 { | |
696 ++no_mapping; | |
697 ++allow_keys; /* no mapping for nchar, but keys */ | |
698 } | |
699 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 700 c = plain_vgetc(); |
7 | 701 LANGMAP_ADJUST(c, TRUE); |
702 --no_zero_mapping; | |
703 if (ctrl_w) | |
704 { | |
705 --no_mapping; | |
706 --allow_keys; | |
707 } | |
708 #ifdef FEAT_CMDL_INFO | |
709 need_flushbuf |= add_to_showcmd(c); | |
710 #endif | |
711 } | |
712 | |
713 /* | |
714 * If we got CTRL-W there may be a/another count | |
715 */ | |
716 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
717 { | |
718 ctrl_w = TRUE; | |
719 ca.opcount = ca.count0; /* remember first count */ | |
720 ca.count0 = 0; | |
721 ++no_mapping; | |
722 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 723 c = plain_vgetc(); /* get next character */ |
7 | 724 LANGMAP_ADJUST(c, TRUE); |
725 --no_mapping; | |
726 --allow_keys; | |
727 #ifdef FEAT_CMDL_INFO | |
728 need_flushbuf |= add_to_showcmd(c); | |
729 #endif | |
730 goto getcount; /* jump back */ | |
731 } | |
732 } | |
733 | |
1692 | 734 if (c == K_CURSORHOLD) |
735 { | |
736 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
737 * the same when coming back here after handling K_CURSORHOLD. */ | |
738 oap->prev_opcount = ca.opcount; | |
739 oap->prev_count0 = ca.count0; | |
740 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
741 else if (ca.opcount != 0) |
1692 | 742 { |
743 /* | |
744 * If we're in the middle of an operator (including after entering a | |
745 * yank buffer with '"') AND we had a count before the operator, then | |
746 * that count overrides the current value of ca.count0. | |
747 * What this means effectively, is that commands like "3dw" get turned | |
748 * into "d3w" which makes things fall into place pretty neatly. | |
749 * If you give a count before AND after the operator, they are | |
750 * multiplied. | |
751 */ | |
7 | 752 if (ca.count0) |
753 ca.count0 *= ca.opcount; | |
754 else | |
755 ca.count0 = ca.opcount; | |
756 } | |
757 | |
758 /* | |
759 * Always remember the count. It will be set to zero (on the next call, | |
760 * above) when there is no pending operator. | |
761 * When called from main(), save the count for use by the "count" built-in | |
762 * variable. | |
763 */ | |
764 ca.opcount = ca.count0; | |
765 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
766 | |
767 #ifdef FEAT_EVAL | |
768 /* | |
769 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 770 * Do set it for redo. |
7 | 771 */ |
5649 | 772 if (toplevel && readbuf1_empty()) |
1751 | 773 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 774 #endif |
775 | |
776 /* | |
777 * Find the command character in the table of commands. | |
778 * For CTRL-W we already got nchar when looking for a count. | |
779 */ | |
780 if (ctrl_w) | |
781 { | |
782 ca.nchar = c; | |
783 ca.cmdchar = Ctrl_W; | |
784 } | |
785 else | |
786 ca.cmdchar = c; | |
787 idx = find_command(ca.cmdchar); | |
788 if (idx < 0) | |
789 { | |
790 /* Not a known command: beep. */ | |
791 clearopbeep(oap); | |
792 goto normal_end; | |
793 } | |
631 | 794 |
633 | 795 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 796 { |
5848 | 797 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 798 clearopbeep(oap); |
633 | 799 text_locked_msg(); |
7 | 800 goto normal_end; |
801 } | |
819 | 802 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
803 goto normal_end; | |
7 | 804 |
805 /* | |
806 * In Visual/Select mode, a few keys are handled in a special way. | |
807 */ | |
808 if (VIsual_active) | |
809 { | |
810 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
811 if (km_stopsel | |
812 && (nv_cmds[idx].cmd_flags & NV_STS) | |
813 && !(mod_mask & MOD_MASK_SHIFT)) | |
814 { | |
815 end_visual_mode(); | |
816 redraw_curbuf_later(INVERTED); | |
817 } | |
818 | |
819 /* Keys that work different when 'keymodel' contains "startsel" */ | |
820 if (km_startsel) | |
821 { | |
822 if (nv_cmds[idx].cmd_flags & NV_SS) | |
823 { | |
824 unshift_special(&ca); | |
825 idx = find_command(ca.cmdchar); | |
840 | 826 if (idx < 0) |
827 { | |
828 /* Just in case */ | |
829 clearopbeep(oap); | |
830 goto normal_end; | |
831 } | |
7 | 832 } |
833 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
834 && (mod_mask & MOD_MASK_SHIFT)) | |
835 { | |
836 mod_mask &= ~MOD_MASK_SHIFT; | |
837 } | |
838 } | |
839 } | |
840 | |
841 #ifdef FEAT_RIGHTLEFT | |
842 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
843 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
844 { | |
845 /* Invert horizontal movements and operations. Only when typed by the | |
846 * user directly, not when the result of a mapping or "x" translated | |
847 * to "dl". */ | |
848 switch (ca.cmdchar) | |
849 { | |
850 case 'l': ca.cmdchar = 'h'; break; | |
851 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
852 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
853 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
854 case 'h': ca.cmdchar = 'l'; break; | |
855 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
856 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
857 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
858 case '>': ca.cmdchar = '<'; break; | |
859 case '<': ca.cmdchar = '>'; break; | |
860 } | |
861 idx = find_command(ca.cmdchar); | |
862 } | |
863 #endif | |
864 | |
865 /* | |
866 * Get an additional character if we need one. | |
867 */ | |
868 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
869 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
870 && oap->op_type == OP_NOP) | |
871 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
872 || (ca.cmdchar == 'q' | |
873 && oap->op_type == OP_NOP | |
874 && !Recording | |
875 && !Exec_reg) | |
876 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') | |
5735 | 877 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 878 { |
879 int *cp; | |
880 int repl = FALSE; /* get character for replace mode */ | |
881 int lit = FALSE; /* get extra character literally */ | |
882 int langmap_active = FALSE; /* using :lmap mappings */ | |
883 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
884 #ifdef HAVE_INPUT_METHOD |
7 | 885 int save_smd; /* saved value of p_smd */ |
886 #endif | |
887 | |
888 ++no_mapping; | |
889 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 890 /* Don't generate a CursorHold event here, most commands can't handle |
891 * it, e.g., nv_replace(), nv_csearch(). */ | |
892 did_cursorhold = TRUE; | |
7 | 893 if (ca.cmdchar == 'g') |
894 { | |
895 /* | |
896 * For 'g' get the next character now, so that we can check for | |
897 * "gr", "g'" and "g`". | |
898 */ | |
1389 | 899 ca.nchar = plain_vgetc(); |
7 | 900 LANGMAP_ADJUST(ca.nchar, TRUE); |
901 #ifdef FEAT_CMDL_INFO | |
902 need_flushbuf |= add_to_showcmd(ca.nchar); | |
903 #endif | |
904 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 905 || ca.nchar == Ctrl_BSL) |
7 | 906 { |
907 cp = &ca.extra_char; /* need to get a third character */ | |
908 if (ca.nchar != 'r') | |
909 lit = TRUE; /* get it literally */ | |
910 else | |
911 repl = TRUE; /* get it in replace mode */ | |
912 } | |
913 else | |
914 cp = NULL; /* no third character needed */ | |
915 } | |
916 else | |
917 { | |
918 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
919 repl = TRUE; | |
920 cp = &ca.nchar; | |
921 } | |
922 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
923 | |
924 /* | |
925 * Get a second or third character. | |
926 */ | |
927 if (cp != NULL) | |
928 { | |
929 #ifdef CURSOR_SHAPE | |
930 if (repl) | |
931 { | |
932 State = REPLACE; /* pretend Replace mode */ | |
933 ui_cursor_shape(); /* show different cursor shape */ | |
934 } | |
935 #endif | |
936 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
937 { | |
938 /* Allow mappings defined with ":lmap". */ | |
939 --no_mapping; | |
940 --allow_keys; | |
941 if (repl) | |
942 State = LREPLACE; | |
943 else | |
944 State = LANGMAP; | |
945 langmap_active = TRUE; | |
946 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
947 #ifdef HAVE_INPUT_METHOD |
7 | 948 save_smd = p_smd; |
949 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
950 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
951 im_set_active(TRUE); | |
952 #endif | |
953 | |
1389 | 954 *cp = plain_vgetc(); |
7 | 955 |
956 if (langmap_active) | |
957 { | |
958 /* Undo the decrement done above */ | |
959 ++no_mapping; | |
960 ++allow_keys; | |
961 State = NORMAL_BUSY; | |
962 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
963 #ifdef HAVE_INPUT_METHOD |
7 | 964 if (lang) |
965 { | |
966 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
967 im_save_status(&curbuf->b_p_iminsert); | |
968 im_set_active(FALSE); | |
969 } | |
970 p_smd = save_smd; | |
971 #endif | |
972 #ifdef CURSOR_SHAPE | |
973 State = NORMAL_BUSY; | |
974 #endif | |
975 #ifdef FEAT_CMDL_INFO | |
976 need_flushbuf |= add_to_showcmd(*cp); | |
977 #endif | |
978 | |
979 if (!lit) | |
980 { | |
981 #ifdef FEAT_DIGRAPHS | |
982 /* Typing CTRL-K gets a digraph. */ | |
983 if (*cp == Ctrl_K | |
984 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
985 || cp == &ca.extra_char) | |
986 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
987 { | |
988 c = get_digraph(FALSE); | |
989 if (c > 0) | |
990 { | |
991 *cp = c; | |
992 # ifdef FEAT_CMDL_INFO | |
993 /* Guessing how to update showcmd here... */ | |
994 del_from_showcmd(3); | |
995 need_flushbuf |= add_to_showcmd(*cp); | |
996 # endif | |
997 } | |
998 } | |
999 #endif | |
1000 | |
1001 /* adjust chars > 127, except after "tTfFr" commands */ | |
1002 LANGMAP_ADJUST(*cp, !lang); | |
1003 #ifdef FEAT_RIGHTLEFT | |
1004 /* adjust Hebrew mapped char */ | |
1005 if (p_hkmap && lang && KeyTyped) | |
1006 *cp = hkmap(*cp); | |
1007 # ifdef FEAT_FKMAP | |
1008 /* adjust Farsi mapped char */ | |
1009 if (p_fkmap && lang && KeyTyped) | |
1010 *cp = fkmap(*cp); | |
1011 # endif | |
1012 #endif | |
1013 } | |
1014 | |
1015 /* | |
1016 * When the next character is CTRL-\ a following CTRL-N means the | |
1017 * command is aborted and we go to Normal mode. | |
1018 */ | |
1019 if (cp == &ca.extra_char | |
1020 && ca.nchar == Ctrl_BSL | |
1021 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
1022 { | |
1023 ca.cmdchar = Ctrl_BSL; | |
1024 ca.nchar = ca.extra_char; | |
1025 idx = find_command(ca.cmdchar); | |
1026 } | |
3908 | 1027 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1028 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1029 else if (*cp == Ctrl_BSL) |
1030 { | |
1031 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1032 | |
1033 /* There is a busy wait here when typing "f<C-\>" and then | |
1034 * something different from CTRL-N. Can't be avoided. */ | |
1035 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1036 { | |
1037 do_sleep(towait > 50L ? 50L : towait); | |
1038 towait -= 50L; | |
1039 } | |
1040 if (c > 0) | |
1041 { | |
1389 | 1042 c = plain_vgetc(); |
7 | 1043 if (c != Ctrl_N && c != Ctrl_G) |
1044 vungetc(c); | |
1045 else | |
1046 { | |
1047 ca.cmdchar = Ctrl_BSL; | |
1048 ca.nchar = c; | |
1049 idx = find_command(ca.cmdchar); | |
1050 } | |
1051 } | |
1052 } | |
1053 | |
1054 #ifdef FEAT_MBYTE | |
1055 /* When getting a text character and the next character is a | |
1056 * multi-byte character, it could be a composing character. | |
6071 | 1057 * However, don't wait for it to arrive. Also, do enable mapping, |
1058 * because if it's put back with vungetc() it's too late to apply | |
1059 * mapping. */ | |
1060 --no_mapping; | |
7 | 1061 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1062 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1063 { | |
1389 | 1064 c = plain_vgetc(); |
7 | 1065 if (!utf_iscomposing(c)) |
1066 { | |
1067 vungetc(c); /* it wasn't, put it back */ | |
1068 break; | |
1069 } | |
1070 else if (ca.ncharC1 == 0) | |
1071 ca.ncharC1 = c; | |
1072 else | |
1073 ca.ncharC2 = c; | |
1074 } | |
6071 | 1075 ++no_mapping; |
7 | 1076 #endif |
1077 } | |
1078 --no_mapping; | |
1079 --allow_keys; | |
1080 } | |
1081 | |
1082 #ifdef FEAT_CMDL_INFO | |
1083 /* | |
1084 * Flush the showcmd characters onto the screen so we can see them while | |
1085 * the command is being executed. Only do this when the shown command was | |
1086 * actually displayed, otherwise this will slow down a lot when executing | |
1087 * mappings. | |
1088 */ | |
1089 if (need_flushbuf) | |
1090 out_flush(); | |
1091 #endif | |
1727 | 1092 if (ca.cmdchar != K_IGNORE) |
1093 did_cursorhold = FALSE; | |
7 | 1094 |
1095 State = NORMAL; | |
1096 | |
1097 if (ca.nchar == ESC) | |
1098 { | |
1099 clearop(oap); | |
1100 if (restart_edit == 0 && goto_im()) | |
1101 restart_edit = 'a'; | |
1102 goto normal_end; | |
1103 } | |
1104 | |
24 | 1105 if (ca.cmdchar != K_IGNORE) |
1106 { | |
1107 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1108 msg_col = 0; | |
1109 } | |
7 | 1110 |
1111 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1112 | |
1113 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1114 * mode. */ | |
1115 if (!VIsual_active && km_startsel) | |
1116 { | |
1117 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1118 { | |
1119 start_selection(); | |
1120 unshift_special(&ca); | |
1121 idx = find_command(ca.cmdchar); | |
1122 } | |
1123 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1124 && (mod_mask & MOD_MASK_SHIFT)) | |
1125 { | |
1126 start_selection(); | |
1127 mod_mask &= ~MOD_MASK_SHIFT; | |
1128 } | |
1129 } | |
1130 | |
1131 /* | |
1132 * Execute the command! | |
1133 * Call the command function found in the commands table. | |
1134 */ | |
1135 ca.arg = nv_cmds[idx].cmd_arg; | |
1136 (nv_cmds[idx].cmd_func)(&ca); | |
1137 | |
1138 /* | |
1139 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1140 * need it later. | |
1141 */ | |
1142 if (!finish_op | |
1143 && !oap->op_type | |
1144 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1145 { | |
1146 clearop(oap); | |
1147 #ifdef FEAT_EVAL | |
2821 | 1148 { |
1149 int regname = 0; | |
2829 | 1150 |
2821 | 1151 /* Adjust the register according to 'clipboard', so that when |
1152 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1153 # ifdef FEAT_CLIPBOARD |
2821 | 1154 adjust_clip_reg(®name); |
2829 | 1155 # endif |
2821 | 1156 set_reg_var(regname); |
1157 } | |
7 | 1158 #endif |
1159 } | |
1160 | |
570 | 1161 /* Get the length of mapped chars again after typing a count, second |
36 | 1162 * character or "z333<cr>". */ |
1163 if (old_mapped_len > 0) | |
1164 old_mapped_len = typebuf_maplen(); | |
1165 | |
7 | 1166 /* |
1167 * If an operation is pending, handle it... | |
1168 */ | |
1169 do_pending_operator(&ca, old_col, FALSE); | |
1170 | |
1171 /* | |
1172 * Wait for a moment when a message is displayed that will be overwritten | |
1173 * by the mode message. | |
1174 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1175 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1176 * In Visual mode, it's more important to keep the Visual area updated | |
1177 * than keeping a message (e.g. from a /pat search). | |
1178 * Only do this if the command was typed, not from a mapping. | |
1179 * Don't wait when emsg_silent is non-zero. | |
1180 * Also wait a bit after an error message, e.g. for "^O:". | |
1181 * Don't redraw the screen, it would remove the message. | |
1182 */ | |
1183 if ( ((p_smd | |
641 | 1184 && msg_silent == 0 |
7 | 1185 && (restart_edit != 0 |
1186 || (VIsual_active | |
1187 && old_pos.lnum == curwin->w_cursor.lnum | |
1188 && old_pos.col == curwin->w_cursor.col) | |
1189 ) | |
1190 && (clear_cmdline | |
1191 || redraw_cmdline) | |
1192 && (msg_didout || (msg_didany && msg_scroll)) | |
1193 && !msg_nowait | |
1194 && KeyTyped) | |
1195 || (restart_edit != 0 | |
1196 && !VIsual_active | |
1197 && (msg_scroll | |
1198 || emsg_on_display))) | |
1199 && oap->regname == 0 | |
1200 && !(ca.retval & CA_COMMAND_BUSY) | |
1201 && stuff_empty() | |
1202 && typebuf_typed() | |
1203 && emsg_silent == 0 | |
1204 && !did_wait_return | |
1205 && oap->op_type == OP_NOP) | |
1206 { | |
1207 int save_State = State; | |
1208 | |
1209 /* Draw the cursor with the right shape here */ | |
1210 if (restart_edit != 0) | |
1211 State = INSERT; | |
1212 | |
1213 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1214 * delay */ | |
1215 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1216 { | |
1217 char_u *kmsg; | |
1218 | |
1219 kmsg = keep_msg; | |
1220 keep_msg = NULL; | |
1221 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1222 update_screen(0); | |
1223 /* now reset it, otherwise it's put in the history again */ | |
1224 keep_msg = kmsg; | |
1225 msg_attr(kmsg, keep_msg_attr); | |
1226 vim_free(kmsg); | |
1227 } | |
1228 setcursor(); | |
1229 cursor_on(); | |
1230 out_flush(); | |
1231 if (msg_scroll || emsg_on_display) | |
1232 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1233 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1234 State = save_State; | |
1235 | |
1236 msg_scroll = FALSE; | |
1237 emsg_on_display = FALSE; | |
1238 } | |
1239 | |
1240 /* | |
1241 * Finish up after executing a Normal mode command. | |
1242 */ | |
1243 normal_end: | |
1244 | |
1245 msg_nowait = FALSE; | |
1246 | |
1247 /* Reset finish_op, in case it was set */ | |
1248 #ifdef CURSOR_SHAPE | |
1249 c = finish_op; | |
1250 #endif | |
1251 finish_op = FALSE; | |
1252 #ifdef CURSOR_SHAPE | |
1253 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1254 * mode or did a replace command. */ | |
1255 if (c || ca.cmdchar == 'r') | |
1256 { | |
1257 ui_cursor_shape(); /* may show different cursor shape */ | |
1258 # ifdef FEAT_MOUSESHAPE | |
1259 update_mouseshape(-1); | |
1260 # endif | |
1261 } | |
1262 #endif | |
1263 | |
1264 #ifdef FEAT_CMDL_INFO | |
1692 | 1265 if (oap->op_type == OP_NOP && oap->regname == 0 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1266 && ca.cmdchar != K_CURSORHOLD) |
7 | 1267 clear_showcmd(); |
1268 #endif | |
1269 | |
1270 checkpcmark(); /* check if we moved since setting pcmark */ | |
1271 vim_free(ca.searchbuf); | |
1272 | |
1273 #ifdef FEAT_MBYTE | |
1274 if (has_mbyte) | |
1275 mb_adjust_cursor(); | |
1276 #endif | |
1277 | |
1278 #ifdef FEAT_SCROLLBIND | |
1279 if (curwin->w_p_scb && toplevel) | |
1280 { | |
1281 validate_cursor(); /* may need to update w_leftcol */ | |
1282 do_check_scrollbind(TRUE); | |
1283 } | |
1284 #endif | |
1285 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1286 #ifdef FEAT_CURSORBIND |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1287 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1288 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1289 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
|
1290 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1291 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1292 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1293 |
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
|
1294 #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
|
1295 /* 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
|
1296 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
|
1297 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
|
1298 #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
|
1299 |
7 | 1300 /* |
1301 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1302 * if still inside a mapping that started in Visual mode). | |
1303 * May switch from Visual to Select mode after CTRL-O command. | |
1304 */ | |
1305 if ( oap->op_type == OP_NOP | |
1306 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1307 || restart_VIsual_select == 1) | |
1308 && !(ca.retval & CA_COMMAND_BUSY) | |
1309 && stuff_empty() | |
1310 && oap->regname == 0) | |
1311 { | |
1312 if (restart_VIsual_select == 1) | |
1313 { | |
1314 VIsual_select = TRUE; | |
1315 showmode(); | |
1316 restart_VIsual_select = 0; | |
1317 } | |
5735 | 1318 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1319 (void)edit(restart_edit, FALSE, 1L); |
1320 } | |
1321 | |
1322 if (restart_VIsual_select == 2) | |
1323 restart_VIsual_select = 1; | |
1324 | |
1325 /* Save count before an operator for next time. */ | |
1326 opcount = ca.opcount; | |
1327 } | |
1328 | |
2667 | 1329 #ifdef FEAT_EVAL |
1330 /* | |
1331 * Set v:count and v:count1 according to "cap". | |
1332 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1333 */ | |
1334 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1335 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1336 { |
1337 long count = cap->count0; | |
1338 | |
1339 /* multiply with cap->opcount the same way as above */ | |
1340 if (cap->opcount != 0) | |
1341 count = cap->opcount * (count == 0 ? 1 : count); | |
1342 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1343 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1344 } | |
1345 #endif | |
1346 | |
7 | 1347 /* |
1348 * Handle an operator after visual mode or when the movement is finished | |
1349 */ | |
1350 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1351 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1352 { |
1353 oparg_T *oap = cap->oap; | |
1354 pos_T old_cursor; | |
1355 int empty_region_error; | |
1356 int restart_edit_save; | |
6266 | 1357 #ifdef FEAT_LINEBREAK |
1358 int lbr_saved = curwin->w_p_lbr; | |
1359 #endif | |
7 | 1360 |
1361 /* The visual area is remembered for redo */ | |
1362 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1363 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1364 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1365 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
|
1366 static int redo_VIsual_arg; /* extra argument */ |
5735 | 1367 #ifdef FEAT_VIRTUALEDIT |
7 | 1368 int include_line_break = FALSE; |
1369 #endif | |
1370 | |
1371 #if defined(FEAT_CLIPBOARD) | |
1372 /* | |
1373 * Yank the visual area into the GUI selection register before we operate | |
1374 * on it and lose it forever. | |
1375 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1376 * This could call do_pending_operator() recursively, but that's OK | |
1377 * because gui_yank will be TRUE for the nested call. | |
1378 */ | |
3674 | 1379 if ((clip_star.available || clip_plus.available) |
7 | 1380 && oap->op_type != OP_NOP |
1381 && !gui_yank | |
1382 && VIsual_active | |
1383 && !redo_VIsual_busy | |
1384 && oap->regname == 0) | |
1385 clip_auto_select(); | |
1386 #endif | |
1387 old_cursor = curwin->w_cursor; | |
1388 | |
1389 /* | |
1390 * If an operation is pending, handle it... | |
1391 */ | |
5735 | 1392 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1393 { | |
6497 | 1394 #ifdef FEAT_LINEBREAK |
1395 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1396 if (curwin->w_p_lbr) |
1397 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1398 curwin->w_p_lbr = FALSE; |
1399 #endif | |
7 | 1400 oap->is_VIsual = VIsual_active; |
1401 if (oap->motion_force == 'V') | |
1402 oap->motion_type = MLINE; | |
1403 else if (oap->motion_force == 'v') | |
1404 { | |
1405 /* If the motion was linewise, "inclusive" will not have been set. | |
1406 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1407 if (oap->motion_type == MLINE) | |
1408 oap->inclusive = FALSE; | |
1409 /* If the motion already was characterwise, toggle "inclusive" */ | |
1410 else if (oap->motion_type == MCHAR) | |
1411 oap->inclusive = !oap->inclusive; | |
1412 oap->motion_type = MCHAR; | |
1413 } | |
1414 else if (oap->motion_force == Ctrl_V) | |
1415 { | |
1416 /* Change line- or characterwise motion into Visual block mode. */ | |
1417 VIsual_active = TRUE; | |
1418 VIsual = oap->start; | |
1419 VIsual_mode = Ctrl_V; | |
1420 VIsual_select = FALSE; | |
1421 VIsual_reselect = FALSE; | |
1422 } | |
1423 | |
4337 | 1424 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1425 /* Never redo "zf" (define fold). */ | |
7 | 1426 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
4337 | 1427 && ((!VIsual_active || oap->motion_force) |
1428 /* Also redo Operator-pending Visual mode mappings */ | |
1429 || (VIsual_active && cap->cmdchar == ':' | |
1430 && oap->op_type != OP_COLON)) | |
164 | 1431 && cap->cmdchar != 'D' |
7 | 1432 #ifdef FEAT_FOLDING |
1433 && oap->op_type != OP_FOLD | |
1434 && oap->op_type != OP_FOLDOPEN | |
1435 && oap->op_type != OP_FOLDOPENREC | |
1436 && oap->op_type != OP_FOLDCLOSE | |
1437 && oap->op_type != OP_FOLDCLOSEREC | |
1438 && oap->op_type != OP_FOLDDEL | |
1439 && oap->op_type != OP_FOLDDELREC | |
1440 #endif | |
1441 ) | |
1442 { | |
1443 prep_redo(oap->regname, cap->count0, | |
1444 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1445 oap->motion_force, cap->cmdchar, cap->nchar); | |
1446 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1447 { | |
1448 /* | |
1449 * If 'cpoptions' does not contain 'r', insert the search | |
1450 * pattern to really repeat the same command. | |
1451 */ | |
1452 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1453 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1454 AppendToRedobuff(NL_STR); |
1455 } | |
1456 else if (cap->cmdchar == ':') | |
1457 { | |
1458 /* do_cmdline() has stored the first typed line in | |
1459 * "repeat_cmdline". When several lines are typed repeating | |
1460 * won't be possible. */ | |
1461 if (repeat_cmdline == NULL) | |
1462 ResetRedobuff(); | |
1463 else | |
1464 { | |
620 | 1465 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1466 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1467 VIM_CLEAR(repeat_cmdline); |
7 | 1468 } |
1469 } | |
1470 } | |
1471 | |
1472 if (redo_VIsual_busy) | |
1473 { | |
3125 | 1474 /* Redo of an operation on a Visual area. Use the same size from |
1475 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1476 oap->start = curwin->w_cursor; |
1477 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1478 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1479 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1480 VIsual_mode = redo_VIsual_mode; | |
3125 | 1481 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1482 { |
3125 | 1483 if (VIsual_mode == 'v') |
1484 { | |
1485 if (redo_VIsual_line_count <= 1) | |
1486 { | |
1487 validate_virtcol(); | |
1488 curwin->w_curswant = | |
1489 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1490 } | |
1491 else | |
1492 curwin->w_curswant = redo_VIsual_vcol; | |
1493 } | |
7 | 1494 else |
3125 | 1495 { |
1496 curwin->w_curswant = MAXCOL; | |
1497 } | |
1498 coladvance(curwin->w_curswant); | |
7 | 1499 } |
1500 cap->count0 = redo_VIsual_count; | |
1501 if (redo_VIsual_count != 0) | |
1502 cap->count1 = redo_VIsual_count; | |
1503 else | |
1504 cap->count1 = 1; | |
1505 } | |
1506 else if (VIsual_active) | |
1507 { | |
999 | 1508 if (!gui_yank) |
1509 { | |
1510 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1511 curbuf->b_visual.vi_start = VIsual; | |
1512 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1513 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1514 if (VIsual_mode_orig != NUL) |
1515 { | |
1516 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1517 VIsual_mode_orig = NUL; | |
1518 } | |
999 | 1519 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1520 # ifdef FEAT_EVAL |
999 | 1521 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1522 # endif |
999 | 1523 } |
7 | 1524 |
1525 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1526 * characterwise selection. |
1527 * Special case: gH<Del> deletes the last line. */ | |
1528 if (VIsual_select && VIsual_mode == 'V' | |
1529 && cap->oap->op_type != OP_DELETE) | |
7 | 1530 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1531 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1532 { |
1533 VIsual.col = 0; | |
1534 curwin->w_cursor.col = | |
1535 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1536 } | |
1537 else | |
1538 { | |
1539 curwin->w_cursor.col = 0; | |
1540 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1541 } | |
1542 VIsual_mode = 'v'; | |
1543 } | |
1544 /* If 'selection' is "exclusive", backup one character for | |
1545 * charwise selections. */ | |
1546 else if (VIsual_mode == 'v') | |
1547 { | |
1548 # ifdef FEAT_VIRTUALEDIT | |
1549 include_line_break = | |
1550 # endif | |
1551 unadjust_for_sel(); | |
1552 } | |
1553 | |
1554 oap->start = VIsual; | |
1555 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
|
1556 { |
7 | 1557 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
|
1558 # ifdef FEAT_VIRTUALEDIT |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1559 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1560 # endif |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1561 } |
7 | 1562 } |
1563 | |
1564 /* | |
1565 * Set oap->start to the first position of the operated text, oap->end | |
1566 * to the end of the operated text. w_cursor is equal to oap->start. | |
1567 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1568 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1569 { |
1570 #ifdef FEAT_FOLDING | |
1571 /* Include folded lines completely. */ | |
1572 if (!VIsual_active) | |
1573 { | |
1574 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1575 oap->start.col = 0; | |
1576 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1577 &curwin->w_cursor.lnum)) | |
1578 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1579 } | |
1580 #endif | |
1581 oap->end = curwin->w_cursor; | |
1582 curwin->w_cursor = oap->start; | |
1583 | |
1584 /* w_virtcol may have been updated; if the cursor goes back to its | |
1585 * previous position w_virtcol becomes invalid and isn't updated | |
1586 * automatically. */ | |
1587 curwin->w_valid &= ~VALID_VIRTCOL; | |
1588 } | |
1589 else | |
1590 { | |
1591 #ifdef FEAT_FOLDING | |
1592 /* Include folded lines completely. */ | |
1593 if (!VIsual_active && oap->motion_type == MLINE) | |
1594 { | |
1595 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1596 NULL)) | |
1597 curwin->w_cursor.col = 0; | |
1598 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1599 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1600 } | |
1601 #endif | |
1602 oap->end = oap->start; | |
1603 oap->start = curwin->w_cursor; | |
1604 } | |
1605 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1606 /* 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
|
1607 check_pos(curwin->w_buffer, &oap->end); |
7 | 1608 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1609 | |
1610 #ifdef FEAT_VIRTUALEDIT | |
1611 /* Set "virtual_op" before resetting VIsual_active. */ | |
1612 virtual_op = virtual_active(); | |
1613 #endif | |
1614 | |
1615 if (VIsual_active || redo_VIsual_busy) | |
1616 { | |
6866 | 1617 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1618 |
1619 if (!redo_VIsual_busy && !gui_yank) | |
1620 { | |
1621 /* | |
1622 * Prepare to reselect and redo Visual: this is based on the | |
1623 * size of the Visual text | |
1624 */ | |
1625 resel_VIsual_mode = VIsual_mode; | |
1626 if (curwin->w_curswant == MAXCOL) | |
3125 | 1627 resel_VIsual_vcol = MAXCOL; |
7 | 1628 else |
3125 | 1629 { |
1630 if (VIsual_mode != Ctrl_V) | |
1631 getvvcol(curwin, &(oap->end), | |
1632 NULL, NULL, &oap->end_vcol); | |
1633 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1634 { | |
1635 if (VIsual_mode != Ctrl_V) | |
1636 getvvcol(curwin, &(oap->start), | |
1637 &oap->start_vcol, NULL, NULL); | |
1638 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1639 } | |
1640 else | |
1641 resel_VIsual_vcol = oap->end_vcol; | |
1642 } | |
7 | 1643 resel_VIsual_line_count = oap->line_count; |
1644 } | |
1645 | |
1646 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
1647 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | |
1648 && oap->op_type != OP_COLON | |
1649 #ifdef FEAT_FOLDING | |
1650 && oap->op_type != OP_FOLD | |
1651 && oap->op_type != OP_FOLDOPEN | |
1652 && oap->op_type != OP_FOLDOPENREC | |
1653 && oap->op_type != OP_FOLDCLOSE | |
1654 && oap->op_type != OP_FOLDCLOSEREC | |
1655 && oap->op_type != OP_FOLDDEL | |
1656 && oap->op_type != OP_FOLDDELREC | |
1657 #endif | |
1658 && oap->motion_force == NUL | |
1659 ) | |
1660 { | |
1661 /* Prepare for redoing. Only use the nchar field for "r", | |
1662 * otherwise it might be the second char of the operator. */ | |
3701 | 1663 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1664 || cap->nchar == 'N')) | |
5523 | 1665 prep_redo(oap->regname, cap->count0, |
1666 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1667 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1668 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
|
1669 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1670 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
|
1671 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1672 /* 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
|
1673 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
|
1674 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1675 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
|
1676 nchar = NL; |
3701 | 1677 prep_redo(oap->regname, 0L, NUL, 'v', |
1678 get_op_char(oap->op_type), | |
1679 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
|
1680 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1681 } |
7 | 1682 if (!redo_VIsual_busy) |
1683 { | |
1684 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1685 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1686 redo_VIsual_line_count = resel_VIsual_line_count; |
1687 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1688 redo_VIsual_arg = cap->arg; |
7 | 1689 } |
1690 } | |
1691 | |
1692 /* | |
1693 * oap->inclusive defaults to TRUE. | |
1694 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1695 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1696 */ | |
1697 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1698 oap->inclusive = TRUE; | |
1699 if (VIsual_mode == 'V') | |
1700 oap->motion_type = MLINE; | |
1701 else | |
1702 { | |
1703 oap->motion_type = MCHAR; | |
1704 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1705 #ifdef FEAT_VIRTUALEDIT |
7 | 1706 && (include_line_break || !virtual_op) |
5735 | 1707 #endif |
7 | 1708 ) |
1709 { | |
1710 oap->inclusive = FALSE; | |
1711 /* Try to include the newline, unless it's an operator | |
2957 | 1712 * that works on lines only. */ |
6826 | 1713 if (*p_sel != 'o' |
1714 && !op_on_lines(oap->op_type) | |
1715 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1716 { |
6826 | 1717 ++oap->end.lnum; |
1718 oap->end.col = 0; | |
5735 | 1719 #ifdef FEAT_VIRTUALEDIT |
6826 | 1720 oap->end.coladd = 0; |
1721 #endif | |
1722 ++oap->line_count; | |
7 | 1723 } |
1724 } | |
1725 } | |
1726 | |
1727 redo_VIsual_busy = FALSE; | |
592 | 1728 |
7 | 1729 /* |
1730 * Switch Visual off now, so screen updating does | |
1731 * not show inverted text when the screen is redrawn. | |
1732 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1733 * no screen redraw, so it is done here to remove the inverted | |
1734 * part. | |
1735 */ | |
1736 if (!gui_yank) | |
1737 { | |
1738 VIsual_active = FALSE; | |
5735 | 1739 #ifdef FEAT_MOUSE |
7 | 1740 setmouse(); |
1741 mouse_dragging = 0; | |
5735 | 1742 #endif |
6979 | 1743 may_clear_cmdline(); |
7 | 1744 if ((oap->op_type == OP_YANK |
1745 || oap->op_type == OP_COLON | |
592 | 1746 || oap->op_type == OP_FUNCTION |
7 | 1747 || oap->op_type == OP_FILTER) |
1748 && oap->motion_force == NUL) | |
6497 | 1749 { |
1750 #ifdef FEAT_LINEBREAK | |
1751 /* make sure redrawing is correct */ | |
1752 curwin->w_p_lbr = lbr_saved; | |
1753 #endif | |
7 | 1754 redraw_curbuf_later(INVERTED); |
6497 | 1755 } |
7 | 1756 } |
1757 } | |
1758 | |
1759 #ifdef FEAT_MBYTE | |
1760 /* Include the trailing byte of a multi-byte char. */ | |
1761 if (has_mbyte && oap->inclusive) | |
1762 { | |
1763 int l; | |
1764 | |
474 | 1765 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1766 if (l > 1) |
1767 oap->end.col += l - 1; | |
1768 } | |
1769 #endif | |
1770 curwin->w_set_curswant = TRUE; | |
1771 | |
1772 /* | |
1773 * oap->empty is set when start and end are the same. The inclusive | |
1774 * flag affects this too, unless yanking and the end is on a NUL. | |
1775 */ | |
1776 oap->empty = (oap->motion_type == MCHAR | |
1777 && (!oap->inclusive | |
1778 || (oap->op_type == OP_YANK | |
1779 && 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
|
1780 && EQUAL_POS(oap->start, oap->end) |
7 | 1781 #ifdef FEAT_VIRTUALEDIT |
1782 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1783 #endif | |
1784 ); | |
1785 /* | |
1786 * For delete, change and yank, it's an error to operate on an | |
1787 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1788 */ | |
1789 empty_region_error = (oap->empty | |
1790 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1791 | |
1792 /* Force a redraw when operating on an empty Visual region, when | |
1793 * 'modifiable is off or creating a fold. */ | |
1794 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1795 #ifdef FEAT_FOLDING |
7 | 1796 || oap->op_type == OP_FOLD |
5735 | 1797 #endif |
7 | 1798 )) |
6497 | 1799 { |
1800 #ifdef FEAT_LINEBREAK | |
1801 curwin->w_p_lbr = lbr_saved; | |
1802 #endif | |
7 | 1803 redraw_curbuf_later(INVERTED); |
6497 | 1804 } |
7 | 1805 |
1806 /* | |
1807 * If the end of an operator is in column one while oap->motion_type | |
1808 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1809 * character in the previous line. If op_start is on or before the | |
1810 * first non-blank in the line, the operator becomes linewise | |
1811 * (strange, but that's the way vi does it). | |
1812 */ | |
1813 if ( oap->motion_type == MCHAR | |
1814 && oap->inclusive == FALSE | |
1815 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1816 && oap->end.col == 0 | |
1817 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1818 && !oap->block_mode |
7 | 1819 && oap->line_count > 1) |
1820 { | |
1821 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1822 --oap->line_count; | |
1823 --oap->end.lnum; | |
1824 if (inindent(0)) | |
1825 oap->motion_type = MLINE; | |
1826 else | |
1827 { | |
1828 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1829 if (oap->end.col) | |
1830 { | |
1831 --oap->end.col; | |
1832 oap->inclusive = TRUE; | |
1833 } | |
1834 } | |
1835 } | |
1836 else | |
1837 oap->end_adjusted = FALSE; | |
1838 | |
1839 switch (oap->op_type) | |
1840 { | |
1841 case OP_LSHIFT: | |
1842 case OP_RSHIFT: | |
5735 | 1843 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1844 auto_format(FALSE, TRUE); |
1845 break; | |
1846 | |
1847 case OP_JOIN_NS: | |
1848 case OP_JOIN: | |
1849 if (oap->line_count < 2) | |
1850 oap->line_count = 2; | |
1851 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1852 curbuf->b_ml.ml_line_count) | |
1853 beep_flush(); | |
1854 else | |
1855 { | |
5735 | 1856 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1857 TRUE, TRUE, TRUE); |
7 | 1858 auto_format(FALSE, TRUE); |
1859 } | |
1860 break; | |
1861 | |
1862 case OP_DELETE: | |
1863 VIsual_reselect = FALSE; /* don't reselect now */ | |
1864 if (empty_region_error) | |
3324 | 1865 { |
6949 | 1866 vim_beep(BO_OPER); |
3324 | 1867 CancelRedo(); |
1868 } | |
7 | 1869 else |
1870 { | |
1871 (void)op_delete(oap); | |
1872 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1873 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1874 auto_format(FALSE, TRUE); | |
1875 } | |
1876 break; | |
1877 | |
1878 case OP_YANK: | |
1879 if (empty_region_error) | |
1880 { | |
1881 if (!gui_yank) | |
3324 | 1882 { |
6949 | 1883 vim_beep(BO_OPER); |
3324 | 1884 CancelRedo(); |
1885 } | |
7 | 1886 } |
1887 else | |
6497 | 1888 { |
1889 #ifdef FEAT_LINEBREAK | |
1890 curwin->w_p_lbr = lbr_saved; | |
1891 #endif | |
7 | 1892 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1893 } |
7 | 1894 check_cursor_col(); |
1895 break; | |
1896 | |
1897 case OP_CHANGE: | |
1898 VIsual_reselect = FALSE; /* don't reselect now */ | |
1899 if (empty_region_error) | |
3324 | 1900 { |
6949 | 1901 vim_beep(BO_OPER); |
3324 | 1902 CancelRedo(); |
1903 } | |
7 | 1904 else |
1905 { | |
1906 /* This is a new edit command, not a restart. Need to | |
1907 * remember it to make 'insertmode' work with mappings for | |
1908 * Visual mode. But do this only once and not when typed and | |
1909 * 'insertmode' isn't set. */ | |
1910 if (p_im || !KeyTyped) | |
1911 restart_edit_save = restart_edit; | |
1912 else | |
1913 restart_edit_save = 0; | |
1914 restart_edit = 0; | |
6497 | 1915 #ifdef FEAT_LINEBREAK |
1916 /* Restore linebreak, so that when the user edits it looks as | |
1917 * before. */ | |
6866 | 1918 if (curwin->w_p_lbr != lbr_saved) |
1919 { | |
1920 curwin->w_p_lbr = lbr_saved; | |
1921 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1922 } | |
6497 | 1923 #endif |
7 | 1924 /* Reset finish_op now, don't want it set inside edit(). */ |
1925 finish_op = FALSE; | |
1926 if (op_change(oap)) /* will call edit() */ | |
1927 cap->retval |= CA_COMMAND_BUSY; | |
1928 if (restart_edit == 0) | |
1929 restart_edit = restart_edit_save; | |
1930 } | |
1931 break; | |
1932 | |
1933 case OP_FILTER: | |
1934 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1935 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1936 else | |
1937 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
|
1938 /* FALLTHROUGH */ |
7 | 1939 |
1940 case OP_INDENT: | |
1941 case OP_COLON: | |
1942 | |
1943 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1944 /* | |
1945 * If 'equalprg' is empty, do the indenting internally. | |
1946 */ | |
1947 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1948 { | |
1949 # ifdef FEAT_LISP | |
1950 if (curbuf->b_p_lisp) | |
1951 { | |
1952 op_reindent(oap, get_lisp_indent); | |
1953 break; | |
1954 } | |
1955 # endif | |
1956 # ifdef FEAT_CINDENT | |
1957 op_reindent(oap, | |
1958 # ifdef FEAT_EVAL | |
1959 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1960 # endif | |
1961 get_c_indent); | |
1962 break; | |
1963 # endif | |
1964 } | |
1965 #endif | |
1966 | |
1967 op_colon(oap); | |
1968 break; | |
1969 | |
1970 case OP_TILDE: | |
1971 case OP_UPPER: | |
1972 case OP_LOWER: | |
1973 case OP_ROT13: | |
1974 if (empty_region_error) | |
3324 | 1975 { |
6949 | 1976 vim_beep(BO_OPER); |
3324 | 1977 CancelRedo(); |
1978 } | |
7 | 1979 else |
1980 op_tilde(oap); | |
1981 check_cursor_col(); | |
1982 break; | |
1983 | |
1984 case OP_FORMAT: | |
667 | 1985 #if defined(FEAT_EVAL) |
1986 if (*curbuf->b_p_fex != NUL) | |
1987 op_formatexpr(oap); /* use expression */ | |
1988 else | |
1989 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1990 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1991 op_colon(oap); /* use external command */ |
1992 else | |
1993 op_format(oap, FALSE); /* use internal function */ | |
1994 break; | |
1995 | |
1996 case OP_FORMAT2: | |
1997 op_format(oap, TRUE); /* use internal function */ | |
1998 break; | |
1999 | |
592 | 2000 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2001 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2002 /* 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
|
2003 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2004 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2005 #endif |
592 | 2006 op_function(oap); /* call 'operatorfunc' */ |
2007 break; | |
2008 | |
7 | 2009 case OP_INSERT: |
2010 case OP_APPEND: | |
2011 VIsual_reselect = FALSE; /* don't reselect now */ | |
2012 #ifdef FEAT_VISUALEXTRA | |
2013 if (empty_region_error) | |
3324 | 2014 { |
6949 | 2015 vim_beep(BO_OPER); |
3324 | 2016 CancelRedo(); |
2017 } | |
7 | 2018 else |
2019 { | |
2020 /* This is a new edit command, not a restart. Need to | |
2021 * remember it to make 'insertmode' work with mappings for | |
2022 * Visual mode. But do this only once. */ | |
2023 restart_edit_save = restart_edit; | |
2024 restart_edit = 0; | |
6497 | 2025 #ifdef FEAT_LINEBREAK |
2026 /* Restore linebreak, so that when the user edits it looks as | |
2027 * before. */ | |
6866 | 2028 if (curwin->w_p_lbr != lbr_saved) |
2029 { | |
2030 curwin->w_p_lbr = lbr_saved; | |
2031 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2032 } | |
6497 | 2033 #endif |
7 | 2034 op_insert(oap, cap->count1); |
6497 | 2035 #ifdef FEAT_LINEBREAK |
2036 /* Reset linebreak, so that formatting works correctly. */ | |
2037 curwin->w_p_lbr = FALSE; | |
2038 #endif | |
7 | 2039 |
2040 /* TODO: when inserting in several lines, should format all | |
2041 * the lines. */ | |
2042 auto_format(FALSE, TRUE); | |
2043 | |
2044 if (restart_edit == 0) | |
2045 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
|
2046 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
|
2047 cap->retval |= CA_COMMAND_BUSY; |
7 | 2048 } |
2049 #else | |
6949 | 2050 vim_beep(BO_OPER); |
7 | 2051 #endif |
2052 break; | |
2053 | |
2054 case OP_REPLACE: | |
2055 VIsual_reselect = FALSE; /* don't reselect now */ | |
2056 #ifdef FEAT_VISUALEXTRA | |
2057 if (empty_region_error) | |
2058 #endif | |
3324 | 2059 { |
6949 | 2060 vim_beep(BO_OPER); |
3324 | 2061 CancelRedo(); |
2062 } | |
7 | 2063 #ifdef FEAT_VISUALEXTRA |
2064 else | |
6497 | 2065 { |
6866 | 2066 # ifdef FEAT_LINEBREAK |
6497 | 2067 /* Restore linebreak, so that when the user edits it looks as |
2068 * before. */ | |
6866 | 2069 if (curwin->w_p_lbr != lbr_saved) |
2070 { | |
2071 curwin->w_p_lbr = lbr_saved; | |
2072 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2073 } | |
2074 # endif | |
7 | 2075 op_replace(oap, cap->nchar); |
6497 | 2076 } |
7 | 2077 #endif |
2078 break; | |
2079 | |
2080 #ifdef FEAT_FOLDING | |
2081 case OP_FOLD: | |
2082 VIsual_reselect = FALSE; /* don't reselect now */ | |
2083 foldCreate(oap->start.lnum, oap->end.lnum); | |
2084 break; | |
2085 | |
2086 case OP_FOLDOPEN: | |
2087 case OP_FOLDOPENREC: | |
2088 case OP_FOLDCLOSE: | |
2089 case OP_FOLDCLOSEREC: | |
2090 VIsual_reselect = FALSE; /* don't reselect now */ | |
2091 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2092 oap->op_type == OP_FOLDOPEN | |
2093 || oap->op_type == OP_FOLDOPENREC, | |
2094 oap->op_type == OP_FOLDOPENREC | |
2095 || oap->op_type == OP_FOLDCLOSEREC, | |
2096 oap->is_VIsual); | |
2097 break; | |
2098 | |
2099 case OP_FOLDDEL: | |
2100 case OP_FOLDDELREC: | |
2101 VIsual_reselect = FALSE; /* don't reselect now */ | |
2102 deleteFold(oap->start.lnum, oap->end.lnum, | |
2103 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2104 break; | |
2105 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2106 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2107 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2108 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2109 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2110 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2111 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2112 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2113 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2114 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2115 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2116 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2117 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2118 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2119 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
|
2120 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2121 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2122 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2123 break; |
7 | 2124 default: |
2125 clearopbeep(oap); | |
2126 } | |
2127 #ifdef FEAT_VIRTUALEDIT | |
2128 virtual_op = MAYBE; | |
2129 #endif | |
2130 if (!gui_yank) | |
2131 { | |
2132 /* | |
2133 * if 'sol' not set, go back to old column for some commands | |
2134 */ | |
2135 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2136 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2137 || oap->op_type == OP_DELETE)) | |
6497 | 2138 { |
2139 #ifdef FEAT_LINEBREAK | |
2140 curwin->w_p_lbr = FALSE; | |
2141 #endif | |
7 | 2142 coladvance(curwin->w_curswant = old_col); |
6497 | 2143 } |
7 | 2144 } |
2145 else | |
2146 { | |
2147 curwin->w_cursor = old_cursor; | |
2148 } | |
2149 oap->block_mode = FALSE; | |
2150 clearop(oap); | |
2151 } | |
6266 | 2152 #ifdef FEAT_LINEBREAK |
2153 curwin->w_p_lbr = lbr_saved; | |
2154 #endif | |
7 | 2155 } |
2156 | |
2157 /* | |
2158 * Handle indent and format operators and visual mode ":". | |
2159 */ | |
2160 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2161 op_colon(oparg_T *oap) |
7 | 2162 { |
2163 stuffcharReadbuff(':'); | |
2164 if (oap->is_VIsual) | |
2165 stuffReadbuff((char_u *)"'<,'>"); | |
2166 else | |
2167 { | |
2168 /* | |
2169 * Make the range look nice, so it can be repeated. | |
2170 */ | |
2171 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2172 stuffcharReadbuff('.'); | |
2173 else | |
2174 stuffnumReadbuff((long)oap->start.lnum); | |
2175 if (oap->end.lnum != oap->start.lnum) | |
2176 { | |
2177 stuffcharReadbuff(','); | |
2178 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2179 stuffcharReadbuff('.'); | |
2180 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2181 stuffcharReadbuff('$'); | |
2182 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2183 { | |
2184 stuffReadbuff((char_u *)".+"); | |
2185 stuffnumReadbuff((long)oap->line_count - 1); | |
2186 } | |
2187 else | |
2188 stuffnumReadbuff((long)oap->end.lnum); | |
2189 } | |
2190 } | |
2191 if (oap->op_type != OP_COLON) | |
2192 stuffReadbuff((char_u *)"!"); | |
2193 if (oap->op_type == OP_INDENT) | |
2194 { | |
2195 #ifndef FEAT_CINDENT | |
2196 if (*get_equalprg() == NUL) | |
2197 stuffReadbuff((char_u *)"indent"); | |
2198 else | |
2199 #endif | |
2200 stuffReadbuff(get_equalprg()); | |
2201 stuffReadbuff((char_u *)"\n"); | |
2202 } | |
2203 else if (oap->op_type == OP_FORMAT) | |
2204 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2205 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
|
2206 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
|
2207 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
|
2208 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2209 else |
7 | 2210 stuffReadbuff((char_u *)"fmt"); |
216 | 2211 stuffReadbuff((char_u *)"\n']"); |
7 | 2212 } |
2213 | |
2214 /* | |
2215 * do_cmdline() does the rest | |
2216 */ | |
2217 } | |
2218 | |
592 | 2219 /* |
602 | 2220 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2221 */ |
690 | 2222 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2223 op_function(oparg_T *oap UNUSED) |
592 | 2224 { |
2225 #ifdef FEAT_EVAL | |
2226 char_u *(argv[1]); | |
4133 | 2227 # ifdef FEAT_VIRTUALEDIT |
3431 | 2228 int save_virtual_op = virtual_op; |
4133 | 2229 # endif |
592 | 2230 |
2231 if (*p_opfunc == NUL) | |
2232 EMSG(_("E774: 'operatorfunc' is empty")); | |
2233 else | |
2234 { | |
2235 /* Set '[ and '] marks to text to be operated on. */ | |
2236 curbuf->b_op_start = oap->start; | |
2237 curbuf->b_op_end = oap->end; | |
2238 if (oap->motion_type != MLINE && !oap->inclusive) | |
2239 /* Exclude the end position. */ | |
2240 decl(&curbuf->b_op_end); | |
2241 | |
2242 if (oap->block_mode) | |
2243 argv[0] = (char_u *)"block"; | |
2244 else if (oap->motion_type == MLINE) | |
2245 argv[0] = (char_u *)"line"; | |
2246 else | |
2247 argv[0] = (char_u *)"char"; | |
3431 | 2248 |
4133 | 2249 # ifdef FEAT_VIRTUALEDIT |
3431 | 2250 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2251 * function. */ | |
2252 virtual_op = MAYBE; | |
4133 | 2253 # endif |
3431 | 2254 |
592 | 2255 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
3431 | 2256 |
4133 | 2257 # ifdef FEAT_VIRTUALEDIT |
3431 | 2258 virtual_op = save_virtual_op; |
4133 | 2259 # endif |
592 | 2260 } |
2261 #else | |
2262 EMSG(_("E775: Eval feature not available")); | |
2263 #endif | |
2264 } | |
2265 | |
7 | 2266 #if defined(FEAT_MOUSE) || defined(PROTO) |
2267 /* | |
2268 * Do the appropriate action for the current mouse click in the current mode. | |
2269 * Not used for Command-line mode. | |
2270 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2271 * Normal and Visual Mode: |
7 | 2272 * event modi- position visual change action |
2273 * fier cursor window | |
2274 * left press - yes end yes | |
2275 * 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
|
2276 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2277 * left drag - yes start if moved no |
2278 * left relse - yes start if moved no | |
2279 * middle press - yes if not active no put register | |
2280 * middle press - yes if active no yank and put | |
2281 * right press - yes start or extend yes | |
2282 * right press S yes no change yes "#" (2) | |
2283 * right drag - yes extend no | |
2284 * right relse - yes extend no | |
2285 * | |
2286 * Insert or Replace Mode: | |
2287 * event modi- position visual change action | |
2288 * fier cursor window | |
2289 * left press - yes (cannot be active) yes | |
2290 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2291 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2292 * left drag - yes start or extend (1) no CTRL-O (1) | |
2293 * left relse - yes start or extend (1) no CTRL-O (1) | |
2294 * middle press - no (cannot be active) no put register | |
2295 * right press - yes start or extend yes CTRL-O | |
2296 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2297 * | |
2298 * (1) only if mouse pointer moved since press | |
2299 * (2) only if click is in same buffer | |
2300 * | |
2301 * Return TRUE if start_arrow() should be called for edit mode. | |
2302 */ | |
2303 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2304 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2305 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
|
2306 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2307 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
|
2308 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2309 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2310 { |
2311 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2312 static int got_click = FALSE; /* got a click some time back */ | |
2313 | |
2314 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2315 int is_click; /* If FALSE it's a drag or release event */ | |
2316 int is_drag; /* If TRUE it's a drag event */ | |
2317 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2318 pos_T start_visual; | |
2319 int moved; /* Has cursor moved? */ | |
2320 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
|
2321 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2322 int in_sep_line; /* mouse in vertical separator line */ |
2323 int c1, c2; | |
2324 #if defined(FEAT_FOLDING) | |
2325 pos_T save_cursor; | |
2326 #endif | |
2327 win_T *old_curwin = curwin; | |
2328 static pos_T orig_cursor; | |
2329 colnr_T leftcol, rightcol; | |
2330 pos_T end_visual; | |
2331 int diff; | |
2332 int old_active = VIsual_active; | |
2333 int old_mode = VIsual_mode; | |
2334 int regname; | |
2335 | |
2336 #if defined(FEAT_FOLDING) | |
2337 save_cursor = curwin->w_cursor; | |
2338 #endif | |
2339 | |
2340 /* | |
2341 * When GUI is active, always recognize mouse events, otherwise: | |
2342 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2343 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2344 * - For command line and insert mode 'mouse' is checked before calling | |
2345 * do_mouse(). | |
2346 */ | |
2347 if (do_always) | |
2348 do_always = FALSE; | |
2349 else | |
2350 #ifdef FEAT_GUI | |
2351 if (!gui.in_use) | |
2352 #endif | |
2353 { | |
2354 if (VIsual_active) | |
2355 { | |
2356 if (!mouse_has(MOUSE_VISUAL)) | |
2357 return FALSE; | |
2358 } | |
5735 | 2359 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2360 return FALSE; |
2361 } | |
2362 | |
4221 | 2363 for (;;) |
2364 { | |
2365 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2366 if (is_drag) | |
2367 { | |
2368 /* If the next character is the same mouse event then use that | |
2369 * one. Speeds up dragging the status line. */ | |
2370 if (vpeekc() != NUL) | |
2371 { | |
2372 int nc; | |
2373 int save_mouse_row = mouse_row; | |
2374 int save_mouse_col = mouse_col; | |
2375 | |
2376 /* Need to get the character, peeking doesn't get the actual | |
2377 * one. */ | |
2378 nc = safe_vgetc(); | |
2379 if (c == nc) | |
2380 continue; | |
2381 vungetc(nc); | |
2382 mouse_row = save_mouse_row; | |
2383 mouse_col = save_mouse_col; | |
2384 } | |
2385 } | |
2386 break; | |
2387 } | |
7 | 2388 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2389 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2390 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2391 /* 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
|
2392 #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
|
2393 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2394 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
|
2395 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2396 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
|
2397 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2398 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2399 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2400 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2401 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2402 |
7 | 2403 #ifdef FEAT_MOUSESHAPE |
2404 /* May have stopped dragging the status or separator line. The pointer is | |
2405 * most likely still on the status or separator line. */ | |
2406 if (!is_drag && drag_status_line) | |
2407 { | |
2408 drag_status_line = FALSE; | |
2409 update_mouseshape(SHAPE_IDX_STATUS); | |
2410 } | |
2411 if (!is_drag && drag_sep_line) | |
2412 { | |
2413 drag_sep_line = FALSE; | |
2414 update_mouseshape(SHAPE_IDX_VSEP); | |
2415 } | |
2416 #endif | |
2417 | |
2418 /* | |
2419 * Ignore drag and release events if we didn't get a click. | |
2420 */ | |
2421 if (is_click) | |
2422 got_click = TRUE; | |
2423 else | |
2424 { | |
2425 if (!got_click) /* didn't get click, ignore */ | |
2426 return FALSE; | |
2427 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
|
2428 { |
7 | 2429 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
|
2430 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
|
2431 { |
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
|
2432 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
|
2433 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
|
2434 } |
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
|
2435 } |
7 | 2436 } |
2437 | |
2438 /* | |
2439 * CTRL right mouse button does CTRL-T | |
2440 */ | |
2441 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2442 { | |
2443 if (State & INSERT) | |
2444 stuffcharReadbuff(Ctrl_O); | |
2445 if (count > 1) | |
2446 stuffnumReadbuff(count); | |
2447 stuffcharReadbuff(Ctrl_T); | |
2448 got_click = FALSE; /* ignore drag&release now */ | |
2449 return FALSE; | |
2450 } | |
2451 | |
2452 /* | |
2453 * CTRL only works with left mouse button | |
2454 */ | |
2455 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2456 return FALSE; | |
2457 | |
2458 /* | |
2459 * When a modifier is down, ignore drag and release events, as well as | |
2460 * multiple clicks and the middle mouse button. | |
2461 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2462 */ | |
179 | 2463 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2464 | MOD_MASK_META)) | |
7 | 2465 && (!is_click |
2466 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2467 || which_button == MOUSE_MIDDLE) | |
598 | 2468 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2469 && mouse_model_popup() |
2470 && which_button == MOUSE_LEFT) | |
598 | 2471 && !((mod_mask & MOD_MASK_ALT) |
2472 && !mouse_model_popup() | |
2473 && which_button == MOUSE_RIGHT) | |
7 | 2474 ) |
2475 return FALSE; | |
2476 | |
2477 /* | |
2478 * If the button press was used as the movement command for an operator | |
2479 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2480 * drag/release events. | |
2481 */ | |
2482 if (!is_click && which_button == MOUSE_MIDDLE) | |
2483 return FALSE; | |
2484 | |
2485 if (oap != NULL) | |
2486 regname = oap->regname; | |
2487 else | |
2488 regname = 0; | |
2489 | |
2490 /* | |
2491 * Middle mouse button does a 'put' of the selected text | |
2492 */ | |
2493 if (which_button == MOUSE_MIDDLE) | |
2494 { | |
2495 if (State == NORMAL) | |
2496 { | |
2497 /* | |
2498 * If an operator was pending, we don't know what the user wanted | |
2499 * to do. Go back to normal mode: Clear the operator and beep(). | |
2500 */ | |
2501 if (oap != NULL && oap->op_type != OP_NOP) | |
2502 { | |
2503 clearopbeep(oap); | |
2504 return FALSE; | |
2505 } | |
2506 | |
2507 /* | |
2508 * If visual was active, yank the highlighted text and put it | |
2509 * before the mouse pointer position. | |
1016 | 2510 * In Select mode replace the highlighted text with the clipboard. |
7 | 2511 */ |
2512 if (VIsual_active) | |
2513 { | |
1016 | 2514 if (VIsual_select) |
2515 { | |
2516 stuffcharReadbuff(Ctrl_G); | |
1019 | 2517 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2518 } |
2519 else | |
2520 { | |
2521 stuffcharReadbuff('y'); | |
2522 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2523 } | |
7 | 2524 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2525 return FALSE; | |
2526 } | |
2527 /* | |
2528 * The rest is below jump_to_mouse() | |
2529 */ | |
2530 } | |
2531 | |
2532 else if ((State & INSERT) == 0) | |
2533 return FALSE; | |
2534 | |
2535 /* | |
2536 * Middle click in insert mode doesn't move the mouse, just insert the | |
2537 * contents of a register. '.' register is special, can't insert that | |
2538 * with do_put(). | |
2539 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2540 * happens for the GUI). | |
2541 */ | |
2542 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2543 { | |
2544 if (regname == '.') | |
2545 insert_reg(regname, TRUE); | |
2546 else | |
2547 { | |
2548 #ifdef FEAT_CLIPBOARD | |
2549 if (clip_star.available && regname == 0) | |
2550 regname = '*'; | |
2551 #endif | |
2552 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2553 insert_reg(regname, TRUE); | |
2554 else | |
2555 { | |
2556 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2557 | |
2558 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2559 AppendCharToRedobuff(Ctrl_R); | |
2560 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2561 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2562 } | |
2563 } | |
2564 return FALSE; | |
2565 } | |
2566 } | |
2567 | |
2568 /* When dragging or button-up stay in the same window. */ | |
2569 if (!is_click) | |
2570 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2571 | |
2572 start_visual.lnum = 0; | |
2573 | |
671 | 2574 /* Check for clicking in the tab page line. */ |
2575 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2576 { | |
1619 | 2577 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
|
2578 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2579 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
|
2580 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2581 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2582 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
|
2583 ? 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
|
2584 } |
1619 | 2585 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
|
2586 } |
671 | 2587 |
2588 /* click in a tab selects that tab page */ | |
2589 if (is_click | |
2590 # ifdef FEAT_CMDWIN | |
2591 && cmdwin_type == 0 | |
2592 # endif | |
681 | 2593 && mouse_col < Columns) |
2594 { | |
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
|
2595 in_tab_line = TRUE; |
681 | 2596 c1 = TabPageIdxs[mouse_col]; |
2597 if (c1 >= 0) | |
2598 { | |
682 | 2599 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2600 { | |
2601 /* double click opens new page */ | |
681 | 2602 end_visual_mode(); |
682 | 2603 tabpage_new(); |
2604 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2605 } | |
2606 else | |
2607 { | |
2608 /* Go to specified tab page, or next one if not clicking | |
2609 * on a label. */ | |
2610 goto_tabpage(c1); | |
2611 | |
2612 /* It's like clicking on the status line of a window. */ | |
2613 if (curwin != old_curwin) | |
2614 end_visual_mode(); | |
2615 } | |
681 | 2616 } |
2617 else if (c1 < 0) | |
2618 { | |
2619 tabpage_T *tp; | |
2620 | |
2621 /* Close the current or specified tab page. */ | |
2622 if (c1 == -999) | |
2623 tp = curtab; | |
2624 else | |
2625 tp = find_tabpage(-c1); | |
2626 if (tp == curtab) | |
2627 { | |
2628 if (first_tabpage->tp_next != NULL) | |
2629 tabpage_close(FALSE); | |
2630 } | |
2631 else if (tp != NULL) | |
2632 tabpage_close_other(tp, FALSE); | |
2633 } | |
2634 } | |
2635 return TRUE; | |
671 | 2636 } |
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
|
2637 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
|
2638 { |
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
|
2639 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
|
2640 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
|
2641 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
|
2642 } |
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
|
2643 |
7 | 2644 /* |
2645 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2646 * right button up -> pop-up menu | |
2647 * shift-left button -> right button | |
598 | 2648 * alt-left button -> alt-right button |
7 | 2649 */ |
2650 if (mouse_model_popup()) | |
2651 { | |
2652 if (which_button == MOUSE_RIGHT | |
2653 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2654 { | |
573 | 2655 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2656 || 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
|
2657 || 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
|
2658 || 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
|
2659 # ifdef FEAT_GUI |
7 | 2660 if (gui.in_use) |
2661 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2662 # 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
|
2663 || 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
|
2664 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2665 /* 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
|
2666 * 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
|
2667 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2668 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2669 # 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
|
2670 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
|
2671 /* 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
|
2672 * 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
|
2673 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2674 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2675 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2676 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2677 # 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
|
2678 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2679 # endif |
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_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2681 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2682 /* 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
|
2683 * 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
|
2684 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2685 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2686 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2687 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2688 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
|
2689 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2690 /* 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
|
2691 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2692 if (VIsual_active) |
7 | 2693 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2694 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
|
2695 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2696 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2697 * 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
|
2698 * 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
|
2699 * negative here) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2700 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2701 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
|
2702 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2703 > (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
|
2704 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
|
2705 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
|
2706 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
|
2707 else |
7 | 2708 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2709 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
|
2710 && (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
|
2711 || 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
|
2712 || (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
|
2713 && (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
|
2714 || 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
|
2715 { |
7 | 2716 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
|
2717 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2718 else if (VIsual_mode == Ctrl_V) |
7 | 2719 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2720 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
|
2721 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2722 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
|
2723 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2724 jump_flags = MOUSE_MAY_STOP_VIS; |
2725 } | |
2726 } | |
2727 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2728 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2729 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
|
2730 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2731 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2732 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2733 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
|
2734 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
|
2735 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2736 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
|
2737 } |
7 | 2738 # 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
|
2739 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2740 got_click = FALSE; /* ignore release events */ |
7 | 2741 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2742 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2743 #else |
2744 return FALSE; | |
2745 #endif | |
2746 } | |
598 | 2747 if (which_button == MOUSE_LEFT |
2748 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2749 { |
2750 which_button = MOUSE_RIGHT; | |
2751 mod_mask &= ~MOD_MASK_SHIFT; | |
2752 } | |
2753 } | |
2754 | |
2755 if ((State & (NORMAL | INSERT)) | |
2756 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2757 { | |
2758 if (which_button == MOUSE_LEFT) | |
2759 { | |
2760 if (is_click) | |
2761 { | |
2762 /* stop Visual mode for a left click in a window, but not when | |
2763 * on a status line */ | |
2764 if (VIsual_active) | |
2765 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2766 } | |
2767 else if (mouse_has(MOUSE_VISUAL)) | |
2768 jump_flags |= MOUSE_MAY_VIS; | |
2769 } | |
2770 else if (which_button == MOUSE_RIGHT) | |
2771 { | |
2772 if (is_click && VIsual_active) | |
2773 { | |
2774 /* | |
2775 * Remember the start and end of visual before moving the | |
2776 * cursor. | |
2777 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2778 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2779 { |
2780 start_visual = curwin->w_cursor; | |
2781 end_visual = VIsual; | |
2782 } | |
2783 else | |
2784 { | |
2785 start_visual = VIsual; | |
2786 end_visual = curwin->w_cursor; | |
2787 } | |
2788 } | |
2789 jump_flags |= MOUSE_FOCUS; | |
2790 if (mouse_has(MOUSE_VISUAL)) | |
2791 jump_flags |= MOUSE_MAY_VIS; | |
2792 } | |
2793 } | |
2794 | |
2795 /* | |
2796 * If an operator is pending, ignore all drags and releases until the | |
2797 * next mouse click. | |
2798 */ | |
2799 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2800 { | |
2801 got_click = FALSE; | |
2802 oap->motion_type = MCHAR; | |
2803 } | |
2804 | |
2805 /* When releasing the button let jump_to_mouse() know. */ | |
2806 if (!is_click && !is_drag) | |
2807 jump_flags |= MOUSE_RELEASED; | |
2808 | |
2809 /* | |
2810 * JUMP! | |
2811 */ | |
2812 jump_flags = jump_to_mouse(jump_flags, | |
2813 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
|
2814 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2815 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2816 /* 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
|
2817 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
|
2818 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2819 #endif |
7 | 2820 moved = (jump_flags & CURSOR_MOVED); |
2821 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2822 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2823 | |
2824 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2825 if (isNetbeansBuffer(curbuf) |
7 | 2826 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2827 { | |
2828 int key = KEY2TERMCAP1(c); | |
2829 | |
2830 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2831 || key == (int)KE_RIGHTRELEASE) | |
2832 netbeans_button_release(which_button); | |
2833 } | |
2834 #endif | |
2835 | |
2836 /* When jumping to another window, clear a pending operator. That's a bit | |
2837 * friendlier than beeping and not jumping to that window. */ | |
2838 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2839 clearop(oap); | |
2840 | |
2841 #ifdef FEAT_FOLDING | |
2842 if (mod_mask == 0 | |
2843 && !is_drag | |
2844 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2845 && which_button == MOUSE_LEFT) | |
2846 { | |
2847 /* open or close a fold at this line */ | |
2848 if (jump_flags & MOUSE_FOLD_OPEN) | |
2849 openFold(curwin->w_cursor.lnum, 1L); | |
2850 else | |
2851 closeFold(curwin->w_cursor.lnum, 1L); | |
2852 /* don't move the cursor if still in the same window */ | |
2853 if (curwin == old_curwin) | |
2854 curwin->w_cursor = save_cursor; | |
2855 } | |
2856 #endif | |
2857 | |
2858 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2859 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2860 { | |
2861 clip_modeless(which_button, is_click, is_drag); | |
2862 return FALSE; | |
2863 } | |
2864 #endif | |
2865 | |
2866 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2867 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2868 if (VIsual_active && is_drag && p_so) |
2869 { | |
2870 /* In the very first line, allow scrolling one line */ | |
2871 if (mouse_row == 0) | |
2872 mouse_dragging = 2; | |
2873 else | |
2874 mouse_dragging = 1; | |
2875 } | |
2876 | |
2877 /* When dragging the mouse above the window, scroll down. */ | |
2878 if (is_drag && mouse_row < 0 && !in_status_line) | |
2879 { | |
2880 scroll_redraw(FALSE, 1L); | |
2881 mouse_row = 0; | |
2882 } | |
2883 | |
2884 if (start_visual.lnum) /* right click in visual mode */ | |
2885 { | |
598 | 2886 /* When ALT is pressed make Visual mode blockwise. */ |
2887 if (mod_mask & MOD_MASK_ALT) | |
2888 VIsual_mode = Ctrl_V; | |
2889 | |
7 | 2890 /* |
2891 * In Visual-block mode, divide the area in four, pick up the corner | |
2892 * that is in the quarter that the cursor is in. | |
2893 */ | |
2894 if (VIsual_mode == Ctrl_V) | |
2895 { | |
2896 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2897 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2898 end_visual.col = leftcol; | |
2899 else | |
2900 end_visual.col = rightcol; | |
7009 | 2901 if (curwin->w_cursor.lnum >= |
7 | 2902 (start_visual.lnum + end_visual.lnum) / 2) |
2903 end_visual.lnum = start_visual.lnum; | |
2904 | |
2905 /* move VIsual to the right column */ | |
2906 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2907 curwin->w_cursor = end_visual; | |
2908 coladvance(end_visual.col); | |
2909 VIsual = curwin->w_cursor; | |
2910 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2911 } | |
2912 else | |
2913 { | |
2914 /* | |
2915 * If the click is before the start of visual, change the start. | |
2916 * If the click is after the end of visual, change the end. If | |
2917 * the click is inside the visual, change the closest side. | |
2918 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2919 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2920 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2921 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2922 VIsual = start_visual; |
2923 else | |
2924 { | |
2925 /* In the same line, compare column number */ | |
2926 if (end_visual.lnum == start_visual.lnum) | |
2927 { | |
2928 if (curwin->w_cursor.col - start_visual.col > | |
2929 end_visual.col - curwin->w_cursor.col) | |
2930 VIsual = start_visual; | |
2931 else | |
2932 VIsual = end_visual; | |
2933 } | |
2934 | |
2935 /* In different lines, compare line number */ | |
2936 else | |
2937 { | |
2938 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2939 (end_visual.lnum - curwin->w_cursor.lnum); | |
2940 | |
2941 if (diff > 0) /* closest to end */ | |
2942 VIsual = start_visual; | |
2943 else if (diff < 0) /* closest to start */ | |
2944 VIsual = end_visual; | |
2945 else /* in the middle line */ | |
2946 { | |
2947 if (curwin->w_cursor.col < | |
2948 (start_visual.col + end_visual.col) / 2) | |
2949 VIsual = end_visual; | |
2950 else | |
2951 VIsual = start_visual; | |
2952 } | |
2953 } | |
2954 } | |
2955 } | |
2956 } | |
2957 /* | |
2958 * If Visual mode started in insert mode, execute "CTRL-O" | |
2959 */ | |
2960 else if ((State & INSERT) && VIsual_active) | |
2961 stuffcharReadbuff(Ctrl_O); | |
2962 | |
2963 /* | |
2964 * Middle mouse click: Put text before cursor. | |
2965 */ | |
2966 if (which_button == MOUSE_MIDDLE) | |
2967 { | |
2968 #ifdef FEAT_CLIPBOARD | |
2969 if (clip_star.available && regname == 0) | |
2970 regname = '*'; | |
2971 #endif | |
2972 if (yank_register_mline(regname)) | |
2973 { | |
2974 if (mouse_past_bottom) | |
2975 dir = FORWARD; | |
2976 } | |
2977 else if (mouse_past_eol) | |
2978 dir = FORWARD; | |
2979 | |
2980 if (fixindent) | |
2981 { | |
2982 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2983 c2 = 'p'; | |
2984 } | |
2985 else | |
2986 { | |
2987 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2988 c2 = NUL; | |
2989 } | |
2990 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2991 | |
2992 /* | |
2993 * Remember where the paste started, so in edit() Insstart can be set | |
2994 * to this position | |
2995 */ | |
2996 if (restart_edit != 0) | |
2997 where_paste_started = curwin->w_cursor; | |
2998 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2999 } | |
3000 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3001 #if defined(FEAT_QUICKFIX) |
7 | 3002 /* |
3003 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
3004 * error under the mouse pointer. | |
3005 */ | |
3006 else if (((mod_mask & MOD_MASK_CTRL) | |
3007 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3008 && bt_quickfix(curbuf)) | |
3009 { | |
643 | 3010 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
|
3011 do_cmdline_cmd((char_u *)".cc"); |
643 | 3012 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
|
3013 do_cmdline_cmd((char_u *)".ll"); |
7 | 3014 got_click = FALSE; /* ignore drag&release now */ |
3015 } | |
3016 #endif | |
3017 | |
3018 /* | |
3019 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3020 * under the mouse pointer. | |
3021 */ | |
3022 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3023 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3024 { | |
3025 if (State & INSERT) | |
3026 stuffcharReadbuff(Ctrl_O); | |
3027 stuffcharReadbuff(Ctrl_RSB); | |
3028 got_click = FALSE; /* ignore drag&release now */ | |
3029 } | |
3030 | |
3031 /* | |
3032 * Shift-Mouse click searches for the next occurrence of the word under | |
3033 * the mouse pointer | |
3034 */ | |
3035 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3036 { | |
5735 | 3037 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3038 stuffcharReadbuff(Ctrl_O); |
3039 if (which_button == MOUSE_LEFT) | |
3040 stuffcharReadbuff('*'); | |
3041 else /* MOUSE_RIGHT */ | |
3042 stuffcharReadbuff('#'); | |
3043 } | |
3044 | |
3045 /* Handle double clicks, unless on status line */ | |
3046 else if (in_status_line) | |
3047 { | |
3048 #ifdef FEAT_MOUSESHAPE | |
3049 if ((is_drag || is_click) && !drag_status_line) | |
3050 { | |
3051 drag_status_line = TRUE; | |
3052 update_mouseshape(-1); | |
3053 } | |
3054 #endif | |
3055 } | |
3056 else if (in_sep_line) | |
3057 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3058 #ifdef FEAT_MOUSESHAPE |
7 | 3059 if ((is_drag || is_click) && !drag_sep_line) |
3060 { | |
3061 drag_sep_line = TRUE; | |
3062 update_mouseshape(-1); | |
3063 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3064 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3065 } |
7 | 3066 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3067 && mouse_has(MOUSE_VISUAL)) | |
3068 { | |
3069 if (is_click || !VIsual_active) | |
3070 { | |
3071 if (VIsual_active) | |
3072 orig_cursor = VIsual; | |
3073 else | |
3074 { | |
3075 check_visual_highlight(); | |
3076 VIsual = curwin->w_cursor; | |
3077 orig_cursor = VIsual; | |
3078 VIsual_active = TRUE; | |
3079 VIsual_reselect = TRUE; | |
3080 /* start Select mode if 'selectmode' contains "mouse" */ | |
3081 may_start_select('o'); | |
3082 setmouse(); | |
3083 } | |
3084 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3085 { |
3086 /* Double click with ALT pressed makes it blockwise. */ | |
3087 if (mod_mask & MOD_MASK_ALT) | |
3088 VIsual_mode = Ctrl_V; | |
3089 else | |
3090 VIsual_mode = 'v'; | |
3091 } | |
7 | 3092 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3093 VIsual_mode = 'V'; | |
3094 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3095 VIsual_mode = Ctrl_V; | |
3096 #ifdef FEAT_CLIPBOARD | |
3097 /* Make sure the clipboard gets updated. Needed because start and | |
3098 * end may still be the same, and the selection needs to be owned */ | |
3099 clip_star.vmode = NUL; | |
3100 #endif | |
3101 } | |
3102 /* | |
3103 * A double click selects a word or a block. | |
3104 */ | |
3105 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3106 { | |
3107 pos_T *pos = NULL; | |
300 | 3108 int gc; |
7 | 3109 |
3110 if (is_click) | |
3111 { | |
3112 /* If the character under the cursor (skipping white space) is | |
3113 * not a word character, try finding a match and select a (), | |
3114 * {}, [], #if/#endif, etc. block. */ | |
3115 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
|
3116 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3117 inc(&end_visual); |
3118 if (oap != NULL) | |
3119 oap->motion_type = MCHAR; | |
3120 if (oap != NULL | |
3121 && VIsual_mode == 'v' | |
3122 && !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
|
3123 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3124 && (pos = findmatch(oap, NUL)) != NULL) |
3125 { | |
3126 curwin->w_cursor = *pos; | |
3127 if (oap->motion_type == MLINE) | |
3128 VIsual_mode = 'V'; | |
3129 else if (*p_sel == 'e') | |
3130 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3131 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3132 ++VIsual.col; |
3133 else | |
3134 ++curwin->w_cursor.col; | |
3135 } | |
3136 } | |
3137 } | |
3138 | |
3139 if (pos == NULL && (is_click || is_drag)) | |
3140 { | |
3141 /* When not found a match or when dragging: extend to include | |
3142 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3143 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3144 { |
3145 find_start_of_word(&curwin->w_cursor); | |
3146 find_end_of_word(&VIsual); | |
3147 } | |
3148 else | |
3149 { | |
3150 find_start_of_word(&VIsual); | |
3151 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3152 #ifdef FEAT_MBYTE | |
3153 curwin->w_cursor.col += | |
474 | 3154 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3155 #else |
3156 ++curwin->w_cursor.col; | |
3157 #endif | |
3158 find_end_of_word(&curwin->w_cursor); | |
3159 } | |
3160 } | |
3161 curwin->w_set_curswant = TRUE; | |
3162 } | |
3163 if (is_click) | |
3164 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3165 } | |
3166 else if (VIsual_active && !old_active) | |
598 | 3167 { |
3168 if (mod_mask & MOD_MASK_ALT) | |
3169 VIsual_mode = Ctrl_V; | |
3170 else | |
3171 VIsual_mode = 'v'; | |
3172 } | |
7 | 3173 |
3174 /* If Visual mode changed show it later. */ | |
643 | 3175 if ((!VIsual_active && old_active && mode_displayed) |
3176 || (VIsual_active && p_smd && msg_silent == 0 | |
3177 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3178 redraw_cmdline = TRUE; |
3179 | |
3180 return moved; | |
3181 } | |
3182 | |
3183 /* | |
3184 * Move "pos" back to the start of the word it's in. | |
3185 */ | |
3186 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3187 find_start_of_word(pos_T *pos) |
7 | 3188 { |
3189 char_u *line; | |
3190 int cclass; | |
3191 int col; | |
3192 | |
3193 line = ml_get(pos->lnum); | |
3194 cclass = get_mouse_class(line + pos->col); | |
3195 | |
3196 while (pos->col > 0) | |
3197 { | |
3198 col = pos->col - 1; | |
3199 #ifdef FEAT_MBYTE | |
3200 col -= (*mb_head_off)(line, line + col); | |
3201 #endif | |
3202 if (get_mouse_class(line + col) != cclass) | |
3203 break; | |
3204 pos->col = col; | |
3205 } | |
3206 } | |
3207 | |
3208 /* | |
3209 * Move "pos" forward to the end of the word it's in. | |
3210 * When 'selection' is "exclusive", the position is just after the word. | |
3211 */ | |
3212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3213 find_end_of_word(pos_T *pos) |
7 | 3214 { |
3215 char_u *line; | |
3216 int cclass; | |
3217 int col; | |
3218 | |
3219 line = ml_get(pos->lnum); | |
3220 if (*p_sel == 'e' && pos->col > 0) | |
3221 { | |
3222 --pos->col; | |
3223 #ifdef FEAT_MBYTE | |
3224 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3225 #endif | |
3226 } | |
3227 cclass = get_mouse_class(line + pos->col); | |
3228 while (line[pos->col] != NUL) | |
3229 { | |
3230 #ifdef FEAT_MBYTE | |
474 | 3231 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3232 #else |
3233 col = pos->col + 1; | |
3234 #endif | |
3235 if (get_mouse_class(line + col) != cclass) | |
3236 { | |
3237 if (*p_sel == 'e') | |
3238 pos->col = col; | |
3239 break; | |
3240 } | |
3241 pos->col = col; | |
3242 } | |
3243 } | |
3244 | |
3245 /* | |
3246 * Get class of a character for selection: same class means same word. | |
3247 * 0: blank | |
3248 * 1: punctuation groups | |
3249 * 2: normal word character | |
3250 * >2: multi-byte word character. | |
3251 */ | |
3252 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3253 get_mouse_class(char_u *p) |
7 | 3254 { |
3255 int c; | |
3256 | |
3257 #ifdef FEAT_MBYTE | |
3258 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3259 return mb_get_class(p); | |
3260 #endif | |
3261 | |
3262 c = *p; | |
3263 if (c == ' ' || c == '\t') | |
3264 return 0; | |
3265 | |
3266 if (vim_iswordc(c)) | |
3267 return 2; | |
3268 | |
3269 /* | |
3270 * There are a few special cases where we want certain combinations of | |
3271 * characters to be considered as a single word. These are things like | |
3272 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3273 * character is in its own class. |
7 | 3274 */ |
3275 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3276 return 1; | |
3277 return c; | |
3278 } | |
3279 #endif /* FEAT_MOUSE */ | |
3280 | |
3281 /* | |
3282 * Check if highlighting for visual mode is possible, give a warning message | |
3283 * if not. | |
3284 */ | |
3285 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3286 check_visual_highlight(void) |
7 | 3287 { |
3288 static int did_check = FALSE; | |
3289 | |
3290 if (full_screen) | |
3291 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3292 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3293 MSG(_("Warning: terminal cannot highlight")); |
3294 did_check = TRUE; | |
3295 } | |
3296 } | |
3297 | |
3298 /* | |
638 | 3299 * End Visual mode. |
7 | 3300 * This function should ALWAYS be called to end Visual mode, except from |
3301 * do_pending_operator(). | |
3302 */ | |
3303 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3304 end_visual_mode(void) |
7 | 3305 { |
3306 #ifdef FEAT_CLIPBOARD | |
3307 /* | |
3308 * If we are using the clipboard, then remember what was selected in case | |
3309 * we need to paste it somewhere while we still own the selection. | |
3310 * Only do this when the clipboard is already owned. Don't want to grab | |
3311 * the selection when hitting ESC. | |
3312 */ | |
3313 if (clip_star.available && clip_star.owned) | |
3314 clip_auto_select(); | |
3315 #endif | |
3316 | |
3317 VIsual_active = FALSE; | |
3318 #ifdef FEAT_MOUSE | |
3319 setmouse(); | |
3320 mouse_dragging = 0; | |
3321 #endif | |
3322 | |
3323 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3324 curbuf->b_visual.vi_mode = VIsual_mode; |
3325 curbuf->b_visual.vi_start = VIsual; | |
3326 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3327 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3328 #ifdef FEAT_EVAL |
3329 curbuf->b_visual_mode_eval = VIsual_mode; | |
3330 #endif | |
3331 #ifdef FEAT_VIRTUALEDIT | |
3332 if (!virtual_active()) | |
3333 curwin->w_cursor.coladd = 0; | |
3334 #endif | |
6979 | 3335 may_clear_cmdline(); |
7 | 3336 |
844 | 3337 adjust_cursor_eol(); |
7 | 3338 } |
3339 | |
3340 /* | |
3341 * Reset VIsual_active and VIsual_reselect. | |
3342 */ | |
3343 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3344 reset_VIsual_and_resel(void) |
7 | 3345 { |
3346 if (VIsual_active) | |
3347 { | |
3348 end_visual_mode(); | |
3349 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3350 } | |
3351 VIsual_reselect = FALSE; | |
3352 } | |
3353 | |
3354 /* | |
3355 * Reset VIsual_active and VIsual_reselect if it's set. | |
3356 */ | |
3357 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3358 reset_VIsual(void) |
7 | 3359 { |
3360 if (VIsual_active) | |
3361 { | |
3362 end_visual_mode(); | |
3363 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3364 VIsual_reselect = FALSE; | |
3365 } | |
3366 } | |
3367 | |
3368 /* | |
3369 * Check for a balloon-eval special item to include when searching for an | |
3370 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3371 * Returns TRUE if the character at "*ptr" should be included. | |
3372 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3373 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3374 * "bnp" points to a counter for square brackets. | |
3375 */ | |
3376 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3377 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3378 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3379 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3380 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3381 int dir) |
7 | 3382 { |
3383 /* Accept everything inside []. */ | |
3384 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3385 ++*bnp; | |
3386 if (*bnp > 0) | |
3387 { | |
3388 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3389 --*bnp; | |
3390 return TRUE; | |
3391 } | |
3392 | |
3393 /* skip over "s.var" */ | |
3394 if (*ptr == '.') | |
3395 return TRUE; | |
3396 | |
3397 /* two-character item: s->var */ | |
3398 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3399 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3400 { | |
3401 *colp += dir; | |
3402 return TRUE; | |
3403 } | |
3404 return FALSE; | |
3405 } | |
3406 | |
3407 /* | |
3408 * Find the identifier under or to the right of the cursor. | |
3409 * "find_type" can have one of three values: | |
3410 * FIND_IDENT: find an identifier (keyword) | |
3411 * FIND_STRING: find any non-white string | |
3412 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3413 * FIND_EVAL: find text useful for C program debugging |
7 | 3414 * |
3415 * There are three steps: | |
3416 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3417 * already on one. | |
3418 * 2. Search backward for the start of this identifier/string. | |
3419 * This doesn't match the real Vi but I like it a little better and it | |
3420 * shouldn't bother anyone. | |
3421 * 3. Search forward to the end of this identifier/string. | |
3422 * When FIND_IDENT isn't defined, we backup until a blank. | |
3423 * | |
3424 * Returns the length of the string, or zero if no string is found. | |
3425 * If a string is found, a pointer to the string is put in "*string". This | |
3426 * string is not always NUL terminated. | |
3427 */ | |
3428 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3429 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3430 { |
3431 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3432 curwin->w_cursor.col, string, find_type); | |
3433 } | |
3434 | |
3435 /* | |
3436 * Like find_ident_under_cursor(), but for any window and any position. | |
3437 * However: Uses 'iskeyword' from the current window!. | |
3438 */ | |
3439 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3440 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3441 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3442 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3443 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3444 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3445 int find_type) |
7 | 3446 { |
3447 char_u *ptr; | |
3448 int col = 0; /* init to shut up GCC */ | |
3449 int i; | |
3450 #ifdef FEAT_MBYTE | |
3451 int this_class = 0; | |
3452 int prev_class; | |
3453 int prevcol; | |
3454 #endif | |
3455 int bn = 0; /* bracket nesting */ | |
3456 | |
3457 /* | |
3458 * if i == 0: try to find an identifier | |
3459 * if i == 1: try to find any non-white string | |
3460 */ | |
3461 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3462 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3463 { | |
3464 /* | |
3465 * 1. skip to start of identifier/string | |
3466 */ | |
3467 col = startcol; | |
3468 #ifdef FEAT_MBYTE | |
3469 if (has_mbyte) | |
3470 { | |
3471 while (ptr[col] != NUL) | |
3472 { | |
3473 /* Stop at a ']' to evaluate "a[x]". */ | |
3474 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3475 break; | |
3476 this_class = mb_get_class(ptr + col); | |
3477 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3478 break; | |
474 | 3479 col += (*mb_ptr2len)(ptr + col); |
7 | 3480 } |
3481 } | |
3482 else | |
3483 #endif | |
3484 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
|
3485 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3486 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3487 ) | |
3488 ++col; | |
3489 | |
3490 /* When starting on a ']' count it, so that we include the '['. */ | |
3491 bn = ptr[col] == ']'; | |
3492 | |
3493 /* | |
3494 * 2. Back up to start of identifier/string. | |
3495 */ | |
3496 #ifdef FEAT_MBYTE | |
3497 if (has_mbyte) | |
3498 { | |
3499 /* Remember class of character under cursor. */ | |
3500 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3501 this_class = mb_get_class((char_u *)"a"); | |
3502 else | |
3503 this_class = mb_get_class(ptr + col); | |
835 | 3504 while (col > 0 && this_class != 0) |
7 | 3505 { |
3506 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3507 prev_class = mb_get_class(ptr + prevcol); | |
3508 if (this_class != prev_class | |
3509 && (i == 0 | |
3510 || prev_class == 0 | |
3511 || (find_type & FIND_IDENT)) | |
3512 && (!(find_type & FIND_EVAL) | |
3513 || prevcol == 0 | |
3514 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3515 &bn, BACKWARD)) | |
3516 ) | |
3517 break; | |
3518 col = prevcol; | |
3519 } | |
3520 | |
3521 /* If we don't want just any old string, or we've found an | |
3522 * identifier, stop searching. */ | |
3523 if (this_class > 2) | |
3524 this_class = 2; | |
3525 if (!(find_type & FIND_STRING) || this_class == 2) | |
3526 break; | |
3527 } | |
3528 else | |
3529 #endif | |
3530 { | |
3531 while (col > 0 | |
3532 && ((i == 0 | |
3533 ? 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
|
3534 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3535 && (!(find_type & FIND_IDENT) |
3536 || !vim_iswordc(ptr[col - 1])))) | |
3537 || ((find_type & FIND_EVAL) | |
3538 && col > 1 | |
3539 && find_is_eval_item(ptr + col - 1, &col, | |
3540 &bn, BACKWARD)) | |
3541 )) | |
3542 --col; | |
3543 | |
3544 /* If we don't want just any old string, or we've found an | |
3545 * identifier, stop searching. */ | |
3546 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3547 break; | |
3548 } | |
3549 } | |
3550 | |
3551 if (ptr[col] == NUL || (i == 0 && ( | |
3552 #ifdef FEAT_MBYTE | |
3553 has_mbyte ? this_class != 2 : | |
3554 #endif | |
3555 !vim_iswordc(ptr[col])))) | |
3556 { | |
3557 /* | |
3558 * didn't find an identifier or string | |
3559 */ | |
3560 if (find_type & FIND_STRING) | |
3561 EMSG(_("E348: No string under cursor")); | |
3562 else | |
1728 | 3563 EMSG(_(e_noident)); |
7 | 3564 return 0; |
3565 } | |
3566 ptr += col; | |
3567 *string = ptr; | |
3568 | |
3569 /* | |
3570 * 3. Find the end if the identifier/string. | |
3571 */ | |
3572 bn = 0; | |
3573 startcol -= col; | |
3574 col = 0; | |
3575 #ifdef FEAT_MBYTE | |
3576 if (has_mbyte) | |
3577 { | |
3578 /* Search for point of changing multibyte character class. */ | |
3579 this_class = mb_get_class(ptr); | |
3580 while (ptr[col] != NUL | |
3581 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3582 : mb_get_class(ptr + col) != 0) | |
3583 || ((find_type & FIND_EVAL) | |
3584 && col <= (int)startcol | |
3585 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3586 )) | |
474 | 3587 col += (*mb_ptr2len)(ptr + col); |
7 | 3588 } |
3589 else | |
3590 #endif | |
3591 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
|
3592 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3593 || ((find_type & FIND_EVAL) |
3594 && col <= (int)startcol | |
3595 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3596 ) | |
3597 { | |
3598 ++col; | |
3599 } | |
3600 | |
3601 return col; | |
3602 } | |
3603 | |
3604 /* | |
3605 * Prepare for redo of a normal command. | |
3606 */ | |
3607 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3608 prep_redo_cmd(cmdarg_T *cap) |
7 | 3609 { |
3610 prep_redo(cap->oap->regname, cap->count0, | |
3611 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3612 } | |
3613 | |
3614 /* | |
3615 * Prepare for redo of any command. | |
3616 * Note that only the last argument can be a multi-byte char. | |
3617 */ | |
3618 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3619 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3620 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3621 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3622 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3623 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3624 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3625 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3626 int cmd5) |
7 | 3627 { |
3628 ResetRedobuff(); | |
3629 if (regname != 0) /* yank from specified buffer */ | |
3630 { | |
3631 AppendCharToRedobuff('"'); | |
3632 AppendCharToRedobuff(regname); | |
3633 } | |
3634 if (num) | |
3635 AppendNumberToRedobuff(num); | |
3636 | |
3637 if (cmd1 != NUL) | |
3638 AppendCharToRedobuff(cmd1); | |
3639 if (cmd2 != NUL) | |
3640 AppendCharToRedobuff(cmd2); | |
3641 if (cmd3 != NUL) | |
3642 AppendCharToRedobuff(cmd3); | |
3643 if (cmd4 != NUL) | |
3644 AppendCharToRedobuff(cmd4); | |
3645 if (cmd5 != NUL) | |
3646 AppendCharToRedobuff(cmd5); | |
3647 } | |
3648 | |
3649 /* | |
3650 * check for operator active and clear it | |
3651 * | |
3652 * return TRUE if operator was active | |
3653 */ | |
3654 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3655 checkclearop(oparg_T *oap) |
7 | 3656 { |
3657 if (oap->op_type == OP_NOP) | |
3658 return FALSE; | |
3659 clearopbeep(oap); | |
3660 return TRUE; | |
3661 } | |
3662 | |
3663 /* | |
1131 | 3664 * Check for operator or Visual active. Clear active operator. |
7 | 3665 * |
1131 | 3666 * Return TRUE if operator or Visual was active. |
7 | 3667 */ |
3668 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3669 checkclearopq(oparg_T *oap) |
7 | 3670 { |
5735 | 3671 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3672 return FALSE; |
3673 clearopbeep(oap); | |
3674 return TRUE; | |
3675 } | |
3676 | |
3677 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3678 clearop(oparg_T *oap) |
7 | 3679 { |
3680 oap->op_type = OP_NOP; | |
3681 oap->regname = 0; | |
3682 oap->motion_force = NUL; | |
3683 oap->use_reg_one = FALSE; | |
3684 } | |
3685 | |
3686 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3687 clearopbeep(oparg_T *oap) |
7 | 3688 { |
3689 clearop(oap); | |
3690 beep_flush(); | |
3691 } | |
3692 | |
3693 /* | |
3694 * Remove the shift modifier from a special key. | |
3695 */ | |
3696 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3697 unshift_special(cmdarg_T *cap) |
7 | 3698 { |
3699 switch (cap->cmdchar) | |
3700 { | |
3701 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3702 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3703 case K_S_UP: cap->cmdchar = K_UP; break; | |
3704 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3705 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3706 case K_S_END: cap->cmdchar = K_END; break; | |
3707 } | |
3708 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3709 } | |
3710 | |
6979 | 3711 /* |
3712 * If the mode is currently displayed clear the command line or update the | |
3713 * command displayed. | |
3714 */ | |
3715 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3716 may_clear_cmdline(void) |
6979 | 3717 { |
3718 if (mode_displayed) | |
3719 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3720 #ifdef FEAT_CMDL_INFO | |
3721 else | |
3722 clear_showcmd(); | |
3723 #endif | |
3724 } | |
3725 | |
7 | 3726 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3727 /* | |
3728 * Routines for displaying a partly typed command | |
3729 */ | |
3730 | |
5735 | 3731 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3732 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3733 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3734 static int showcmd_is_clear = TRUE; | |
3735 static int showcmd_visual = FALSE; | |
3736 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3737 static void display_showcmd(void); |
7 | 3738 |
3739 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3740 clear_showcmd(void) |
7 | 3741 { |
3742 if (!p_sc) | |
3743 return; | |
3744 | |
3745 if (VIsual_active && !char_avail()) | |
3746 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3747 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3748 long lines; |
3749 colnr_T leftcol, rightcol; | |
3750 linenr_T top, bot; | |
3751 | |
3752 /* Show the size of the Visual area. */ | |
1866 | 3753 if (cursor_bot) |
7 | 3754 { |
3755 top = VIsual.lnum; | |
3756 bot = curwin->w_cursor.lnum; | |
3757 } | |
3758 else | |
3759 { | |
3760 top = curwin->w_cursor.lnum; | |
3761 bot = VIsual.lnum; | |
3762 } | |
3763 # ifdef FEAT_FOLDING | |
3764 /* Include closed folds as a whole. */ | |
7009 | 3765 (void)hasFolding(top, &top, NULL); |
3766 (void)hasFolding(bot, NULL, &bot); | |
7 | 3767 # endif |
3768 lines = bot - top + 1; | |
3769 | |
3770 if (VIsual_mode == Ctrl_V) | |
3771 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3772 # ifdef FEAT_LINEBREAK |
1866 | 3773 char_u *saved_sbr = p_sbr; |
3774 | |
3775 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3776 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3777 # endif |
7 | 3778 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
|
3779 # ifdef FEAT_LINEBREAK |
1866 | 3780 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3781 # endif |
7 | 3782 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3783 (long)(rightcol - leftcol + 1)); | |
3784 } | |
3785 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3786 sprintf((char *)showcmd_buf, "%ld", lines); | |
3787 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3788 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3789 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
|
3790 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3791 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
|
3792 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
|
3793 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3794 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
|
3795 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3796 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
|
3797 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
|
3798 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3799 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3800 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3801 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
|
3802 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
|
3803 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3804 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
|
3805 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3806 # 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
|
3807 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3808 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3809 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3810 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3811 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
|
3812 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3813 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3814 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3815 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
|
3816 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3817 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3818 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3819 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3820 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3821 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
|
3822 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
|
3823 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3824 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
|
3825 } |
7 | 3826 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3827 showcmd_visual = TRUE; | |
3828 } | |
3829 else | |
3830 { | |
3831 showcmd_buf[0] = NUL; | |
3832 showcmd_visual = FALSE; | |
3833 | |
3834 /* Don't actually display something if there is nothing to clear. */ | |
3835 if (showcmd_is_clear) | |
3836 return; | |
3837 } | |
3838 | |
3839 display_showcmd(); | |
3840 } | |
3841 | |
3842 /* | |
3843 * Add 'c' to string of shown command chars. | |
3844 * Return TRUE if output has been written (and setcursor() has been called). | |
3845 */ | |
3846 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3847 add_to_showcmd(int c) |
7 | 3848 { |
3849 char_u *p; | |
3850 int old_len; | |
3851 int extra_len; | |
3852 int overflow; | |
3853 #if defined(FEAT_MOUSE) | |
3854 int i; | |
3855 static int ignore[] = | |
3856 { | |
660 | 3857 # ifdef FEAT_GUI |
7 | 3858 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3859 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3860 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3861 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
|
3862 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3863 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3864 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
|
3865 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3866 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3867 K_CURSORHOLD, |
7 | 3868 0 |
3869 }; | |
3870 #endif | |
3871 | |
641 | 3872 if (!p_sc || msg_silent != 0) |
7 | 3873 return FALSE; |
3874 | |
3875 if (showcmd_visual) | |
3876 { | |
3877 showcmd_buf[0] = NUL; | |
3878 showcmd_visual = FALSE; | |
3879 } | |
3880 | |
3881 #if defined(FEAT_MOUSE) | |
3882 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3883 if (IS_SPECIAL(c)) | |
3884 for (i = 0; ignore[i] != 0; ++i) | |
3885 if (ignore[i] == c) | |
3886 return FALSE; | |
3887 #endif | |
3888 | |
3889 p = transchar(c); | |
5535 | 3890 if (*p == ' ') |
3891 STRCPY(p, "<20>"); | |
7 | 3892 old_len = (int)STRLEN(showcmd_buf); |
3893 extra_len = (int)STRLEN(p); | |
3894 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3895 if (overflow > 0) | |
1362 | 3896 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3897 old_len - overflow + 1); | |
7 | 3898 STRCAT(showcmd_buf, p); |
3899 | |
3900 if (char_avail()) | |
3901 return FALSE; | |
3902 | |
3903 display_showcmd(); | |
3904 | |
3905 return TRUE; | |
3906 } | |
3907 | |
3908 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3909 add_to_showcmd_c(int c) |
7 | 3910 { |
3911 if (!add_to_showcmd(c)) | |
3912 setcursor(); | |
3913 } | |
3914 | |
3915 /* | |
3916 * Delete 'len' characters from the end of the shown command. | |
3917 */ | |
3918 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3919 del_from_showcmd(int len) |
7 | 3920 { |
3921 int old_len; | |
3922 | |
3923 if (!p_sc) | |
3924 return; | |
3925 | |
3926 old_len = (int)STRLEN(showcmd_buf); | |
3927 if (len > old_len) | |
3928 len = old_len; | |
3929 showcmd_buf[old_len - len] = NUL; | |
3930 | |
3931 if (!char_avail()) | |
3932 display_showcmd(); | |
3933 } | |
3934 | |
3935 /* | |
3936 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3937 * something and there is a partial mapping. | |
3938 */ | |
3939 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3940 push_showcmd(void) |
7 | 3941 { |
3942 if (p_sc) | |
3943 STRCPY(old_showcmd_buf, showcmd_buf); | |
3944 } | |
3945 | |
3946 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3947 pop_showcmd(void) |
7 | 3948 { |
3949 if (!p_sc) | |
3950 return; | |
3951 | |
3952 STRCPY(showcmd_buf, old_showcmd_buf); | |
3953 | |
3954 display_showcmd(); | |
3955 } | |
3956 | |
3957 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3958 display_showcmd(void) |
7 | 3959 { |
3960 int len; | |
3961 | |
3962 cursor_off(); | |
3963 | |
3964 len = (int)STRLEN(showcmd_buf); | |
3965 if (len == 0) | |
3966 showcmd_is_clear = TRUE; | |
3967 else | |
3968 { | |
3969 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3970 showcmd_is_clear = FALSE; | |
3971 } | |
3972 | |
3973 /* | |
1188 | 3974 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3975 * spaces | |
7 | 3976 */ |
3977 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3978 | |
3979 setcursor(); /* put cursor back where it belongs */ | |
3980 } | |
3981 #endif | |
3982 | |
3983 #ifdef FEAT_SCROLLBIND | |
3984 /* | |
3985 * When "check" is FALSE, prepare for commands that scroll the window. | |
3986 * When "check" is TRUE, take care of scroll-binding after the window has | |
3987 * scrolled. Called from normal_cmd() and edit(). | |
3988 */ | |
3989 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3990 do_check_scrollbind(int check) |
7 | 3991 { |
3992 static win_T *old_curwin = NULL; | |
3993 static linenr_T old_topline = 0; | |
3994 #ifdef FEAT_DIFF | |
3995 static int old_topfill = 0; | |
3996 #endif | |
3997 static buf_T *old_buf = NULL; | |
3998 static colnr_T old_leftcol = 0; | |
3999 | |
4000 if (check && curwin->w_p_scb) | |
4001 { | |
4002 /* If a ":syncbind" command was just used, don't scroll, only reset | |
4003 * the values. */ | |
4004 if (did_syncbind) | |
4005 did_syncbind = FALSE; | |
4006 else if (curwin == old_curwin) | |
4007 { | |
4008 /* | |
4009 * Synchronize other windows, as necessary according to | |
4010 * 'scrollbind'. Don't do this after an ":edit" command, except | |
4011 * when 'diff' is set. | |
4012 */ | |
4013 if ((curwin->w_buffer == old_buf | |
4014 #ifdef FEAT_DIFF | |
4015 || curwin->w_p_diff | |
4016 #endif | |
4017 ) | |
4018 && (curwin->w_topline != old_topline | |
4019 #ifdef FEAT_DIFF | |
4020 || curwin->w_topfill != old_topfill | |
4021 #endif | |
4022 || curwin->w_leftcol != old_leftcol)) | |
4023 { | |
4024 check_scrollbind(curwin->w_topline - old_topline, | |
4025 (long)(curwin->w_leftcol - old_leftcol)); | |
4026 } | |
4027 } | |
4028 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4029 { | |
4030 /* | |
4031 * When switching between windows, make sure that the relative | |
4032 * vertical offset is valid for the new window. The relative | |
4033 * offset is invalid whenever another 'scrollbind' window has | |
4034 * scrolled to a point that would force the current window to | |
4035 * scroll past the beginning or end of its buffer. When the | |
4036 * resync is performed, some of the other 'scrollbind' windows may | |
4037 * need to jump so that the current window's relative position is | |
4038 * visible on-screen. | |
4039 */ | |
4040 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4041 } | |
4042 curwin->w_scbind_pos = curwin->w_topline; | |
4043 } | |
4044 | |
4045 old_curwin = curwin; | |
4046 old_topline = curwin->w_topline; | |
4047 #ifdef FEAT_DIFF | |
4048 old_topfill = curwin->w_topfill; | |
4049 #endif | |
4050 old_buf = curwin->w_buffer; | |
4051 old_leftcol = curwin->w_leftcol; | |
4052 } | |
4053 | |
4054 /* | |
4055 * Synchronize any windows that have "scrollbind" set, based on the | |
4056 * number of rows by which the current window has changed | |
4057 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4058 */ | |
4059 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4060 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4061 { |
4062 int want_ver; | |
4063 int want_hor; | |
4064 win_T *old_curwin = curwin; | |
4065 buf_T *old_curbuf = curbuf; | |
4066 int old_VIsual_select = VIsual_select; | |
4067 int old_VIsual_active = VIsual_active; | |
4068 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4069 long topline; | |
4070 long y; | |
4071 | |
4072 /* | |
4073 * check 'scrollopt' string for vertical and horizontal scroll options | |
4074 */ | |
4075 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4076 #ifdef FEAT_DIFF | |
4077 want_ver |= old_curwin->w_p_diff; | |
4078 #endif | |
4079 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4080 | |
4081 /* | |
4082 * loop through the scrollbound windows and scroll accordingly | |
4083 */ | |
4084 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4085 FOR_ALL_WINDOWS(curwin) |
7 | 4086 { |
4087 curbuf = curwin->w_buffer; | |
4088 /* skip original window and windows with 'noscrollbind' */ | |
4089 if (curwin != old_curwin && curwin->w_p_scb) | |
4090 { | |
4091 /* | |
4092 * do the vertical scroll | |
4093 */ | |
4094 if (want_ver) | |
4095 { | |
4096 #ifdef FEAT_DIFF | |
4097 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4098 { | |
4099 diff_set_topline(old_curwin, curwin); | |
4100 } | |
4101 else | |
4102 #endif | |
4103 { | |
4104 curwin->w_scbind_pos += topline_diff; | |
4105 topline = curwin->w_scbind_pos; | |
4106 if (topline > curbuf->b_ml.ml_line_count) | |
4107 topline = curbuf->b_ml.ml_line_count; | |
4108 if (topline < 1) | |
4109 topline = 1; | |
4110 | |
4111 y = topline - curwin->w_topline; | |
4112 if (y > 0) | |
4113 scrollup(y, FALSE); | |
4114 else | |
4115 scrolldown(-y, FALSE); | |
4116 } | |
4117 | |
4118 redraw_later(VALID); | |
4119 cursor_correct(); | |
4120 curwin->w_redr_status = TRUE; | |
4121 } | |
4122 | |
4123 /* | |
4124 * do the horizontal scroll | |
4125 */ | |
4126 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4127 { | |
4128 curwin->w_leftcol = tgt_leftcol; | |
4129 leftcol_changed(); | |
4130 } | |
4131 } | |
4132 } | |
4133 | |
4134 /* | |
4135 * reset current-window | |
4136 */ | |
4137 VIsual_select = old_VIsual_select; | |
4138 VIsual_active = old_VIsual_active; | |
4139 curwin = old_curwin; | |
4140 curbuf = old_curbuf; | |
4141 } | |
4142 #endif /* #ifdef FEAT_SCROLLBIND */ | |
4143 | |
4144 /* | |
4145 * Command character that's ignored. | |
4146 * 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
|
4147 * xon/xoff. |
7 | 4148 */ |
4149 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4150 nv_ignore(cmdarg_T *cap) |
7 | 4151 { |
226 | 4152 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4153 } |
4154 | |
4155 /* | |
620 | 4156 * Command character that doesn't do anything, but unlike nv_ignore() does |
4157 * start edit(). Used for "startinsert" executed while starting up. | |
4158 */ | |
4159 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4160 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4161 { |
4162 } | |
4163 | |
4164 /* | |
7 | 4165 * Command character doesn't exist. |
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_error(cmdarg_T *cap) |
7 | 4169 { |
4170 clearopbeep(cap->oap); | |
4171 } | |
4172 | |
4173 /* | |
4174 * <Help> and <F1> commands. | |
4175 */ | |
4176 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4177 nv_help(cmdarg_T *cap) |
7 | 4178 { |
4179 if (!checkclearopq(cap->oap)) | |
4180 ex_help(NULL); | |
4181 } | |
4182 | |
4183 /* | |
4184 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4185 */ | |
4186 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4187 nv_addsub(cmdarg_T *cap) |
7 | 4188 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4189 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
|
4190 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4191 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4192 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
|
4193 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
|
4194 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4195 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4196 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4197 nv_operator(cap); |
6868 | 4198 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4199 clearop(cap->oap); |
7 | 4200 } |
4201 | |
4202 /* | |
4203 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4204 */ | |
4205 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4206 nv_page(cmdarg_T *cap) |
7 | 4207 { |
4208 if (!checkclearop(cap->oap)) | |
819 | 4209 { |
4210 if (mod_mask & MOD_MASK_CTRL) | |
4211 { | |
4212 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4213 if (cap->arg == BACKWARD) | |
4214 goto_tabpage(-(int)cap->count1); | |
4215 else | |
4216 goto_tabpage((int)cap->count0); | |
4217 } | |
4218 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4219 (void)onepage(cap->arg, cap->count1); |
819 | 4220 } |
7 | 4221 } |
4222 | |
4223 /* | |
4224 * Implementation of "gd" and "gD" command. | |
4225 */ | |
4226 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4227 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4228 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4229 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4230 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4231 { |
4232 int len; | |
503 | 4233 char_u *ptr; |
4234 | |
4235 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
|
4236 || 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
|
4237 == FAIL) |
503 | 4238 clearopbeep(oap); |
4239 #ifdef FEAT_FOLDING | |
4240 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4241 foldOpenCursor(); | |
4242 #endif | |
4243 } | |
4244 | |
4245 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4246 * 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
|
4247 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4248 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4249 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4250 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
|
4251 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4252 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4253 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4254 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4255 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4256 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4257 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
|
4258 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4259 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4260 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4261 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4262 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4263 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 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
|
4265 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 else |
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 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4271 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4272 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4274 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4275 else if (prev == '/' && line[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 incomment = TRUE; |
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 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4280 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4281 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4282 } |
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 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4285 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4286 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4287 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4288 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4289 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4290 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4291 /* |
523 | 4292 * Search for variable declaration of "ptr[len]". |
4293 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4294 * current file ("gD"). | |
4295 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4296 * Return FAIL when not found. |
4297 */ | |
4298 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4299 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4300 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4301 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4302 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4303 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4304 int flags_arg) /* flags passed to searchit() */ |
503 | 4305 { |
7 | 4306 char_u *pat; |
4307 pos_T old_pos; | |
503 | 4308 pos_T par_pos; |
4309 pos_T found_pos; | |
7 | 4310 int t; |
4311 int save_p_ws; | |
4312 int save_p_scs; | |
503 | 4313 int retval = OK; |
944 | 4314 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4315 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4316 int valid; |
503 | 4317 |
4318 if ((pat = alloc(len + 7)) == NULL) | |
4319 return FAIL; | |
268 | 4320 |
4321 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4322 * and "~" causes trouble. */ | |
4323 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4324 len, ptr); | |
7 | 4325 old_pos = curwin->w_cursor; |
4326 save_p_ws = p_ws; | |
4327 save_p_scs = p_scs; | |
4328 p_ws = FALSE; /* don't wrap around end of file now */ | |
4329 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4330 | |
4331 /* | |
4332 * With "gD" go to line 1. | |
4333 * With "gd" Search back for the start of the current function, then go | |
4334 * back until a blank line. If this fails go to line 1. | |
4335 */ | |
944 | 4336 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4337 { |
4338 setpcmark(); /* Set in findpar() otherwise */ | |
4339 curwin->w_cursor.lnum = 1; | |
539 | 4340 par_pos = curwin->w_cursor; |
7 | 4341 } |
4342 else | |
4343 { | |
539 | 4344 par_pos = curwin->w_cursor; |
7 | 4345 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4346 --curwin->w_cursor.lnum; | |
4347 } | |
4348 curwin->w_cursor.col = 0; | |
4349 | |
4350 /* 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
|
4351 CLEAR_POS(&found_pos); |
503 | 4352 for (;;) |
4353 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4354 valid = FALSE; |
503 | 4355 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
|
4356 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4357 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4358 t = FAIL; /* match after start is failure too */ | |
523 | 4359 |
718 | 4360 if (thisblock && t != FAIL) |
523 | 4361 { |
4362 pos_T *pos; | |
4363 | |
4364 /* Check that the block the match is in doesn't end before the | |
4365 * position where we started the search from. */ | |
4366 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4367 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4368 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4369 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4370 /* 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
|
4371 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4372 curwin->w_cursor = *pos; |
523 | 4373 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4374 } |
523 | 4375 } |
4376 | |
503 | 4377 if (t == FAIL) |
4378 { | |
4379 /* If we previously found a valid position, use it. */ | |
4380 if (found_pos.lnum != 0) | |
4381 { | |
4382 curwin->w_cursor = found_pos; | |
4383 t = OK; | |
4384 } | |
4385 break; | |
4386 } | |
7 | 4387 #ifdef FEAT_COMMENTS |
3562 | 4388 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4389 { |
4390 /* Ignore this line, continue at start of next line. */ | |
4391 ++curwin->w_cursor.lnum; | |
4392 curwin->w_cursor.col = 0; | |
4393 continue; | |
4394 } | |
4395 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4396 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
|
4397 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4398 /* 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
|
4399 * 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
|
4400 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4401 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4402 curwin->w_cursor = found_pos; |
503 | 4403 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4404 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4405 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4406 /* 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
|
4407 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4408 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4409 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4410 { |
4411 /* If we previously found a valid position, use it. */ | |
4412 if (found_pos.lnum != 0) | |
4413 curwin->w_cursor = found_pos; | |
4414 break; | |
4415 } | |
4416 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4417 /* 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
|
4418 * 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
|
4419 * 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
|
4420 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4421 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4422 CLEAR_POS(&found_pos); |
10251
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 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4425 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4426 /* 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
|
4427 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4428 searchflags &= ~SEARCH_START; |
503 | 4429 } |
4430 | |
4431 if (t == FAIL) | |
4432 { | |
4433 retval = FAIL; | |
7 | 4434 curwin->w_cursor = old_pos; |
4435 } | |
4436 else | |
4437 { | |
4438 curwin->w_set_curswant = TRUE; | |
4439 /* "n" searches forward now */ | |
4440 reset_search_dir(); | |
4441 } | |
4442 | |
4443 vim_free(pat); | |
4444 p_ws = save_p_ws; | |
4445 p_scs = save_p_scs; | |
503 | 4446 |
4447 return retval; | |
7 | 4448 } |
4449 | |
4450 /* | |
4451 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4452 * lines rather than lines in the file. | |
4453 * 'dist' must be positive. | |
4454 * | |
4455 * Return OK if able to move cursor, FAIL otherwise. | |
4456 */ | |
4457 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4458 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4459 { |
4460 int linelen = linetabsize(ml_get_curline()); | |
4461 int retval = OK; | |
4462 int atend = FALSE; | |
4463 int n; | |
4464 int col_off1; /* margin offset for first screen line */ | |
4465 int col_off2; /* margin offset for wrapped screen line */ | |
4466 int width1; /* text width for first screen line */ | |
4467 int width2; /* test width for wrapped screen line */ | |
4468 | |
4469 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4470 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4471 |
4472 col_off1 = curwin_col_off(); | |
4473 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
|
4474 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
|
4475 width2 = curwin->w_width - col_off2; |
6559 | 4476 if (width2 == 0) |
4477 width2 = 1; /* avoid divide by zero */ | |
7 | 4478 |
4479 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4480 { |
7 | 4481 /* |
4482 * Instead of sticking at the last character of the buffer line we | |
4483 * try to stick in the last column of the screen. | |
4484 */ | |
4485 if (curwin->w_curswant == MAXCOL) | |
4486 { | |
4487 atend = TRUE; | |
4488 validate_virtcol(); | |
4489 if (width1 <= 0) | |
4490 curwin->w_curswant = 0; | |
4491 else | |
4492 { | |
4493 curwin->w_curswant = width1 - 1; | |
4494 if (curwin->w_virtcol > curwin->w_curswant) | |
4495 curwin->w_curswant += ((curwin->w_virtcol | |
4496 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4497 } | |
4498 } | |
4499 else | |
4500 { | |
4501 if (linelen > width1) | |
4502 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4503 else | |
4504 n = width1; | |
4505 if (curwin->w_curswant > (colnr_T)n + 1) | |
4506 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4507 * width2; | |
4508 } | |
4509 | |
4510 while (dist--) | |
4511 { | |
4512 if (dir == BACKWARD) | |
4513 { | |
4514 if ((long)curwin->w_curswant >= width2) | |
4515 /* move back within line */ | |
4516 curwin->w_curswant -= width2; | |
4517 else | |
4518 { | |
4519 /* to previous line */ | |
4520 if (curwin->w_cursor.lnum == 1) | |
4521 { | |
4522 retval = FAIL; | |
4523 break; | |
4524 } | |
4525 --curwin->w_cursor.lnum; | |
4526 #ifdef FEAT_FOLDING | |
4527 /* Move to the start of a closed fold. Don't do that when | |
4528 * 'foldopen' contains "all": it will open in a moment. */ | |
4529 if (!(fdo_flags & FDO_ALL)) | |
4530 (void)hasFolding(curwin->w_cursor.lnum, | |
4531 &curwin->w_cursor.lnum, NULL); | |
4532 #endif | |
4533 linelen = linetabsize(ml_get_curline()); | |
4534 if (linelen > width1) | |
4535 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4536 + 1) * width2; | |
4537 } | |
4538 } | |
4539 else /* dir == FORWARD */ | |
4540 { | |
4541 if (linelen > width1) | |
4542 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4543 else | |
4544 n = width1; | |
4545 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4546 /* move forward within line */ | |
4547 curwin->w_curswant += width2; | |
4548 else | |
4549 { | |
4550 /* to next line */ | |
4551 #ifdef FEAT_FOLDING | |
4552 /* Move to the end of a closed fold. */ | |
4553 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4554 &curwin->w_cursor.lnum); | |
4555 #endif | |
4556 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4557 { | |
4558 retval = FAIL; | |
4559 break; | |
4560 } | |
4561 curwin->w_cursor.lnum++; | |
4562 curwin->w_curswant %= width2; | |
2911 | 4563 linelen = linetabsize(ml_get_curline()); |
7 | 4564 } |
4565 } | |
4566 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4567 } |
7 | 4568 |
5600 | 4569 if (virtual_active() && atend) |
4570 coladvance(MAXCOL); | |
4571 else | |
4572 coladvance(curwin->w_curswant); | |
7 | 4573 |
4574 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4575 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4576 { | |
6178 | 4577 colnr_T virtcol; |
4578 | |
7 | 4579 /* |
4580 * Check for landing on a character that got split at the end of the | |
4581 * last line. We want to advance a screenline, not end up in the same | |
4582 * screenline or move two screenlines. | |
4583 */ | |
4584 validate_virtcol(); | |
6178 | 4585 virtcol = curwin->w_virtcol; |
6187 | 4586 # if defined(FEAT_LINEBREAK) |
6178 | 4587 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4588 virtcol -= vim_strsize(p_sbr); | |
6187 | 4589 # endif |
6178 | 4590 |
4591 if (virtcol > curwin->w_curswant | |
7 | 4592 && (curwin->w_curswant < (colnr_T)width1 |
4593 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4594 : ((curwin->w_curswant - width1) % width2 | |
4595 > (colnr_T)width2 / 2))) | |
4596 --curwin->w_cursor.col; | |
4597 } | |
4598 #endif | |
4599 | |
4600 if (atend) | |
4601 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4602 | |
4603 return retval; | |
4604 } | |
4605 | |
4606 #ifdef FEAT_MOUSE | |
4607 /* | |
4608 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4609 * 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
|
4610 * 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
|
4611 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4612 */ |
4613 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4614 nv_mousescroll(cmdarg_T *cap) |
7 | 4615 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4616 win_T *old_curwin = curwin, *wp; |
7 | 4617 |
4162 | 4618 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4619 { |
4620 int row, col; | |
4621 | |
4622 row = mouse_row; | |
4623 col = mouse_col; | |
4624 | |
4625 /* 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
|
4626 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
|
4627 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
|
4628 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4629 curwin = wp; |
7 | 4630 curbuf = curwin->w_buffer; |
4631 } | |
4632 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4633 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
|
4634 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4635 # 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
|
4636 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
|
4637 /* 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
|
4638 * 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
|
4639 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
|
4640 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4641 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4642 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
|
4643 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4644 (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
|
4645 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4646 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4647 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4648 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4649 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4650 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4651 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4652 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4653 # ifdef FEAT_GUI |
7 | 4654 else |
4655 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4656 /* 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
|
4657 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4658 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4659 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4660 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4661 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
|
4662 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4663 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
|
4664 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4665 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4666 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4667 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4668 } |
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 # endif |
7 | 4671 |
4672 curwin->w_redr_status = TRUE; | |
4673 | |
4674 curwin = old_curwin; | |
4675 curbuf = curwin->w_buffer; | |
4676 } | |
4677 | |
4678 /* | |
4679 * Mouse clicks and drags. | |
4680 */ | |
4681 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4682 nv_mouse(cmdarg_T *cap) |
7 | 4683 { |
4684 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4685 } | |
4686 #endif | |
4687 | |
4688 /* | |
4689 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4690 * cap->arg must be TRUE for CTRL-E. | |
4691 */ | |
4692 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4693 nv_scroll_line(cmdarg_T *cap) |
7 | 4694 { |
4695 if (!checkclearop(cap->oap)) | |
4696 scroll_redraw(cap->arg, cap->count1); | |
4697 } | |
4698 | |
4699 /* | |
4700 * Scroll "count" lines up or down, and redraw. | |
4701 */ | |
4702 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4703 scroll_redraw(int up, long count) |
7 | 4704 { |
4705 linenr_T prev_topline = curwin->w_topline; | |
4706 #ifdef FEAT_DIFF | |
4707 int prev_topfill = curwin->w_topfill; | |
4708 #endif | |
4709 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4710 | |
4711 if (up) | |
4712 scrollup(count, TRUE); | |
4713 else | |
4714 scrolldown(count, TRUE); | |
4715 if (p_so) | |
4716 { | |
4717 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4718 * valid, otherwise the screen jumps back at the end of the file. */ | |
4719 cursor_correct(); | |
4720 check_cursor_moved(curwin); | |
4721 curwin->w_valid |= VALID_TOPLINE; | |
4722 | |
4723 /* If moved back to where we were, at least move the cursor, otherwise | |
4724 * we get stuck at one position. Don't move the cursor up if the | |
4725 * first line of the buffer is already on the screen */ | |
4726 while (curwin->w_topline == prev_topline | |
4727 #ifdef FEAT_DIFF | |
4728 && curwin->w_topfill == prev_topfill | |
4729 #endif | |
4730 ) | |
4731 { | |
4732 if (up) | |
4733 { | |
4734 if (curwin->w_cursor.lnum > prev_lnum | |
4735 || cursor_down(1L, FALSE) == FAIL) | |
4736 break; | |
4737 } | |
4738 else | |
4739 { | |
4740 if (curwin->w_cursor.lnum < prev_lnum | |
4741 || prev_topline == 1L | |
4742 || cursor_up(1L, FALSE) == FAIL) | |
4743 break; | |
4744 } | |
4745 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4746 * end of the file. */ | |
4747 check_cursor_moved(curwin); | |
4748 curwin->w_valid |= VALID_TOPLINE; | |
4749 } | |
4750 } | |
4751 if (curwin->w_cursor.lnum != prev_lnum) | |
4752 coladvance(curwin->w_curswant); | |
4753 redraw_later(VALID); | |
4754 } | |
4755 | |
4756 /* | |
4757 * Commands that start with "z". | |
4758 */ | |
4759 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4760 nv_zet(cmdarg_T *cap) |
7 | 4761 { |
4762 long n; | |
4763 colnr_T col; | |
4764 int nchar = cap->nchar; | |
4765 #ifdef FEAT_FOLDING | |
4766 long old_fdl = curwin->w_p_fdl; | |
4767 int old_fen = curwin->w_p_fen; | |
4768 #endif | |
737 | 4769 #ifdef FEAT_SPELL |
710 | 4770 int undo = FALSE; |
4771 #endif | |
7 | 4772 |
4773 if (VIM_ISDIGIT(nchar)) | |
4774 { | |
4775 /* | |
4776 * "z123{nchar}": edit the count before obtaining {nchar} | |
4777 */ | |
4778 if (checkclearop(cap->oap)) | |
4779 return; | |
4780 n = nchar - '0'; | |
4781 for (;;) | |
4782 { | |
4783 #ifdef USE_ON_FLY_SCROLL | |
4784 dont_scroll = TRUE; /* disallow scrolling here */ | |
4785 #endif | |
4786 ++no_mapping; | |
4787 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4788 nchar = plain_vgetc(); |
7 | 4789 LANGMAP_ADJUST(nchar, TRUE); |
4790 --no_mapping; | |
4791 --allow_keys; | |
4792 #ifdef FEAT_CMDL_INFO | |
4793 (void)add_to_showcmd(nchar); | |
4794 #endif | |
4795 if (nchar == K_DEL || nchar == K_KDEL) | |
4796 n /= 10; | |
4797 else if (VIM_ISDIGIT(nchar)) | |
4798 n = n * 10 + (nchar - '0'); | |
4799 else if (nchar == CAR) | |
4800 { | |
4801 #ifdef FEAT_GUI | |
4802 need_mouse_correct = TRUE; | |
4803 #endif | |
4804 win_setheight((int)n); | |
4805 break; | |
4806 } | |
4807 else if (nchar == 'l' | |
4808 || nchar == 'h' | |
4809 || nchar == K_LEFT | |
229 | 4810 || nchar == K_RIGHT) |
7 | 4811 { |
4812 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4813 goto dozet; | |
4814 } | |
4815 else | |
4816 { | |
4817 clearopbeep(cap->oap); | |
4818 break; | |
4819 } | |
4820 } | |
4821 cap->oap->op_type = OP_NOP; | |
4822 return; | |
4823 } | |
4824 | |
4825 dozet: | |
4826 if ( | |
4827 #ifdef FEAT_FOLDING | |
4828 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4829 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4830 * commands. */ | |
4831 cap->nchar != 'f' && cap->nchar != 'F' | |
4832 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4833 && cap->nchar != 'j' && cap->nchar != 'k' | |
4834 && | |
4835 #endif | |
4836 checkclearop(cap->oap)) | |
4837 return; | |
4838 | |
4839 /* | |
4840 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4841 * If line number given, set cursor. | |
4842 */ | |
4843 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4844 && cap->count0 | |
4845 && cap->count0 != curwin->w_cursor.lnum) | |
4846 { | |
4847 setpcmark(); | |
4848 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4849 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4850 else | |
4851 curwin->w_cursor.lnum = cap->count0; | |
22 | 4852 check_cursor_col(); |
7 | 4853 } |
4854 | |
4855 switch (nchar) | |
4856 { | |
4857 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4858 case '+': | |
4859 if (cap->count0 == 0) | |
4860 { | |
4861 /* No count given: put cursor at the line below screen */ | |
4862 validate_botline(); /* make sure w_botline is valid */ | |
4863 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4864 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4865 else | |
4866 curwin->w_cursor.lnum = curwin->w_botline; | |
4867 } | |
4868 /* FALLTHROUGH */ | |
4869 case NL: | |
4870 case CAR: | |
4871 case K_KENTER: | |
4872 beginline(BL_WHITE | BL_FIX); | |
4873 /* FALLTHROUGH */ | |
4874 | |
4875 case 't': scroll_cursor_top(0, TRUE); | |
4876 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4877 set_fraction(curwin); |
7 | 4878 break; |
4879 | |
4880 /* "z." and "zz": put cursor in middle of screen */ | |
4881 case '.': beginline(BL_WHITE | BL_FIX); | |
4882 /* FALLTHROUGH */ | |
4883 | |
4884 case 'z': scroll_cursor_halfway(TRUE); | |
4885 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4886 set_fraction(curwin); |
7 | 4887 break; |
4888 | |
4889 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4890 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4891 * when <count> is at bottom of window, and puts that one at | |
4892 * bottom of window. */ | |
4893 if (cap->count0 != 0) | |
4894 { | |
4895 scroll_cursor_bot(0, TRUE); | |
4896 curwin->w_cursor.lnum = curwin->w_topline; | |
4897 } | |
4898 else if (curwin->w_topline == 1) | |
4899 curwin->w_cursor.lnum = 1; | |
4900 else | |
4901 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4902 /* FALLTHROUGH */ | |
4903 case '-': | |
4904 beginline(BL_WHITE | BL_FIX); | |
4905 /* FALLTHROUGH */ | |
4906 | |
4907 case 'b': scroll_cursor_bot(0, TRUE); | |
4908 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4909 set_fraction(curwin); |
7 | 4910 break; |
4911 | |
4912 /* "zH" - scroll screen right half-page */ | |
4913 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4914 cap->count1 *= curwin->w_width / 2; |
7 | 4915 /* FALLTHROUGH */ |
4916 | |
4917 /* "zh" - scroll screen to the right */ | |
4918 case 'h': | |
4919 case K_LEFT: | |
4920 if (!curwin->w_p_wrap) | |
4921 { | |
4922 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4923 curwin->w_leftcol = 0; | |
4924 else | |
4925 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4926 leftcol_changed(); | |
4927 } | |
4928 break; | |
4929 | |
4930 /* "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
|
4931 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4932 /* FALLTHROUGH */ |
4933 | |
4934 /* "zl" - scroll screen to the left */ | |
4935 case 'l': | |
4936 case K_RIGHT: | |
4937 if (!curwin->w_p_wrap) | |
4938 { | |
4939 /* scroll the window left */ | |
4940 curwin->w_leftcol += (colnr_T)cap->count1; | |
4941 leftcol_changed(); | |
4942 } | |
4943 break; | |
4944 | |
4945 /* "zs" - scroll screen, cursor at the start */ | |
4946 case 's': if (!curwin->w_p_wrap) | |
4947 { | |
4948 #ifdef FEAT_FOLDING | |
4949 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4950 col = 0; /* like the cursor is in col 0 */ | |
4951 else | |
4952 #endif | |
4953 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4954 if ((long)col > p_siso) | |
4955 col -= p_siso; | |
4956 else | |
4957 col = 0; | |
4958 if (curwin->w_leftcol != col) | |
4959 { | |
4960 curwin->w_leftcol = col; | |
4961 redraw_later(NOT_VALID); | |
4962 } | |
4963 } | |
4964 break; | |
4965 | |
4966 /* "ze" - scroll screen, cursor at the end */ | |
4967 case 'e': if (!curwin->w_p_wrap) | |
4968 { | |
4969 #ifdef FEAT_FOLDING | |
4970 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4971 col = 0; /* like the cursor is in col 0 */ | |
4972 else | |
4973 #endif | |
4974 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
|
4975 n = curwin->w_width - curwin_col_off(); |
7 | 4976 if ((long)col + p_siso < n) |
4977 col = 0; | |
4978 else | |
4979 col = col + p_siso - n + 1; | |
4980 if (curwin->w_leftcol != col) | |
4981 { | |
4982 curwin->w_leftcol = col; | |
4983 redraw_later(NOT_VALID); | |
4984 } | |
4985 } | |
4986 break; | |
4987 | |
4988 #ifdef FEAT_FOLDING | |
4989 /* "zF": create fold command */ | |
4990 /* "zf": create fold operator */ | |
4991 case 'F': | |
4992 case 'f': if (foldManualAllowed(TRUE)) | |
4993 { | |
4994 cap->nchar = 'f'; | |
4995 nv_operator(cap); | |
4996 curwin->w_p_fen = TRUE; | |
4997 | |
4998 /* "zF" is like "zfzf" */ | |
4999 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
5000 { | |
5001 nv_operator(cap); | |
5002 finish_op = TRUE; | |
5003 } | |
5004 } | |
5005 else | |
5006 clearopbeep(cap->oap); | |
5007 break; | |
5008 | |
5009 /* "zd": delete fold at cursor */ | |
5010 /* "zD": delete fold at cursor recursively */ | |
5011 case 'd': | |
5012 case 'D': if (foldManualAllowed(FALSE)) | |
5013 { | |
5014 if (VIsual_active) | |
5015 nv_operator(cap); | |
5016 else | |
5017 deleteFold(curwin->w_cursor.lnum, | |
5018 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5019 } | |
5020 break; | |
5021 | |
4352 | 5022 /* "zE": erase all folds */ |
7 | 5023 case 'E': if (foldmethodIsManual(curwin)) |
5024 { | |
5025 clearFolding(curwin); | |
5026 changed_window_setting(); | |
5027 } | |
5028 else if (foldmethodIsMarker(curwin)) | |
5029 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5030 TRUE, FALSE); | |
5031 else | |
5032 EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); | |
5033 break; | |
5034 | |
5035 /* "zn": fold none: reset 'foldenable' */ | |
5036 case 'n': curwin->w_p_fen = FALSE; | |
5037 break; | |
5038 | |
5039 /* "zN": fold Normal: set 'foldenable' */ | |
5040 case 'N': curwin->w_p_fen = TRUE; | |
5041 break; | |
5042 | |
5043 /* "zi": invert folding: toggle 'foldenable' */ | |
5044 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5045 break; | |
5046 | |
5047 /* "za": open closed fold or close open fold at cursor */ | |
5048 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5049 openFold(curwin->w_cursor.lnum, cap->count1); | |
5050 else | |
5051 { | |
5052 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5053 curwin->w_p_fen = TRUE; | |
5054 } | |
5055 break; | |
5056 | |
5057 /* "zA": open fold at cursor recursively */ | |
5058 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5059 openFoldRecurse(curwin->w_cursor.lnum); | |
5060 else | |
5061 { | |
5062 closeFoldRecurse(curwin->w_cursor.lnum); | |
5063 curwin->w_p_fen = TRUE; | |
5064 } | |
5065 break; | |
5066 | |
5067 /* "zo": open fold at cursor or Visual area */ | |
5068 case 'o': if (VIsual_active) | |
5069 nv_operator(cap); | |
5070 else | |
5071 openFold(curwin->w_cursor.lnum, cap->count1); | |
5072 break; | |
5073 | |
5074 /* "zO": open fold recursively */ | |
5075 case 'O': if (VIsual_active) | |
5076 nv_operator(cap); | |
5077 else | |
5078 openFoldRecurse(curwin->w_cursor.lnum); | |
5079 break; | |
5080 | |
5081 /* "zc": close fold at cursor or Visual area */ | |
5082 case 'c': if (VIsual_active) | |
5083 nv_operator(cap); | |
5084 else | |
5085 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5086 curwin->w_p_fen = TRUE; | |
5087 break; | |
5088 | |
5089 /* "zC": close fold recursively */ | |
5090 case 'C': if (VIsual_active) | |
5091 nv_operator(cap); | |
5092 else | |
5093 closeFoldRecurse(curwin->w_cursor.lnum); | |
5094 curwin->w_p_fen = TRUE; | |
5095 break; | |
5096 | |
5097 /* "zv": open folds at the cursor */ | |
5098 case 'v': foldOpenCursor(); | |
5099 break; | |
5100 | |
5101 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5102 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5103 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5104 newFoldLevel(); /* update right now */ |
7 | 5105 foldOpenCursor(); |
5106 break; | |
5107 | |
5108 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5109 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5110 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5111 old_fdl = -1; /* force an update */ |
7 | 5112 break; |
5113 | |
5114 /* "zm": fold more */ | |
5115 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5116 { |
5117 curwin->w_p_fdl -= cap->count1; | |
5118 if (curwin->w_p_fdl < 0) | |
5119 curwin->w_p_fdl = 0; | |
5120 } | |
7 | 5121 old_fdl = -1; /* force an update */ |
5122 curwin->w_p_fen = TRUE; | |
5123 break; | |
5124 | |
5125 /* "zM": close all folds */ | |
5126 case 'M': curwin->w_p_fdl = 0; | |
5127 old_fdl = -1; /* force an update */ | |
5128 curwin->w_p_fen = TRUE; | |
5129 break; | |
5130 | |
5131 /* "zr": reduce folding */ | |
6725 | 5132 case 'r': curwin->w_p_fdl += cap->count1; |
5133 { | |
5134 int d = getDeepestNesting(); | |
5135 | |
5136 if (curwin->w_p_fdl >= d) | |
5137 curwin->w_p_fdl = d; | |
5138 } | |
7 | 5139 break; |
5140 | |
5141 /* "zR": open all folds */ | |
5142 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5143 old_fdl = -1; /* force an update */ | |
5144 break; | |
5145 | |
5146 case 'j': /* "zj" move to next fold downwards */ | |
5147 case 'k': /* "zk" move to next fold upwards */ | |
5148 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5149 cap->count1) == FAIL) | |
5150 clearopbeep(cap->oap); | |
5151 break; | |
5152 | |
5153 #endif /* FEAT_FOLDING */ | |
5154 | |
737 | 5155 #ifdef FEAT_SPELL |
710 | 5156 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5157 ++no_mapping; | |
5158 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5159 nchar = plain_vgetc(); |
710 | 5160 LANGMAP_ADJUST(nchar, TRUE); |
5161 --no_mapping; | |
5162 --allow_keys; | |
5163 #ifdef FEAT_CMDL_INFO | |
5164 (void)add_to_showcmd(nchar); | |
5165 #endif | |
5166 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5167 { | |
5168 clearopbeep(cap->oap); | |
5169 break; | |
5170 } | |
5171 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5172 /* FALLTHROUGH */ |
710 | 5173 |
310 | 5174 case 'g': /* "zg": add good word to word list */ |
5175 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5176 case 'G': /* "zG": add good word to temp word list */ |
5177 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5178 { |
5179 char_u *ptr = NULL; | |
5180 int len; | |
5181 | |
5182 if (checkclearop(cap->oap)) | |
5183 break; | |
5184 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5185 == FAIL) | |
5186 return; | |
501 | 5187 if (ptr == NULL) |
5188 { | |
5189 pos_T pos = curwin->w_cursor; | |
5190 | |
5374 | 5191 /* Find bad word under the cursor. When 'spell' is |
5192 * off this fails and find_ident_under_cursor() is | |
5193 * used below. */ | |
5194 emsg_off++; | |
534 | 5195 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5196 emsg_off--; |
501 | 5197 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5198 ptr = ml_get_pos(&curwin->w_cursor); | |
5199 curwin->w_cursor = pos; | |
5200 } | |
5201 | |
310 | 5202 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5203 FIND_IDENT)) == 0) | |
5204 return; | |
381 | 5205 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5206 (nchar == 'G' || nchar == 'W') |
5207 ? 0 : (int)cap->count1, | |
5208 undo); | |
310 | 5209 } |
316 | 5210 break; |
323 | 5211 |
584 | 5212 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5213 if (!checkclearop(cap->oap)) |
485 | 5214 spell_suggest((int)cap->count0); |
323 | 5215 break; |
310 | 5216 #endif |
5217 | |
7 | 5218 default: clearopbeep(cap->oap); |
5219 } | |
5220 | |
5221 #ifdef FEAT_FOLDING | |
5222 /* Redraw when 'foldenable' changed */ | |
5223 if (old_fen != curwin->w_p_fen) | |
5224 { | |
5225 # ifdef FEAT_DIFF | |
5226 win_T *wp; | |
5227 | |
5228 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5229 { | |
5230 /* Adjust 'foldenable' in diff-synced windows. */ | |
5231 FOR_ALL_WINDOWS(wp) | |
5232 { | |
5233 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5234 { | |
5235 wp->w_p_fen = curwin->w_p_fen; | |
5236 changed_window_setting_win(wp); | |
5237 } | |
5238 } | |
5239 } | |
5240 # endif | |
5241 changed_window_setting(); | |
5242 } | |
5243 | |
5244 /* Redraw when 'foldlevel' changed. */ | |
5245 if (old_fdl != curwin->w_p_fdl) | |
5246 newFoldLevel(); | |
5247 #endif | |
5248 } | |
5249 | |
5250 #ifdef FEAT_GUI | |
5251 /* | |
5252 * Vertical scrollbar movement. | |
5253 */ | |
5254 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5255 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5256 { |
5257 if (cap->oap->op_type != OP_NOP) | |
5258 clearopbeep(cap->oap); | |
5259 | |
5260 /* Even if an operator was pending, we still want to scroll */ | |
5261 gui_do_scroll(); | |
5262 } | |
5263 | |
5264 /* | |
5265 * Horizontal scrollbar movement. | |
5266 */ | |
5267 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5268 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5269 { |
5270 if (cap->oap->op_type != OP_NOP) | |
5271 clearopbeep(cap->oap); | |
5272 | |
5273 /* 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
|
5274 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5275 } |
5276 #endif | |
5277 | |
690 | 5278 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5279 /* |
5280 * Click in GUI tab. | |
5281 */ | |
5282 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5283 nv_tabline(cmdarg_T *cap) |
685 | 5284 { |
5285 if (cap->oap->op_type != OP_NOP) | |
5286 clearopbeep(cap->oap); | |
5287 | |
5288 /* Even if an operator was pending, we still want to jump tabs. */ | |
5289 goto_tabpage(current_tab); | |
5290 } | |
686 | 5291 |
5292 /* | |
5293 * Selected item in tab line menu. | |
5294 */ | |
5295 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5296 nv_tabmenu(cmdarg_T *cap) |
686 | 5297 { |
5298 if (cap->oap->op_type != OP_NOP) | |
5299 clearopbeep(cap->oap); | |
5300 | |
5301 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5302 handle_tabmenu(); |
5303 } | |
5304 | |
5305 /* | |
5306 * Handle selecting an item of the GUI tab line menu. | |
5307 * Used in Normal and Insert mode. | |
5308 */ | |
5309 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5310 handle_tabmenu(void) |
690 | 5311 { |
686 | 5312 switch (current_tabmenu) |
5313 { | |
5314 case TABLINE_MENU_CLOSE: | |
5315 if (current_tab == 0) | |
5316 do_cmdline_cmd((char_u *)"tabclose"); | |
5317 else | |
5318 { | |
5319 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5320 current_tab); | |
5321 do_cmdline_cmd(IObuff); | |
5322 } | |
5323 break; | |
5324 | |
5325 case TABLINE_MENU_NEW: | |
6631 | 5326 if (current_tab == 0) |
5327 do_cmdline_cmd((char_u *)"$tabnew"); | |
5328 else | |
5329 { | |
5330 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5331 current_tab - 1); | |
5332 do_cmdline_cmd(IObuff); | |
5333 } | |
686 | 5334 break; |
5335 | |
5336 case TABLINE_MENU_OPEN: | |
6631 | 5337 if (current_tab == 0) |
5338 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5339 else | |
5340 { | |
5341 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5342 current_tab - 1); | |
5343 do_cmdline_cmd(IObuff); | |
5344 } | |
686 | 5345 break; |
5346 } | |
5347 } | |
685 | 5348 #endif |
5349 | |
7 | 5350 /* |
5351 * "Q" command. | |
5352 */ | |
5353 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5354 nv_exmode(cmdarg_T *cap) |
7 | 5355 { |
5356 /* | |
5357 * Ignore 'Q' in Visual mode, just give a beep. | |
5358 */ | |
5359 if (VIsual_active) | |
6949 | 5360 vim_beep(BO_EX); |
5735 | 5361 else if (!checkclearop(cap->oap)) |
7 | 5362 do_exmode(FALSE); |
5363 } | |
5364 | |
5365 /* | |
5366 * Handle a ":" command. | |
5367 */ | |
5368 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5369 nv_colon(cmdarg_T *cap) |
7 | 5370 { |
5371 int old_p_im; | |
4256 | 5372 int cmd_result; |
7 | 5373 |
5374 if (VIsual_active) | |
5375 nv_operator(cap); | |
5376 else | |
5377 { | |
5378 if (cap->oap->op_type != OP_NOP) | |
5379 { | |
5380 /* Using ":" as a movement is characterwise exclusive. */ | |
5381 cap->oap->motion_type = MCHAR; | |
5382 cap->oap->inclusive = FALSE; | |
5383 } | |
5384 else if (cap->count0) | |
5385 { | |
5386 /* translate "count:" into ":.,.+(count - 1)" */ | |
5387 stuffcharReadbuff('.'); | |
5388 if (cap->count0 > 1) | |
5389 { | |
5390 stuffReadbuff((char_u *)",.+"); | |
5391 stuffnumReadbuff((long)cap->count0 - 1L); | |
5392 } | |
5393 } | |
5394 | |
5395 /* When typing, don't type below an old message */ | |
5396 if (KeyTyped) | |
5397 compute_cmdrow(); | |
5398 | |
5399 old_p_im = p_im; | |
5400 | |
5401 /* get a command line and execute it */ | |
4256 | 5402 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5403 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5404 | |
5405 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5406 if (p_im != old_p_im) | |
5407 { | |
5408 if (p_im) | |
5409 restart_edit = 'i'; | |
5410 else | |
5411 restart_edit = 0; | |
5412 } | |
5413 | |
4256 | 5414 if (cmd_result == FAIL) |
5415 /* The Ex command failed, do not execute the operator. */ | |
5416 clearop(cap->oap); | |
5417 else if (cap->oap->op_type != OP_NOP | |
7 | 5418 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5419 || cap->oap->start.col > | |
4256 | 5420 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5421 || did_emsg | |
5422 )) | |
5423 /* The start of the operator has become invalid by the Ex command. | |
5424 */ | |
7 | 5425 clearopbeep(cap->oap); |
5426 } | |
5427 } | |
5428 | |
5429 /* | |
5430 * Handle CTRL-G command. | |
5431 */ | |
5432 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5433 nv_ctrlg(cmdarg_T *cap) |
7 | 5434 { |
5435 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5436 { | |
5437 VIsual_select = !VIsual_select; | |
5438 showmode(); | |
5439 } | |
5735 | 5440 else if (!checkclearop(cap->oap)) |
7 | 5441 /* print full name if count given or :cd used */ |
5442 fileinfo((int)cap->count0, FALSE, TRUE); | |
5443 } | |
5444 | |
5445 /* | |
5446 * Handle CTRL-H <Backspace> command. | |
5447 */ | |
5448 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5449 nv_ctrlh(cmdarg_T *cap) |
7 | 5450 { |
5451 if (VIsual_active && VIsual_select) | |
5452 { | |
5453 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5454 v_visop(cap); | |
5455 } | |
5456 else | |
5457 nv_left(cap); | |
5458 } | |
5459 | |
5460 /* | |
5461 * CTRL-L: clear screen and redraw. | |
5462 */ | |
5463 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5464 nv_clear(cmdarg_T *cap) |
7 | 5465 { |
5466 if (!checkclearop(cap->oap)) | |
5467 { | |
5468 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5469 /* | |
5470 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5471 * window resizing, so we cheat and make the user detect it | |
5472 * manually with CTRL-L instead | |
5473 */ | |
5474 ui_get_shellsize(); | |
5475 #endif | |
5476 #ifdef FEAT_SYN_HL | |
5477 /* 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
|
5478 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
|
5479 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5480 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5481 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5482 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5483 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
|
5484 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
|
5485 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5486 # endif |
7 | 5487 #endif |
5488 redraw_later(CLEAR); | |
5489 } | |
5490 } | |
5491 | |
5492 /* | |
5493 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5494 * Otherwise: Go to older pcmark. | |
5495 */ | |
5496 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5497 nv_ctrlo(cmdarg_T *cap) |
7 | 5498 { |
5499 if (VIsual_active && VIsual_select) | |
5500 { | |
5501 VIsual_select = FALSE; | |
5502 showmode(); | |
5503 restart_VIsual_select = 2; /* restart Select mode later */ | |
5504 } | |
5505 else | |
5506 { | |
5507 cap->count1 = -cap->count1; | |
5508 nv_pcmark(cap); | |
5509 } | |
5510 } | |
5511 | |
5512 /* | |
5513 * CTRL-^ command, short for ":e #" | |
5514 */ | |
5515 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5516 nv_hat(cmdarg_T *cap) |
7 | 5517 { |
5518 if (!checkclearopq(cap->oap)) | |
5519 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5520 GETF_SETMARK|GETF_ALT, FALSE); | |
5521 } | |
5522 | |
5523 /* | |
5524 * "Z" commands. | |
5525 */ | |
5526 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5527 nv_Zet(cmdarg_T *cap) |
7 | 5528 { |
5529 if (!checkclearopq(cap->oap)) | |
5530 { | |
5531 switch (cap->nchar) | |
5532 { | |
5533 /* "ZZ": equivalent to ":x". */ | |
5534 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5535 break; | |
5536 | |
5537 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5538 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5539 break; | |
5540 | |
5541 default: clearopbeep(cap->oap); | |
5542 } | |
5543 } | |
5544 } | |
5545 | |
5546 /* | |
5547 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5548 */ | |
5549 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5550 do_nv_ident(int c1, int c2) |
7 | 5551 { |
5552 oparg_T oa; | |
5553 cmdarg_T ca; | |
5554 | |
5555 clear_oparg(&oa); | |
5556 vim_memset(&ca, 0, sizeof(ca)); | |
5557 ca.oap = &oa; | |
5558 ca.cmdchar = c1; | |
5559 ca.nchar = c2; | |
5560 nv_ident(&ca); | |
5561 } | |
5562 | |
5563 /* | |
5564 * Handle the commands that use the word under the cursor. | |
5565 * [g] CTRL-] :ta to current identifier | |
5566 * [g] 'K' run program for current identifier | |
5567 * [g] '*' / to current identifier or string | |
5568 * [g] '#' ? to current identifier or string | |
5569 * g ']' :tselect for current identifier | |
5570 */ | |
5571 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5572 nv_ident(cmdarg_T *cap) |
7 | 5573 { |
5574 char_u *ptr = NULL; | |
5575 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5576 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5577 char_u *newbuf; |
7 | 5578 char_u *p; |
5579 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
|
5580 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5581 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5582 int n = 0; /* init for GCC */ |
5583 int cmdchar; | |
5584 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5585 int tag_cmd = FALSE; |
7 | 5586 char_u *aux_ptr; |
5587 int isman; | |
5588 int isman_s; | |
5589 | |
5590 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5591 { | |
5592 cmdchar = cap->nchar; | |
5593 g_cmd = TRUE; | |
5594 } | |
5595 else | |
5596 { | |
5597 cmdchar = cap->cmdchar; | |
5598 g_cmd = FALSE; | |
5599 } | |
5600 | |
5601 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5602 cmdchar = '#'; | |
5603 | |
5604 /* | |
5605 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5606 */ | |
5607 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5608 { | |
5609 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5610 return; | |
5611 if (checkclearopq(cap->oap)) | |
5612 return; | |
5613 } | |
5614 | |
5615 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5616 (cmdchar == '*' || cmdchar == '#') | |
5617 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5618 { | |
5619 clearop(cap->oap); | |
5620 return; | |
5621 } | |
5622 | |
5623 /* Allocate buffer to put the command in. Inserting backslashes can | |
5624 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5625 * and some numbers. */ | |
5626 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5627 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5628 || 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
|
5629 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
|
5630 { |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5631 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
|
5632 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
|
5633 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5634 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5635 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
|
5636 buf = alloc(buflen); |
7 | 5637 if (buf == NULL) |
5638 return; | |
5639 buf[0] = NUL; | |
5640 | |
5641 switch (cmdchar) | |
5642 { | |
5643 case '*': | |
5644 case '#': | |
5645 /* | |
5646 * Put cursor at start of word, makes search skip the word | |
5647 * under the cursor. | |
5648 * Call setpcmark() first, so "*``" puts the cursor back where | |
5649 * it was. | |
5650 */ | |
5651 setpcmark(); | |
5652 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5653 | |
5654 if (!g_cmd && vim_iswordp(ptr)) | |
5655 STRCPY(buf, "\\<"); | |
5656 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5657 break; | |
5658 | |
5659 case 'K': | |
5660 if (kp_help) | |
5661 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5662 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5663 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5664 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5665 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
|
5666 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5667 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5668 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5669 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5670 } |
7 | 5671 else |
5672 { | |
1712 | 5673 /* An external command will probably use an argument starting |
5674 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5675 while (*ptr == '-' && n > 0) |
5676 { | |
1712 | 5677 ++ptr; |
1728 | 5678 --n; |
5679 } | |
5680 if (n == 0) | |
5681 { | |
5682 EMSG(_(e_noident)); /* found dashes only */ | |
5683 vim_free(buf); | |
5684 return; | |
5685 } | |
1712 | 5686 |
7 | 5687 /* When a count is given, turn it into a range. Is this |
5688 * really what we want? */ | |
5689 isman = (STRCMP(kp, "man") == 0); | |
5690 isman_s = (STRCMP(kp, "man -s") == 0); | |
5691 if (cap->count0 != 0 && !(isman || isman_s)) | |
5692 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5693 | |
5694 STRCAT(buf, "! "); | |
5695 if (cap->count0 == 0 && isman_s) | |
5696 STRCAT(buf, "man"); | |
5697 else | |
5698 STRCAT(buf, kp); | |
5699 STRCAT(buf, " "); | |
5700 if (cap->count0 != 0 && (isman || isman_s)) | |
5701 { | |
5702 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5703 STRCAT(buf, " "); | |
5704 } | |
5705 } | |
5706 break; | |
5707 | |
5708 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5709 tag_cmd = TRUE; |
7 | 5710 #ifdef FEAT_CSCOPE |
5711 if (p_cst) | |
5712 STRCPY(buf, "cstag "); | |
5713 else | |
5714 #endif | |
5715 STRCPY(buf, "ts "); | |
5716 break; | |
5717 | |
5718 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5719 tag_cmd = TRUE; |
7 | 5720 if (curbuf->b_help) |
5721 STRCPY(buf, "he! "); | |
5722 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5723 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5724 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5725 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5726 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5727 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5728 } |
7 | 5729 } |
5730 | |
5731 /* | |
5732 * Now grab the chars in the identifier | |
5733 */ | |
1712 | 5734 if (cmdchar == 'K' && !kp_help) |
5735 { | |
1728 | 5736 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5737 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5738 /* 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
|
5739 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5740 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5741 /* 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
|
5742 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5743 vim_free(ptr); |
1712 | 5744 if (p == NULL) |
5745 { | |
5746 vim_free(buf); | |
5747 return; | |
5748 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5749 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
|
5750 if (newbuf == NULL) |
1712 | 5751 { |
5752 vim_free(buf); | |
5753 vim_free(p); | |
5754 return; | |
5755 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5756 buf = newbuf; |
1712 | 5757 STRCAT(buf, p); |
5758 vim_free(p); | |
5759 } | |
7 | 5760 else |
1712 | 5761 { |
5762 if (cmdchar == '*') | |
5763 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5764 else if (cmdchar == '#') | |
5765 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5766 else if (tag_cmd) |
2603 | 5767 { |
5768 if (curbuf->b_help) | |
5769 /* ":help" handles unescaped argument */ | |
5770 aux_ptr = (char_u *)""; | |
5771 else | |
5772 aux_ptr = (char_u *)"\\|\"\n["; | |
5773 } | |
1712 | 5774 else |
5775 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5776 | |
5777 p = buf + STRLEN(buf); | |
5778 while (n-- > 0) | |
5779 { | |
5780 /* put a backslash before \ and some others */ | |
5781 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5782 *p++ = '\\'; | |
7 | 5783 #ifdef FEAT_MBYTE |
1712 | 5784 /* When current byte is a part of multibyte character, copy all |
5785 * bytes of that character. */ | |
5786 if (has_mbyte) | |
5787 { | |
5788 int i; | |
5789 int len = (*mb_ptr2len)(ptr) - 1; | |
5790 | |
5791 for (i = 0; i < len && n >= 1; ++i, --n) | |
5792 *p++ = *ptr++; | |
5793 } | |
5794 #endif | |
5795 *p++ = *ptr++; | |
5796 } | |
5797 *p = NUL; | |
5798 } | |
7 | 5799 |
5800 /* | |
5801 * Execute the command. | |
5802 */ | |
5803 if (cmdchar == '*' || cmdchar == '#') | |
5804 { | |
5805 if (!g_cmd && ( | |
5806 #ifdef FEAT_MBYTE | |
5807 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5808 #endif | |
5809 vim_iswordc(ptr[-1]))) | |
5810 STRCAT(buf, "\\>"); | |
5811 #ifdef FEAT_CMDHIST | |
5812 /* put pattern in search history */ | |
2024 | 5813 init_history(); |
7 | 5814 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5815 #endif | |
6620 | 5816 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5817 } |
5818 else | |
5819 do_cmdline_cmd(buf); | |
5820 | |
5821 vim_free(buf); | |
5822 } | |
5823 | |
5824 /* | |
5825 * Get visually selected text, within one line only. | |
5826 * Returns FAIL if more than one line selected. | |
5827 */ | |
344 | 5828 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5829 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5830 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5831 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
|
5832 int *lenp) /* return: length of selected text */ |
7 | 5833 { |
5834 if (VIsual_mode != 'V') | |
5835 unadjust_for_sel(); | |
5836 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5837 { | |
344 | 5838 if (cap != NULL) |
5839 clearopbeep(cap->oap); | |
7 | 5840 return FAIL; |
5841 } | |
5842 if (VIsual_mode == 'V') | |
5843 { | |
5844 *pp = ml_get_curline(); | |
5845 *lenp = (int)STRLEN(*pp); | |
5846 } | |
5847 else | |
5848 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5849 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5850 { |
5851 *pp = ml_get_pos(&curwin->w_cursor); | |
5852 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5853 } | |
5854 else | |
5855 { | |
5856 *pp = ml_get_pos(&VIsual); | |
5857 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5858 } | |
5859 #ifdef FEAT_MBYTE | |
5860 if (has_mbyte) | |
5861 /* Correct the length to include the whole last character. */ | |
474 | 5862 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5863 #endif |
5864 } | |
5865 reset_VIsual_and_resel(); | |
5866 return OK; | |
5867 } | |
5868 | |
5869 /* | |
5870 * CTRL-T: backwards in tag stack | |
5871 */ | |
5872 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5873 nv_tagpop(cmdarg_T *cap) |
7 | 5874 { |
5875 if (!checkclearopq(cap->oap)) | |
5876 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5877 } | |
5878 | |
5879 /* | |
5880 * Handle scrolling command 'H', 'L' and 'M'. | |
5881 */ | |
5882 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5883 nv_scroll(cmdarg_T *cap) |
7 | 5884 { |
5885 int used = 0; | |
5886 long n; | |
5887 #ifdef FEAT_FOLDING | |
5888 linenr_T lnum; | |
5889 #endif | |
5890 int half; | |
5891 | |
5892 cap->oap->motion_type = MLINE; | |
5893 setpcmark(); | |
5894 | |
5895 if (cap->cmdchar == 'L') | |
5896 { | |
5897 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5898 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5899 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5900 curwin->w_cursor.lnum = 1; | |
5901 else | |
9 | 5902 { |
5903 #ifdef FEAT_FOLDING | |
5904 if (hasAnyFolding(curwin)) | |
5905 { | |
5906 /* Count a fold for one screen line. */ | |
5907 for (n = cap->count1 - 1; n > 0 | |
5908 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5909 { | |
5910 (void)hasFolding(curwin->w_cursor.lnum, | |
5911 &curwin->w_cursor.lnum, NULL); | |
5912 --curwin->w_cursor.lnum; | |
5913 } | |
5914 } | |
5915 else | |
5916 #endif | |
5917 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5918 } | |
7 | 5919 } |
5920 else | |
5921 { | |
5922 if (cap->cmdchar == 'M') | |
5923 { | |
5924 #ifdef FEAT_DIFF | |
5925 /* Don't count filler lines above the window. */ | |
5926 used -= diff_check_fill(curwin, curwin->w_topline) | |
5927 - curwin->w_topfill; | |
5928 #endif | |
5929 validate_botline(); /* make sure w_empty_rows is valid */ | |
5930 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5931 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5932 { | |
5933 #ifdef FEAT_DIFF | |
5934 /* Count half he number of filler lines to be "below this | |
5935 * line" and half to be "above the next line". */ | |
5936 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5937 + n) / 2 >= half) | |
5938 { | |
5939 --n; | |
5940 break; | |
5941 } | |
5942 #endif | |
5943 used += plines(curwin->w_topline + n); | |
5944 if (used >= half) | |
5945 break; | |
5946 #ifdef FEAT_FOLDING | |
5947 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5948 n = lnum - curwin->w_topline; | |
5949 #endif | |
5950 } | |
5951 if (n > 0 && used > curwin->w_height) | |
5952 --n; | |
5953 } | |
9 | 5954 else /* (cap->cmdchar == 'H') */ |
5955 { | |
7 | 5956 n = cap->count1 - 1; |
9 | 5957 #ifdef FEAT_FOLDING |
5958 if (hasAnyFolding(curwin)) | |
5959 { | |
5960 /* Count a fold for one screen line. */ | |
5961 lnum = curwin->w_topline; | |
5962 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5963 { | |
7009 | 5964 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5965 ++lnum; |
5966 } | |
5967 n = lnum - curwin->w_topline; | |
5968 } | |
5969 #endif | |
5970 } | |
7 | 5971 curwin->w_cursor.lnum = curwin->w_topline + n; |
5972 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5973 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5974 } | |
5975 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5976 /* 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
|
5977 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
|
5978 cursor_correct(); |
7 | 5979 beginline(BL_SOL | BL_FIX); |
5980 } | |
5981 | |
5982 /* | |
5983 * Cursor right commands. | |
5984 */ | |
5985 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5986 nv_right(cmdarg_T *cap) |
7 | 5987 { |
5988 long n; | |
5735 | 5989 int past_line; |
7 | 5990 |
180 | 5991 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5992 { | |
5993 /* <C-Right> and <S-Right> move a word or WORD right */ | |
5994 if (mod_mask & MOD_MASK_CTRL) | |
5995 cap->arg = TRUE; | |
5996 nv_wordcmd(cap); | |
5997 return; | |
5998 } | |
5999 | |
7 | 6000 cap->oap->motion_type = MCHAR; |
6001 cap->oap->inclusive = FALSE; | |
5735 | 6002 past_line = (VIsual_active && *p_sel != 'o'); |
6003 | |
6004 #ifdef FEAT_VIRTUALEDIT | |
7 | 6005 /* |
5735 | 6006 * In virtual edit mode, there's no such thing as "past_line", as lines |
6007 * are (theoretically) infinitely long. | |
7 | 6008 */ |
6009 if (virtual_active()) | |
5735 | 6010 past_line = 0; |
7 | 6011 #endif |
6012 | |
6013 for (n = cap->count1; n > 0; --n) | |
6014 { | |
5735 | 6015 if ((!past_line && oneright() == FAIL) |
6016 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6017 ) |
7 | 6018 { |
6019 /* | |
714 | 6020 * <Space> wraps to next line if 'whichwrap' has 's'. |
6021 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6022 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6023 */ |
6024 if ( ((cap->cmdchar == ' ' | |
6025 && vim_strchr(p_ww, 's') != NULL) | |
6026 || (cap->cmdchar == 'l' | |
6027 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6028 || (cap->cmdchar == K_RIGHT |
7 | 6029 && vim_strchr(p_ww, '>') != NULL)) |
6030 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6031 { | |
6032 /* When deleting we also count the NL as a character. | |
6033 * Set cap->oap->inclusive when last char in the line is | |
6034 * included, move to next line after that */ | |
714 | 6035 if ( cap->oap->op_type != OP_NOP |
7 | 6036 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6037 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6038 cap->oap->inclusive = TRUE; |
6039 else | |
6040 { | |
6041 ++curwin->w_cursor.lnum; | |
6042 curwin->w_cursor.col = 0; | |
6043 #ifdef FEAT_VIRTUALEDIT | |
6044 curwin->w_cursor.coladd = 0; | |
6045 #endif | |
6046 curwin->w_set_curswant = TRUE; | |
6047 cap->oap->inclusive = FALSE; | |
6048 } | |
6049 continue; | |
6050 } | |
6051 if (cap->oap->op_type == OP_NOP) | |
6052 { | |
6053 /* Only beep and flush if not moved at all */ | |
6054 if (n == cap->count1) | |
6055 beep_flush(); | |
6056 } | |
6057 else | |
6058 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6059 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6060 cap->oap->inclusive = TRUE; |
6061 } | |
6062 break; | |
6063 } | |
5735 | 6064 else if (past_line) |
7 | 6065 { |
6066 curwin->w_set_curswant = TRUE; | |
5735 | 6067 #ifdef FEAT_VIRTUALEDIT |
7 | 6068 if (virtual_active()) |
6069 oneright(); | |
6070 else | |
5735 | 6071 #endif |
6072 { | |
6073 #ifdef FEAT_MBYTE | |
7 | 6074 if (has_mbyte) |
6075 curwin->w_cursor.col += | |
474 | 6076 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6077 else |
5735 | 6078 #endif |
7 | 6079 ++curwin->w_cursor.col; |
6080 } | |
6081 } | |
6082 } | |
6083 #ifdef FEAT_FOLDING | |
6084 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6085 && cap->oap->op_type == OP_NOP) | |
6086 foldOpenCursor(); | |
6087 #endif | |
6088 } | |
6089 | |
6090 /* | |
6091 * Cursor left commands. | |
6092 * | |
6093 * Returns TRUE when operator end should not be adjusted. | |
6094 */ | |
6095 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6096 nv_left(cmdarg_T *cap) |
7 | 6097 { |
6098 long n; | |
6099 | |
180 | 6100 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6101 { | |
6102 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6103 if (mod_mask & MOD_MASK_CTRL) | |
6104 cap->arg = 1; | |
6105 nv_bck_word(cap); | |
6106 return; | |
6107 } | |
6108 | |
7 | 6109 cap->oap->motion_type = MCHAR; |
6110 cap->oap->inclusive = FALSE; | |
6111 for (n = cap->count1; n > 0; --n) | |
6112 { | |
6113 if (oneleft() == FAIL) | |
6114 { | |
6115 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6116 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6117 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6118 */ | |
6119 if ( (((cap->cmdchar == K_BS | |
6120 || cap->cmdchar == Ctrl_H) | |
6121 && vim_strchr(p_ww, 'b') != NULL) | |
6122 || (cap->cmdchar == 'h' | |
6123 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6124 || (cap->cmdchar == K_LEFT |
7 | 6125 && vim_strchr(p_ww, '<') != NULL)) |
6126 && curwin->w_cursor.lnum > 1) | |
6127 { | |
6128 --(curwin->w_cursor.lnum); | |
6129 coladvance((colnr_T)MAXCOL); | |
6130 curwin->w_set_curswant = TRUE; | |
6131 | |
6132 /* When the NL before the first char has to be deleted we | |
6133 * put the cursor on the NUL after the previous line. | |
6134 * This is a very special case, be careful! | |
1469 | 6135 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6136 if ( (cap->oap->op_type == OP_DELETE |
6137 || 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
|
6138 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6139 { |
5682 | 6140 char_u *cp = ml_get_cursor(); |
6141 | |
6142 if (*cp != NUL) | |
6143 { | |
6144 #ifdef FEAT_MBYTE | |
6145 if (has_mbyte) | |
6146 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6147 else | |
6148 #endif | |
6149 ++curwin->w_cursor.col; | |
6150 } | |
7 | 6151 cap->retval |= CA_NO_ADJ_OP_END; |
6152 } | |
6153 continue; | |
6154 } | |
6155 /* Only beep and flush if not moved at all */ | |
6156 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6157 beep_flush(); | |
6158 break; | |
6159 } | |
6160 } | |
6161 #ifdef FEAT_FOLDING | |
6162 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6163 && cap->oap->op_type == OP_NOP) | |
6164 foldOpenCursor(); | |
6165 #endif | |
6166 } | |
6167 | |
6168 /* | |
6169 * Cursor up commands. | |
6170 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6171 */ | |
6172 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6173 nv_up(cmdarg_T *cap) |
7 | 6174 { |
180 | 6175 if (mod_mask & MOD_MASK_SHIFT) |
6176 { | |
6177 /* <S-Up> is page up */ | |
6178 cap->arg = BACKWARD; | |
6179 nv_page(cap); | |
6180 } | |
6181 else | |
6182 { | |
6183 cap->oap->motion_type = MLINE; | |
6184 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6185 clearopbeep(cap->oap); | |
6186 else if (cap->arg) | |
6187 beginline(BL_WHITE | BL_FIX); | |
6188 } | |
7 | 6189 } |
6190 | |
6191 /* | |
6192 * Cursor down commands. | |
6193 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6194 */ | |
6195 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6196 nv_down(cmdarg_T *cap) |
7 | 6197 { |
180 | 6198 if (mod_mask & MOD_MASK_SHIFT) |
6199 { | |
6200 /* <S-Down> is page down */ | |
6201 cap->arg = FORWARD; | |
6202 nv_page(cap); | |
6203 } | |
6204 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
6205 #if defined(FEAT_QUICKFIX) |
7 | 6206 /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
170 | 6207 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
|
6208 { |
643 | 6209 if (curwin->w_llist_ref == NULL) |
6210 do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ | |
6211 else | |
6212 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
|
6213 } |
7 | 6214 else |
6215 #endif | |
6216 { | |
6217 #ifdef FEAT_CMDWIN | |
6218 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6219 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6220 cmdwin_result = CAR; |
6221 else | |
6222 #endif | |
6223 { | |
6224 cap->oap->motion_type = MLINE; | |
6225 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6226 clearopbeep(cap->oap); | |
6227 else if (cap->arg) | |
6228 beginline(BL_WHITE | BL_FIX); | |
6229 } | |
6230 } | |
6231 } | |
6232 | |
6233 #ifdef FEAT_SEARCHPATH | |
6234 /* | |
6235 * Grab the file name under the cursor and edit it. | |
6236 */ | |
6237 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6238 nv_gotofile(cmdarg_T *cap) |
7 | 6239 { |
6240 char_u *ptr; | |
681 | 6241 linenr_T lnum = -1; |
7 | 6242 |
633 | 6243 if (text_locked()) |
7 | 6244 { |
6245 clearopbeep(cap->oap); | |
633 | 6246 text_locked_msg(); |
7 | 6247 return; |
6248 } | |
819 | 6249 if (curbuf_locked()) |
6250 { | |
6251 clearop(cap->oap); | |
6252 return; | |
6253 } | |
7 | 6254 |
681 | 6255 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6256 |
6257 if (ptr != NULL) | |
6258 { | |
6259 /* 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
|
6260 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6261 (void)autowrite(curbuf, FALSE); |
7 | 6262 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
|
6263 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
|
6264 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
|
6265 && cap->nchar == 'F' && lnum >= 0) |
681 | 6266 { |
6267 curwin->w_cursor.lnum = lnum; | |
6268 check_cursor_lnum(); | |
6269 beginline(BL_SOL | BL_FIX); | |
6270 } | |
7 | 6271 vim_free(ptr); |
6272 } | |
6273 else | |
6274 clearop(cap->oap); | |
6275 } | |
6276 #endif | |
6277 | |
6278 /* | |
6279 * <End> command: to end of current line or last line. | |
6280 */ | |
6281 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6282 nv_end(cmdarg_T *cap) |
7 | 6283 { |
180 | 6284 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6285 { | |
6286 cap->arg = TRUE; | |
7 | 6287 nv_goto(cap); |
6288 cap->count1 = 1; /* to end of current line */ | |
6289 } | |
6290 nv_dollar(cap); | |
6291 } | |
6292 | |
6293 /* | |
6294 * Handle the "$" command. | |
6295 */ | |
6296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6297 nv_dollar(cmdarg_T *cap) |
7 | 6298 { |
6299 cap->oap->motion_type = MCHAR; | |
6300 cap->oap->inclusive = TRUE; | |
6301 #ifdef FEAT_VIRTUALEDIT | |
6302 /* In virtual mode when off the edge of a line and an operator | |
6303 * is pending (whew!) keep the cursor where it is. | |
6304 * Otherwise, send it to the end of the line. */ | |
6305 if (!virtual_active() || gchar_cursor() != NUL | |
6306 || cap->oap->op_type == OP_NOP) | |
6307 #endif | |
6308 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6309 if (cursor_down((long)(cap->count1 - 1), | |
6310 cap->oap->op_type == OP_NOP) == FAIL) | |
6311 clearopbeep(cap->oap); | |
6312 #ifdef FEAT_FOLDING | |
6313 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6314 foldOpenCursor(); | |
6315 #endif | |
6316 } | |
6317 | |
6318 /* | |
6319 * Implementation of '?' and '/' commands. | |
6320 * If cap->arg is TRUE don't set PC mark. | |
6321 */ | |
6322 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6323 nv_search(cmdarg_T *cap) |
7 | 6324 { |
6325 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6326 pos_T save_cursor = curwin->w_cursor; |
7 | 6327 |
6328 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6329 { | |
6330 /* Translate "g??" to "g?g?" */ | |
6331 cap->cmdchar = 'g'; | |
6332 cap->nchar = '?'; | |
6333 nv_operator(cap); | |
6334 return; | |
6335 } | |
6336 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6337 /* 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
|
6338 * start position. */ |
7 | 6339 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6340 | |
6341 if (cap->searchbuf == NULL) | |
6342 { | |
6343 clearop(oap); | |
6344 return; | |
6345 } | |
6346 | |
6620 | 6347 (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
|
6348 (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
|
6349 ? 0 : SEARCH_MARK); |
7 | 6350 } |
6351 | |
6352 /* | |
6353 * Handle "N" and "n" commands. | |
6354 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6355 */ | |
6356 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6357 nv_next(cmdarg_T *cap) |
7 | 6358 { |
6620 | 6359 pos_T old = curwin->w_cursor; |
6360 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6361 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6362 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6363 { |
6364 /* Avoid getting stuck on the current cursor position, which can | |
6365 * happen when an offset is given and the cursor is on the last char | |
6366 * in the buffer: Repeat with count + 1. */ | |
6367 cap->count1 += 1; | |
6368 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6369 cap->count1 -= 1; | |
6370 } | |
7 | 6371 } |
6372 | |
6373 /* | |
6374 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6375 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6376 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6377 */ | |
6378 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6379 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6380 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6381 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6382 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6383 int opt) /* extra flags for do_search() */ |
7 | 6384 { |
6385 int i; | |
6386 | |
6387 cap->oap->motion_type = MCHAR; | |
6388 cap->oap->inclusive = FALSE; | |
6389 cap->oap->use_reg_one = TRUE; | |
6390 curwin->w_set_curswant = TRUE; | |
6391 | |
6392 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
|
6393 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6394 if (i == 0) |
6395 clearop(cap->oap); | |
6396 else | |
6397 { | |
6398 if (i == 2) | |
6399 cap->oap->motion_type = MLINE; | |
6400 #ifdef FEAT_VIRTUALEDIT | |
6401 curwin->w_cursor.coladd = 0; | |
6402 #endif | |
6403 #ifdef FEAT_FOLDING | |
6404 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6405 foldOpenCursor(); | |
6406 #endif | |
6407 } | |
6408 | |
6409 /* "/$" will put the cursor after the end of the line, may need to | |
6410 * correct that here */ | |
6411 check_cursor(); | |
6620 | 6412 return i; |
7 | 6413 } |
6414 | |
6415 /* | |
6416 * Character search commands. | |
6417 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6418 * ',' and FALSE for ';'. | |
6419 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6420 */ | |
6421 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6422 nv_csearch(cmdarg_T *cap) |
7 | 6423 { |
6424 int t_cmd; | |
6425 | |
6426 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6427 t_cmd = TRUE; | |
6428 else | |
6429 t_cmd = FALSE; | |
6430 | |
6431 cap->oap->motion_type = MCHAR; | |
6432 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6433 clearopbeep(cap->oap); | |
6434 else | |
6435 { | |
6436 curwin->w_set_curswant = TRUE; | |
6437 #ifdef FEAT_VIRTUALEDIT | |
6438 /* Include a Tab for "tx" and for "dfx". */ | |
6439 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6440 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6441 { | |
6442 colnr_T scol, ecol; | |
6443 | |
6444 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6445 curwin->w_cursor.coladd = ecol - scol; | |
6446 } | |
6447 else | |
6448 curwin->w_cursor.coladd = 0; | |
6449 #endif | |
6450 adjust_for_sel(cap); | |
6451 #ifdef FEAT_FOLDING | |
6452 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6453 foldOpenCursor(); | |
6454 #endif | |
6455 } | |
6456 } | |
6457 | |
6458 /* | |
6459 * "[" and "]" commands. | |
6460 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6461 */ | |
6462 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6463 nv_brackets(cmdarg_T *cap) |
7 | 6464 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6465 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6466 pos_T prev_pos; |
6467 pos_T *pos = NULL; /* init for GCC */ | |
6468 pos_T old_pos; /* cursor position before command */ | |
6469 int flag; | |
6470 long n; | |
6471 int findc; | |
6472 int c; | |
6473 | |
6474 cap->oap->motion_type = MCHAR; | |
6475 cap->oap->inclusive = FALSE; | |
6476 old_pos = curwin->w_cursor; | |
6477 #ifdef FEAT_VIRTUALEDIT | |
6478 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6479 #endif | |
6480 | |
6481 #ifdef FEAT_SEARCHPATH | |
6482 /* | |
6483 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6484 */ | |
6485 if (cap->nchar == 'f') | |
6486 nv_gotofile(cap); | |
6487 else | |
6488 #endif | |
6489 | |
6490 #ifdef FEAT_FIND_ID | |
6491 /* | |
1188 | 6492 * Find the occurrence(s) of the identifier or define under cursor |
6493 * in current and included files or jump to the first occurrence. | |
7 | 6494 * |
6495 * search list jump | |
6496 * fwd bwd fwd bwd fwd bwd | |
6497 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6498 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6499 */ | |
6500 if (vim_strchr((char_u *) | |
6501 #ifdef EBCDIC | |
6502 "iI\005dD\067", | |
6503 #else | |
6504 "iI\011dD\004", | |
6505 #endif | |
6506 cap->nchar) != NULL) | |
6507 { | |
6508 char_u *ptr; | |
6509 int len; | |
6510 | |
6511 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6512 clearop(cap->oap); | |
6513 else | |
6514 { | |
6515 find_pattern_in_path(ptr, 0, len, TRUE, | |
6516 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6517 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6518 cap->count1, | |
6519 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6520 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6521 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6522 (linenr_T)MAXLNUM); | |
6523 curwin->w_set_curswant = TRUE; | |
6524 } | |
6525 } | |
6526 else | |
6527 #endif | |
6528 | |
6529 /* | |
6530 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6531 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6532 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6533 * "[m" or "]m" search for prev/next start of (Java) method. | |
6534 * "[M" or "]M" search for prev/next end of (Java) method. | |
6535 */ | |
6536 if ( (cap->cmdchar == '[' | |
6537 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6538 || (cap->cmdchar == ']' | |
6539 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6540 { | |
6541 if (cap->nchar == '*') | |
6542 cap->nchar = '/'; | |
6543 prev_pos.lnum = 0; | |
6544 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6545 { | |
6546 if (cap->cmdchar == '[') | |
6547 findc = '{'; | |
6548 else | |
6549 findc = '}'; | |
6550 n = 9999; | |
6551 } | |
6552 else | |
6553 { | |
6554 findc = cap->nchar; | |
6555 n = cap->count1; | |
6556 } | |
6557 for ( ; n > 0; --n) | |
6558 { | |
6559 if ((pos = findmatchlimit(cap->oap, findc, | |
6560 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6561 { | |
6562 if (new_pos.lnum == 0) /* nothing found */ | |
6563 { | |
6564 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6565 clearopbeep(cap->oap); | |
6566 } | |
6567 else | |
6568 pos = &new_pos; /* use last one found */ | |
6569 break; | |
6570 } | |
6571 prev_pos = new_pos; | |
6572 curwin->w_cursor = *pos; | |
6573 new_pos = *pos; | |
6574 } | |
6575 curwin->w_cursor = old_pos; | |
6576 | |
6577 /* | |
6578 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6579 * brought us to the match for "[m" and "]M" when inside a method. | |
6580 * Try finding the '{' or '}' we want to be at. | |
6581 * Also repeat for the given count. | |
6582 */ | |
6583 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6584 { | |
6585 /* norm is TRUE for "]M" and "[m" */ | |
6586 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6587 | |
6588 n = cap->count1; | |
6589 /* found a match: we were inside a method */ | |
6590 if (prev_pos.lnum != 0) | |
6591 { | |
6592 pos = &prev_pos; | |
6593 curwin->w_cursor = prev_pos; | |
6594 if (norm) | |
6595 --n; | |
6596 } | |
6597 else | |
6598 pos = NULL; | |
6599 while (n > 0) | |
6600 { | |
6601 for (;;) | |
6602 { | |
6603 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6604 { | |
6605 /* if not found anything, that's an error */ | |
6606 if (pos == NULL) | |
6607 clearopbeep(cap->oap); | |
6608 n = 0; | |
6609 break; | |
6610 } | |
6611 c = gchar_cursor(); | |
6612 if (c == '{' || c == '}') | |
6613 { | |
6614 /* Must have found end/start of class: use it. | |
6615 * Or found the place to be at. */ | |
6616 if ((c == findc && norm) || (n == 1 && !norm)) | |
6617 { | |
6618 new_pos = curwin->w_cursor; | |
6619 pos = &new_pos; | |
6620 n = 0; | |
6621 } | |
6622 /* if no match found at all, we started outside of the | |
6623 * class and we're inside now. Just go on. */ | |
6624 else if (new_pos.lnum == 0) | |
6625 { | |
6626 new_pos = curwin->w_cursor; | |
6627 pos = &new_pos; | |
6628 } | |
6629 /* found start/end of other method: go to match */ | |
6630 else if ((pos = findmatchlimit(cap->oap, findc, | |
6631 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6632 0)) == NULL) | |
6633 n = 0; | |
6634 else | |
6635 curwin->w_cursor = *pos; | |
6636 break; | |
6637 } | |
6638 } | |
6639 --n; | |
6640 } | |
6641 curwin->w_cursor = old_pos; | |
6642 if (pos == NULL && new_pos.lnum != 0) | |
6643 clearopbeep(cap->oap); | |
6644 } | |
6645 if (pos != NULL) | |
6646 { | |
6647 setpcmark(); | |
6648 curwin->w_cursor = *pos; | |
6649 curwin->w_set_curswant = TRUE; | |
6650 #ifdef FEAT_FOLDING | |
6651 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6652 && cap->oap->op_type == OP_NOP) | |
6653 foldOpenCursor(); | |
6654 #endif | |
6655 } | |
6656 } | |
6657 | |
6658 /* | |
6659 * "[[", "[]", "]]" and "][": move to start or end of function | |
6660 */ | |
6661 else if (cap->nchar == '[' || cap->nchar == ']') | |
6662 { | |
6663 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6664 flag = '{'; | |
6665 else | |
6666 flag = '}'; /* "][" or "[]" */ | |
6667 | |
6668 curwin->w_set_curswant = TRUE; | |
6669 /* | |
6670 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6671 * we also stop at '}'. | |
6672 */ | |
503 | 6673 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6674 (cap->oap->op_type != OP_NOP |
6675 && cap->arg == FORWARD && flag == '{'))) | |
6676 clearopbeep(cap->oap); | |
6677 else | |
6678 { | |
6679 if (cap->oap->op_type == OP_NOP) | |
6680 beginline(BL_WHITE | BL_FIX); | |
6681 #ifdef FEAT_FOLDING | |
6682 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6683 foldOpenCursor(); | |
6684 #endif | |
6685 } | |
6686 } | |
6687 | |
6688 /* | |
6689 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6690 */ | |
6691 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6692 { | |
1312 | 6693 if (!checkclearop(cap->oap)) |
7 | 6694 { |
5708 | 6695 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6696 ? FORWARD : BACKWARD; | |
6697 int regname = cap->oap->regname; | |
6698 int was_visual = VIsual_active; | |
6699 int line_count = curbuf->b_ml.ml_line_count; | |
6700 pos_T start, end; | |
6701 | |
6702 if (VIsual_active) | |
6703 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6704 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6705 ? 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
|
6706 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6707 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6708 } | |
6709 # ifdef FEAT_CLIPBOARD | |
6710 adjust_clip_reg(®name); | |
6711 # endif | |
7 | 6712 prep_redo_cmd(cap); |
5708 | 6713 |
6714 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6715 if (was_visual) | |
6716 { | |
6717 VIsual = start; | |
6718 curwin->w_cursor = end; | |
6719 if (dir == BACKWARD) | |
6720 { | |
6721 /* adjust lines */ | |
6722 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6723 curwin->w_cursor.lnum += | |
6724 curbuf->b_ml.ml_line_count - line_count; | |
6725 } | |
6726 | |
6727 VIsual_active = TRUE; | |
6728 if (VIsual_mode == 'V') | |
6729 { | |
6730 /* delete visually selected lines */ | |
6731 cap->cmdchar = 'd'; | |
6732 cap->nchar = NUL; | |
6733 cap->oap->regname = regname; | |
6734 nv_operator(cap); | |
6735 do_pending_operator(cap, 0, FALSE); | |
6736 } | |
6737 if (VIsual_active) | |
6738 { | |
6739 end_visual_mode(); | |
6740 redraw_later(SOME_VALID); | |
6741 } | |
6742 } | |
7 | 6743 } |
6744 } | |
6745 | |
6746 /* | |
6747 * "['", "[`", "]'" and "]`": jump to next mark | |
6748 */ | |
6749 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6750 { | |
6751 pos = &curwin->w_cursor; | |
6752 for (n = cap->count1; n > 0; --n) | |
6753 { | |
6754 prev_pos = *pos; | |
6755 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6756 cap->nchar == '\''); | |
6757 if (pos == NULL) | |
6758 break; | |
6759 } | |
6760 if (pos == NULL) | |
6761 pos = &prev_pos; | |
6762 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6763 } | |
6764 | |
6765 #ifdef FEAT_MOUSE | |
6766 /* | |
6767 * [ or ] followed by a middle mouse click: put selected text with | |
6768 * indent adjustment. Any other button just does as usual. | |
6769 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6770 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6771 { |
6772 (void)do_mouse(cap->oap, cap->nchar, | |
6773 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6774 cap->count1, PUT_FIXINDENT); | |
6775 } | |
6776 #endif /* FEAT_MOUSE */ | |
6777 | |
6778 #ifdef FEAT_FOLDING | |
6779 /* | |
6780 * "[z" and "]z": move to start or end of open fold. | |
6781 */ | |
6782 else if (cap->nchar == 'z') | |
6783 { | |
6784 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6785 cap->count1) == FAIL) | |
6786 clearopbeep(cap->oap); | |
6787 } | |
6788 #endif | |
6789 | |
6790 #ifdef FEAT_DIFF | |
6791 /* | |
6792 * "[c" and "]c": move to next or previous diff-change. | |
6793 */ | |
6794 else if (cap->nchar == 'c') | |
6795 { | |
6796 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6797 cap->count1) == FAIL) | |
6798 clearopbeep(cap->oap); | |
6799 } | |
6800 #endif | |
6801 | |
737 | 6802 #ifdef FEAT_SPELL |
236 | 6803 /* |
6804 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6805 */ | |
6806 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6807 { | |
249 | 6808 setpcmark(); |
6809 for (n = 0; n < cap->count1; ++n) | |
498 | 6810 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6811 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6812 { |
6813 clearopbeep(cap->oap); | |
6814 break; | |
6815 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6816 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6817 curwin->w_set_curswant = TRUE; |
819 | 6818 # ifdef FEAT_FOLDING |
6819 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6820 foldOpenCursor(); | |
6821 # endif | |
236 | 6822 } |
6823 #endif | |
6824 | |
7 | 6825 /* Not a valid cap->nchar. */ |
6826 else | |
6827 clearopbeep(cap->oap); | |
6828 } | |
6829 | |
6830 /* | |
6831 * Handle Normal mode "%" command. | |
6832 */ | |
6833 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6834 nv_percent(cmdarg_T *cap) |
7 | 6835 { |
6836 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
|
6837 #if defined(FEAT_FOLDING) |
7 | 6838 linenr_T lnum = curwin->w_cursor.lnum; |
6839 #endif | |
6840 | |
6841 cap->oap->inclusive = TRUE; | |
6842 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6843 { | |
6844 if (cap->count0 > 100) | |
6845 clearopbeep(cap->oap); | |
6846 else | |
6847 { | |
6848 cap->oap->motion_type = MLINE; | |
6849 setpcmark(); | |
6850 /* Round up, so CTRL-G will give same value. Watch out for a | |
6851 * large line count, the line number must not go negative! */ | |
6852 if (curbuf->b_ml.ml_line_count > 1000000) | |
6853 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6854 / 100L * cap->count0; | |
6855 else | |
6856 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6857 cap->count0 + 99L) / 100L; | |
6858 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6859 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6860 beginline(BL_SOL | BL_FIX); | |
6861 } | |
6862 } | |
6863 else /* "%" : go to matching paren */ | |
6864 { | |
6865 cap->oap->motion_type = MCHAR; | |
6866 cap->oap->use_reg_one = TRUE; | |
6867 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6868 clearopbeep(cap->oap); | |
6869 else | |
6870 { | |
6871 setpcmark(); | |
6872 curwin->w_cursor = *pos; | |
6873 curwin->w_set_curswant = TRUE; | |
6874 #ifdef FEAT_VIRTUALEDIT | |
6875 curwin->w_cursor.coladd = 0; | |
6876 #endif | |
6877 adjust_for_sel(cap); | |
6878 } | |
6879 } | |
6880 #ifdef FEAT_FOLDING | |
6881 if (cap->oap->op_type == OP_NOP | |
6882 && lnum != curwin->w_cursor.lnum | |
6883 && (fdo_flags & FDO_PERCENT) | |
6884 && KeyTyped) | |
6885 foldOpenCursor(); | |
6886 #endif | |
6887 } | |
6888 | |
6889 /* | |
6890 * Handle "(" and ")" commands. | |
6891 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6892 */ | |
6893 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6894 nv_brace(cmdarg_T *cap) |
7 | 6895 { |
6896 cap->oap->motion_type = MCHAR; | |
6897 cap->oap->use_reg_one = TRUE; | |
620 | 6898 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6899 cap->oap->inclusive = FALSE; | |
7 | 6900 curwin->w_set_curswant = TRUE; |
6901 | |
6902 if (findsent(cap->arg, cap->count1) == FAIL) | |
6903 clearopbeep(cap->oap); | |
6904 else | |
6905 { | |
1505 | 6906 /* Don't leave the cursor on the NUL past end of line. */ |
6907 adjust_cursor(cap->oap); | |
7 | 6908 #ifdef FEAT_VIRTUALEDIT |
6909 curwin->w_cursor.coladd = 0; | |
6910 #endif | |
6911 #ifdef FEAT_FOLDING | |
6912 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6913 foldOpenCursor(); | |
6914 #endif | |
6915 } | |
6916 } | |
6917 | |
6918 /* | |
6919 * "m" command: Mark a position. | |
6920 */ | |
6921 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6922 nv_mark(cmdarg_T *cap) |
7 | 6923 { |
6924 if (!checkclearop(cap->oap)) | |
6925 { | |
6926 if (setmark(cap->nchar) == FAIL) | |
6927 clearopbeep(cap->oap); | |
6928 } | |
6929 } | |
6930 | |
6931 /* | |
6932 * "{" and "}" commands. | |
6933 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6934 */ | |
6935 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6936 nv_findpar(cmdarg_T *cap) |
7 | 6937 { |
6938 cap->oap->motion_type = MCHAR; | |
6939 cap->oap->inclusive = FALSE; | |
6940 cap->oap->use_reg_one = TRUE; | |
6941 curwin->w_set_curswant = TRUE; | |
503 | 6942 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6943 clearopbeep(cap->oap); |
6944 else | |
6945 { | |
6946 #ifdef FEAT_VIRTUALEDIT | |
6947 curwin->w_cursor.coladd = 0; | |
6948 #endif | |
6949 #ifdef FEAT_FOLDING | |
6950 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6951 foldOpenCursor(); | |
6952 #endif | |
6953 } | |
6954 } | |
6955 | |
6956 /* | |
6957 * "u" command: Undo or make lower case. | |
6958 */ | |
6959 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6960 nv_undo(cmdarg_T *cap) |
7 | 6961 { |
5735 | 6962 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6963 { |
6964 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6965 cap->cmdchar = 'g'; | |
6966 cap->nchar = 'u'; | |
6967 nv_operator(cap); | |
6968 } | |
6969 else | |
6970 nv_kundo(cap); | |
6971 } | |
6972 | |
6973 /* | |
6974 * <Undo> command. | |
6975 */ | |
6976 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6977 nv_kundo(cmdarg_T *cap) |
7 | 6978 { |
6979 if (!checkclearopq(cap->oap)) | |
6980 { | |
6981 u_undo((int)cap->count1); | |
6982 curwin->w_set_curswant = TRUE; | |
6983 } | |
6984 } | |
6985 | |
6986 /* | |
6987 * Handle the "r" command. | |
6988 */ | |
6989 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6990 nv_replace(cmdarg_T *cap) |
7 | 6991 { |
6992 char_u *ptr; | |
6993 int had_ctrl_v; | |
6994 long n; | |
6995 | |
6996 if (checkclearop(cap->oap)) | |
6997 return; | |
6998 | |
6999 /* get another character */ | |
7000 if (cap->nchar == Ctrl_V) | |
7001 { | |
7002 had_ctrl_v = Ctrl_V; | |
7003 cap->nchar = get_literal(); | |
7004 /* Don't redo a multibyte character with CTRL-V. */ | |
7005 if (cap->nchar > DEL) | |
7006 had_ctrl_v = NUL; | |
7007 } | |
7008 else | |
7009 had_ctrl_v = NUL; | |
7010 | |
1343 | 7011 /* Abort if the character is a special key. */ |
7012 if (IS_SPECIAL(cap->nchar)) | |
7013 { | |
7014 clearopbeep(cap->oap); | |
7015 return; | |
7016 } | |
7017 | |
7 | 7018 /* Visual mode "r" */ |
7019 if (VIsual_active) | |
7020 { | |
1797 | 7021 if (got_int) |
7022 reset_VIsual(); | |
5428 | 7023 if (had_ctrl_v) |
7024 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7025 /* 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
|
7026 * 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
|
7027 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7028 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
|
7029 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
|
7030 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 7031 } |
7 | 7032 nv_operator(cap); |
7033 return; | |
7034 } | |
7035 | |
7036 #ifdef FEAT_VIRTUALEDIT | |
7037 /* Break tabs, etc. */ | |
7038 if (virtual_active()) | |
7039 { | |
7040 if (u_save_cursor() == FAIL) | |
7041 return; | |
7042 if (gchar_cursor() == NUL) | |
7043 { | |
7044 /* Add extra space and put the cursor on the first one. */ | |
7045 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7046 curwin->w_cursor.col -= cap->count1; | |
7047 } | |
7048 else if (gchar_cursor() == TAB) | |
7049 coladvance_force(getviscol()); | |
7050 } | |
7051 #endif | |
7052 | |
1343 | 7053 /* Abort if not enough characters to replace. */ |
7 | 7054 ptr = ml_get_cursor(); |
1343 | 7055 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7056 #ifdef FEAT_MBYTE |
7057 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7058 #endif | |
7059 ) | |
7060 { | |
7061 clearopbeep(cap->oap); | |
7062 return; | |
7063 } | |
7064 | |
7065 /* | |
7066 * Replacing with a TAB is done by edit() when it is complicated because | |
7067 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7068 * Other characters are done below to avoid problems with things like | |
7069 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7070 */ | |
7071 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7072 { | |
7073 stuffnumReadbuff(cap->count1); | |
7074 stuffcharReadbuff('R'); | |
7075 stuffcharReadbuff('\t'); | |
7076 stuffcharReadbuff(ESC); | |
7077 return; | |
7078 } | |
7079 | |
7080 /* save line for undo */ | |
7081 if (u_save_cursor() == FAIL) | |
7082 return; | |
7083 | |
7084 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7085 { | |
7086 /* | |
7087 * Replace character(s) by a single newline. | |
7088 * Strange vi behaviour: Only one newline is inserted. | |
7089 * Delete the characters here. | |
7090 * Insert the newline with an insert command, takes care of | |
7091 * autoindent. The insert command depends on being on the last | |
7092 * character of a line or not. | |
7093 */ | |
7094 #ifdef FEAT_MBYTE | |
7095 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7096 #else | |
608 | 7097 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7098 #endif |
7099 stuffcharReadbuff('\r'); | |
7100 stuffcharReadbuff(ESC); | |
7101 | |
7102 /* Give 'r' to edit(), to get the redo command right. */ | |
7103 invoke_edit(cap, TRUE, 'r', FALSE); | |
7104 } | |
7105 else | |
7106 { | |
7107 prep_redo(cap->oap->regname, cap->count1, | |
7108 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7109 | |
7110 curbuf->b_op_start = curwin->w_cursor; | |
7111 #ifdef FEAT_MBYTE | |
7112 if (has_mbyte) | |
7113 { | |
7114 int old_State = State; | |
7115 | |
7116 if (cap->ncharC1 != 0) | |
7117 AppendCharToRedobuff(cap->ncharC1); | |
7118 if (cap->ncharC2 != 0) | |
7119 AppendCharToRedobuff(cap->ncharC2); | |
7120 | |
7121 /* This is slow, but it handles replacing a single-byte with a | |
7122 * multi-byte and the other way around. Also handles adding | |
7123 * composing characters for utf-8. */ | |
7124 for (n = cap->count1; n > 0; --n) | |
7125 { | |
7126 State = REPLACE; | |
3501 | 7127 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7128 { | |
7129 int c = ins_copychar(curwin->w_cursor.lnum | |
7130 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7131 if (c != NUL) | |
7132 ins_char(c); | |
7133 else | |
7134 /* will be decremented further down */ | |
7135 ++curwin->w_cursor.col; | |
7136 } | |
7137 else | |
7138 ins_char(cap->nchar); | |
7 | 7139 State = old_State; |
7140 if (cap->ncharC1 != 0) | |
7141 ins_char(cap->ncharC1); | |
7142 if (cap->ncharC2 != 0) | |
7143 ins_char(cap->ncharC2); | |
7144 } | |
7145 } | |
7146 else | |
7147 #endif | |
7148 { | |
7149 /* | |
7150 * Replace the characters within one line. | |
7151 */ | |
7152 for (n = cap->count1; n > 0; --n) | |
7153 { | |
7154 /* | |
7155 * Get ptr again, because u_save and/or showmatch() will have | |
7156 * released the line. At the same time we let know that the | |
7157 * line will be changed. | |
7158 */ | |
7159 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7160 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7161 { | |
7162 int c = ins_copychar(curwin->w_cursor.lnum | |
7163 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7164 if (c != NUL) | |
7165 ptr[curwin->w_cursor.col] = c; | |
7166 } | |
7167 else | |
7168 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7169 if (p_sm && msg_silent == 0) |
7170 showmatch(cap->nchar); | |
7171 ++curwin->w_cursor.col; | |
7172 } | |
7173 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7174 if (netbeans_active()) |
7 | 7175 { |
2210 | 7176 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7177 |
33 | 7178 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7179 (long)cap->count1); |
7 | 7180 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7181 &ptr[start], (int)cap->count1); |
7 | 7182 } |
7183 #endif | |
7184 | |
7185 /* mark the buffer as changed and prepare for displaying */ | |
7186 changed_bytes(curwin->w_cursor.lnum, | |
7187 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7188 } | |
7189 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7190 #ifdef FEAT_MBYTE | |
7191 /* if the character on the left of the current cursor is a multi-byte | |
7192 * character, move two characters left */ | |
7193 if (has_mbyte) | |
7194 mb_adjust_cursor(); | |
7195 #endif | |
7196 curbuf->b_op_end = curwin->w_cursor; | |
7197 curwin->w_set_curswant = TRUE; | |
7198 set_last_insert(cap->nchar); | |
7199 } | |
7200 } | |
7201 | |
7202 /* | |
7203 * 'o': Exchange start and end of Visual area. | |
7204 * 'O': same, but in block mode exchange left and right corners. | |
7205 */ | |
7206 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7207 v_swap_corners(int cmdchar) |
7 | 7208 { |
7209 pos_T old_cursor; | |
7210 colnr_T left, right; | |
7211 | |
7212 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7213 { | |
7214 old_cursor = curwin->w_cursor; | |
7215 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7216 curwin->w_cursor.lnum = VIsual.lnum; | |
7217 coladvance(left); | |
7218 VIsual = curwin->w_cursor; | |
7219 | |
7220 curwin->w_cursor.lnum = old_cursor.lnum; | |
7221 curwin->w_curswant = right; | |
7222 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7223 * right one column */ | |
7224 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7225 ++curwin->w_curswant; | |
7226 coladvance(curwin->w_curswant); | |
7227 if (curwin->w_cursor.col == old_cursor.col | |
7228 #ifdef FEAT_VIRTUALEDIT | |
7229 && (!virtual_active() | |
7230 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7231 #endif | |
7232 ) | |
7233 { | |
7234 curwin->w_cursor.lnum = VIsual.lnum; | |
7235 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7236 ++right; | |
7237 coladvance(right); | |
7238 VIsual = curwin->w_cursor; | |
7239 | |
7240 curwin->w_cursor.lnum = old_cursor.lnum; | |
7241 coladvance(left); | |
7242 curwin->w_curswant = left; | |
7243 } | |
7244 } | |
7245 else | |
7246 { | |
7247 old_cursor = curwin->w_cursor; | |
7248 curwin->w_cursor = VIsual; | |
7249 VIsual = old_cursor; | |
7250 curwin->w_set_curswant = TRUE; | |
7251 } | |
7252 } | |
7253 | |
7254 /* | |
7255 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7256 */ | |
7257 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7258 nv_Replace(cmdarg_T *cap) |
7 | 7259 { |
7260 if (VIsual_active) /* "R" is replace lines */ | |
7261 { | |
7262 cap->cmdchar = 'c'; | |
7263 cap->nchar = NUL; | |
4213 | 7264 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7265 VIsual_mode = 'V'; |
7266 nv_operator(cap); | |
7267 } | |
5735 | 7268 else if (!checkclearopq(cap->oap)) |
7 | 7269 { |
7270 if (!curbuf->b_p_ma) | |
7271 EMSG(_(e_modifiable)); | |
7272 else | |
7273 { | |
7274 #ifdef FEAT_VIRTUALEDIT | |
7275 if (virtual_active()) | |
7276 coladvance(getviscol()); | |
7277 #endif | |
7278 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7279 } | |
7280 } | |
7281 } | |
7282 | |
7283 #ifdef FEAT_VREPLACE | |
7284 /* | |
7285 * "gr". | |
7286 */ | |
7287 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7288 nv_vreplace(cmdarg_T *cap) |
7 | 7289 { |
7290 if (VIsual_active) | |
7291 { | |
7292 cap->cmdchar = 'r'; | |
7293 cap->nchar = cap->extra_char; | |
7294 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7295 } | |
5735 | 7296 else if (!checkclearopq(cap->oap)) |
7 | 7297 { |
7298 if (!curbuf->b_p_ma) | |
7299 EMSG(_(e_modifiable)); | |
7300 else | |
7301 { | |
7302 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7303 cap->extra_char = get_literal(); | |
7304 stuffcharReadbuff(cap->extra_char); | |
7305 stuffcharReadbuff(ESC); | |
7306 # ifdef FEAT_VIRTUALEDIT | |
7307 if (virtual_active()) | |
7308 coladvance(getviscol()); | |
7309 # endif | |
7310 invoke_edit(cap, TRUE, 'v', FALSE); | |
7311 } | |
7312 } | |
7313 } | |
7314 #endif | |
7315 | |
7316 /* | |
7317 * Swap case for "~" command, when it does not work like an operator. | |
7318 */ | |
7319 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7320 n_swapchar(cmdarg_T *cap) |
7 | 7321 { |
7322 long n; | |
7323 pos_T startpos; | |
7324 int did_change = 0; | |
7325 #ifdef FEAT_NETBEANS_INTG | |
7326 pos_T pos; | |
7327 char_u *ptr; | |
7328 int count; | |
7329 #endif | |
7330 | |
7331 if (checkclearopq(cap->oap)) | |
7332 return; | |
7333 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7334 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7335 { |
7336 clearopbeep(cap->oap); | |
7337 return; | |
7338 } | |
7339 | |
7340 prep_redo_cmd(cap); | |
7341 | |
7342 if (u_save_cursor() == FAIL) | |
7343 return; | |
7344 | |
7345 startpos = curwin->w_cursor; | |
7346 #ifdef FEAT_NETBEANS_INTG | |
7347 pos = startpos; | |
7348 #endif | |
7349 for (n = cap->count1; n > 0; --n) | |
7350 { | |
7351 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7352 inc_cursor(); | |
7353 if (gchar_cursor() == NUL) | |
7354 { | |
7355 if (vim_strchr(p_ww, '~') != NULL | |
7356 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7357 { | |
7358 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7359 if (netbeans_active()) |
7 | 7360 { |
7361 if (did_change) | |
7362 { | |
7363 ptr = ml_get(pos.lnum); | |
835 | 7364 count = (int)STRLEN(ptr) - pos.col; |
33 | 7365 netbeans_removed(curbuf, pos.lnum, pos.col, |
7366 (long)count); | |
7 | 7367 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7368 &ptr[pos.col], count); |
7 | 7369 } |
7370 pos.col = 0; | |
7371 pos.lnum++; | |
7372 } | |
7373 #endif | |
7374 ++curwin->w_cursor.lnum; | |
7375 curwin->w_cursor.col = 0; | |
7376 if (n > 1) | |
7377 { | |
7378 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7379 break; | |
7380 u_clearline(); | |
7381 } | |
7382 } | |
7383 else | |
7384 break; | |
7385 } | |
7386 } | |
7387 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7388 if (did_change && netbeans_active()) |
7 | 7389 { |
7390 ptr = ml_get(pos.lnum); | |
7391 count = curwin->w_cursor.col - pos.col; | |
33 | 7392 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7393 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7394 } |
7395 #endif | |
7396 | |
7397 | |
7398 check_cursor(); | |
7399 curwin->w_set_curswant = TRUE; | |
7400 if (did_change) | |
7401 { | |
7402 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7403 0L); | |
7404 curbuf->b_op_start = startpos; | |
7405 curbuf->b_op_end = curwin->w_cursor; | |
7406 if (curbuf->b_op_end.col > 0) | |
7407 --curbuf->b_op_end.col; | |
7408 } | |
7409 } | |
7410 | |
7411 /* | |
7412 * Move cursor to mark. | |
7413 */ | |
7414 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7415 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7416 { |
7417 if (check_mark(pos) == FAIL) | |
7418 clearop(cap->oap); | |
7419 else | |
7420 { | |
7421 if (cap->cmdchar == '\'' | |
7422 || cap->cmdchar == '`' | |
7423 || cap->cmdchar == '[' | |
7424 || cap->cmdchar == ']') | |
7425 setpcmark(); | |
7426 curwin->w_cursor = *pos; | |
7427 if (flag) | |
7428 beginline(BL_WHITE | BL_FIX); | |
7429 else | |
7430 check_cursor(); | |
7431 } | |
7432 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7433 if (cap->cmdchar == '`') | |
7434 cap->oap->use_reg_one = TRUE; | |
7435 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7436 curwin->w_set_curswant = TRUE; | |
7437 } | |
7438 | |
7439 /* | |
7440 * Handle commands that are operators in Visual mode. | |
7441 */ | |
7442 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7443 v_visop(cmdarg_T *cap) |
7 | 7444 { |
7445 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7446 | |
7447 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7448 * the end of the line, and "C" replaces till EOL */ |
7 | 7449 if (isupper(cap->cmdchar)) |
7450 { | |
7451 if (VIsual_mode != Ctrl_V) | |
4213 | 7452 { |
7453 VIsual_mode_orig = VIsual_mode; | |
7 | 7454 VIsual_mode = 'V'; |
4213 | 7455 } |
7 | 7456 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7457 curwin->w_curswant = MAXCOL; | |
7458 } | |
7459 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7460 nv_operator(cap); | |
7461 } | |
7462 | |
7463 /* | |
7464 * "s" and "S" commands. | |
7465 */ | |
7466 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7467 nv_subst(cmdarg_T *cap) |
7 | 7468 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7469 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7470 /* 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
|
7471 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
|
7472 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7473 #endif |
7 | 7474 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7475 { | |
7476 if (cap->cmdchar == 'S') | |
4213 | 7477 { |
7478 VIsual_mode_orig = VIsual_mode; | |
7 | 7479 VIsual_mode = 'V'; |
4213 | 7480 } |
7 | 7481 cap->cmdchar = 'c'; |
7482 nv_operator(cap); | |
7483 } | |
7484 else | |
7485 nv_optrans(cap); | |
7486 } | |
7487 | |
7488 /* | |
7489 * Abbreviated commands. | |
7490 */ | |
7491 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7492 nv_abbrev(cmdarg_T *cap) |
7 | 7493 { |
7494 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7495 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7496 | |
7497 /* in Visual mode these commands are operators */ | |
7498 if (VIsual_active) | |
7499 v_visop(cap); | |
7500 else | |
7501 nv_optrans(cap); | |
7502 } | |
7503 | |
7504 /* | |
7505 * Translate a command into another command. | |
7506 */ | |
7507 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7508 nv_optrans(cmdarg_T *cap) |
7 | 7509 { |
7510 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7511 (char_u *)"d$", (char_u *)"c$", | |
7512 (char_u *)"cl", (char_u *)"cc", | |
7513 (char_u *)"yy", (char_u *)":s\r"}; | |
7514 static char_u *str = (char_u *)"xXDCsSY&"; | |
7515 | |
7516 if (!checkclearopq(cap->oap)) | |
7517 { | |
164 | 7518 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7519 * either, because "2." should also not use the count. */ | |
7520 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7521 { | |
7522 cap->oap->start = curwin->w_cursor; | |
7523 cap->oap->op_type = OP_DELETE; | |
1490 | 7524 #ifdef FEAT_EVAL |
7525 set_op_var(OP_DELETE); | |
7526 #endif | |
164 | 7527 cap->count1 = 1; |
7528 nv_dollar(cap); | |
7529 finish_op = TRUE; | |
7530 ResetRedobuff(); | |
7531 AppendCharToRedobuff('D'); | |
7532 } | |
7533 else | |
7534 { | |
7535 if (cap->count0) | |
7536 stuffnumReadbuff(cap->count0); | |
7537 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7538 } | |
7 | 7539 } |
7540 cap->opcount = 0; | |
7541 } | |
7542 | |
7543 /* | |
7544 * "'" and "`" commands. Also for "g'" and "g`". | |
7545 * cap->arg is TRUE for "'" and "g'". | |
7546 */ | |
7547 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7548 nv_gomark(cmdarg_T *cap) |
7 | 7549 { |
7550 pos_T *pos; | |
7551 int c; | |
7552 #ifdef FEAT_FOLDING | |
4017 | 7553 pos_T old_cursor = curwin->w_cursor; |
7 | 7554 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7555 #endif | |
7556 | |
7557 if (cap->cmdchar == 'g') | |
7558 c = cap->extra_char; | |
7559 else | |
7560 c = cap->nchar; | |
7561 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7562 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7563 { | |
7564 if (cap->arg) | |
7565 { | |
7566 check_cursor_lnum(); | |
7567 beginline(BL_WHITE | BL_FIX); | |
7568 } | |
7569 else | |
7570 check_cursor(); | |
7571 } | |
7572 else | |
7573 nv_cursormark(cap, cap->arg, pos); | |
7574 | |
7575 #ifdef FEAT_VIRTUALEDIT | |
7576 /* May need to clear the coladd that a mark includes. */ | |
7577 if (!virtual_active()) | |
7578 curwin->w_cursor.coladd = 0; | |
7579 #endif | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7580 check_cursor_col(); |
7 | 7581 #ifdef FEAT_FOLDING |
7582 if (cap->oap->op_type == OP_NOP | |
4057 | 7583 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7584 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7585 && (fdo_flags & FDO_MARK) |
7586 && old_KeyTyped) | |
7587 foldOpenCursor(); | |
7588 #endif | |
7589 } | |
7590 | |
7591 /* | |
7592 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7593 */ | |
7594 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7595 nv_pcmark(cmdarg_T *cap) |
7 | 7596 { |
7597 #ifdef FEAT_JUMPLIST | |
7598 pos_T *pos; | |
7599 # ifdef FEAT_FOLDING | |
7600 linenr_T lnum = curwin->w_cursor.lnum; | |
7601 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7602 # endif | |
7603 | |
7604 if (!checkclearopq(cap->oap)) | |
7605 { | |
7606 if (cap->cmdchar == 'g') | |
7607 pos = movechangelist((int)cap->count1); | |
7608 else | |
7609 pos = movemark((int)cap->count1); | |
7610 if (pos == (pos_T *)-1) /* jump to other file */ | |
7611 { | |
7612 curwin->w_set_curswant = TRUE; | |
7613 check_cursor(); | |
7614 } | |
7615 else if (pos != NULL) /* can jump */ | |
7616 nv_cursormark(cap, FALSE, pos); | |
7617 else if (cap->cmdchar == 'g') | |
7618 { | |
7619 if (curbuf->b_changelistlen == 0) | |
7620 EMSG(_("E664: changelist is empty")); | |
7621 else if (cap->count1 < 0) | |
7622 EMSG(_("E662: At start of changelist")); | |
7623 else | |
7624 EMSG(_("E663: At end of changelist")); | |
7625 } | |
7626 else | |
7627 clearopbeep(cap->oap); | |
7628 # ifdef FEAT_FOLDING | |
7629 if (cap->oap->op_type == OP_NOP | |
7630 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7631 && (fdo_flags & FDO_MARK) | |
7632 && old_KeyTyped) | |
7633 foldOpenCursor(); | |
7634 # endif | |
7635 } | |
7636 #else | |
7637 clearopbeep(cap->oap); | |
7638 #endif | |
7639 } | |
7640 | |
7641 /* | |
7642 * Handle '"' command. | |
7643 */ | |
7644 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7645 nv_regname(cmdarg_T *cap) |
7 | 7646 { |
7647 if (checkclearop(cap->oap)) | |
7648 return; | |
7649 #ifdef FEAT_EVAL | |
7650 if (cap->nchar == '=') | |
7651 cap->nchar = get_expr_register(); | |
7652 #endif | |
7653 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7654 { | |
7655 cap->oap->regname = cap->nchar; | |
7656 cap->opcount = cap->count0; /* remember count before '"' */ | |
7657 #ifdef FEAT_EVAL | |
7658 set_reg_var(cap->oap->regname); | |
7659 #endif | |
7660 } | |
7661 else | |
7662 clearopbeep(cap->oap); | |
7663 } | |
7664 | |
7665 /* | |
7666 * Handle "v", "V" and "CTRL-V" commands. | |
7667 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7668 * is TRUE. | |
167 | 7669 * Handle CTRL-Q just like CTRL-V. |
7 | 7670 */ |
7671 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7672 nv_visual(cmdarg_T *cap) |
7 | 7673 { |
167 | 7674 if (cap->cmdchar == Ctrl_Q) |
7675 cap->cmdchar = Ctrl_V; | |
7676 | |
7 | 7677 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7678 * characterwise, linewise, or blockwise. */ | |
7679 if (cap->oap->op_type != OP_NOP) | |
7680 { | |
7681 cap->oap->motion_force = cap->cmdchar; | |
7682 finish_op = FALSE; /* operator doesn't finish now but later */ | |
7683 return; | |
7684 } | |
7685 | |
7686 VIsual_select = cap->arg; | |
7687 if (VIsual_active) /* change Visual mode */ | |
7688 { | |
7689 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7690 end_visual_mode(); | |
7691 else /* toggle char/block mode */ | |
7692 { /* or char/line mode */ | |
7693 VIsual_mode = cap->cmdchar; | |
7694 showmode(); | |
7695 } | |
7696 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7697 } | |
7698 else /* start Visual mode */ | |
7699 { | |
7700 check_visual_highlight(); | |
3537 | 7701 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7702 { | |
7703 /* use previously selected part */ | |
7 | 7704 VIsual = curwin->w_cursor; |
7705 | |
7706 VIsual_active = TRUE; | |
7707 VIsual_reselect = TRUE; | |
7708 if (!cap->arg) | |
7709 /* start Select mode when 'selectmode' contains "cmd" */ | |
7710 may_start_select('c'); | |
7711 #ifdef FEAT_MOUSE | |
7712 setmouse(); | |
7713 #endif | |
641 | 7714 if (p_smd && msg_silent == 0) |
7 | 7715 redraw_cmdline = TRUE; /* show visual mode later */ |
7716 /* | |
7717 * For V and ^V, we multiply the number of lines even if there | |
7718 * was only one -- webb | |
7719 */ | |
7720 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7721 { | |
7722 curwin->w_cursor.lnum += | |
7723 resel_VIsual_line_count * cap->count0 - 1; | |
7724 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7725 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7726 } | |
7727 VIsual_mode = resel_VIsual_mode; | |
7728 if (VIsual_mode == 'v') | |
7729 { | |
7730 if (resel_VIsual_line_count <= 1) | |
3125 | 7731 { |
7732 validate_virtcol(); | |
7733 curwin->w_curswant = curwin->w_virtcol | |
7734 + resel_VIsual_vcol * cap->count0 - 1; | |
7735 } | |
7 | 7736 else |
3125 | 7737 curwin->w_curswant = resel_VIsual_vcol; |
7738 coladvance(curwin->w_curswant); | |
7 | 7739 } |
3125 | 7740 if (resel_VIsual_vcol == MAXCOL) |
7 | 7741 { |
7742 curwin->w_curswant = MAXCOL; | |
7743 coladvance((colnr_T)MAXCOL); | |
7744 } | |
7745 else if (VIsual_mode == Ctrl_V) | |
7746 { | |
7747 validate_virtcol(); | |
7748 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7749 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7750 coladvance(curwin->w_curswant); |
7751 } | |
7752 else | |
7753 curwin->w_set_curswant = TRUE; | |
7754 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7755 } | |
7756 else | |
7757 { | |
7758 if (!cap->arg) | |
7759 /* start Select mode when 'selectmode' contains "cmd" */ | |
7760 may_start_select('c'); | |
7761 n_start_visual_mode(cap->cmdchar); | |
3537 | 7762 if (VIsual_mode != 'V' && *p_sel == 'e') |
7763 ++cap->count1; /* include one more char */ | |
7764 if (cap->count0 > 0 && --cap->count1 > 0) | |
7765 { | |
7766 /* With a count select that many characters or lines. */ | |
7767 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7768 nv_right(cap); | |
7769 else if (VIsual_mode == 'V') | |
7770 nv_down(cap); | |
7771 } | |
7 | 7772 } |
7773 } | |
7774 } | |
7775 | |
7776 /* | |
7777 * Start selection for Shift-movement keys. | |
7778 */ | |
7779 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7780 start_selection(void) |
7 | 7781 { |
7782 /* if 'selectmode' contains "key", start Select mode */ | |
7783 may_start_select('k'); | |
7784 n_start_visual_mode('v'); | |
7785 } | |
7786 | |
7787 /* | |
7788 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7789 */ | |
7790 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7791 may_start_select(int c) |
7 | 7792 { |
7793 VIsual_select = (stuff_empty() && typebuf_typed() | |
7794 && (vim_strchr(p_slm, c) != NULL)); | |
7795 } | |
7796 | |
7797 /* | |
7798 * Start Visual mode "c". | |
7799 * Should set VIsual_select before calling this. | |
7800 */ | |
7801 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7802 n_start_visual_mode(int c) |
7 | 7803 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7804 #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
|
7805 /* 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
|
7806 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
|
7807 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7808 |
7 | 7809 VIsual_mode = c; |
7810 VIsual_active = TRUE; | |
7811 VIsual_reselect = TRUE; | |
7812 #ifdef FEAT_VIRTUALEDIT | |
7813 /* Corner case: the 0 position in a tab may change when going into | |
7814 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7815 */ | |
7816 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7817 { |
7818 validate_virtcol(); | |
7 | 7819 coladvance(curwin->w_virtcol); |
3742 | 7820 } |
7 | 7821 #endif |
7822 VIsual = curwin->w_cursor; | |
7823 | |
7824 #ifdef FEAT_FOLDING | |
7825 foldAdjustVisual(); | |
7826 #endif | |
7827 | |
7828 #ifdef FEAT_MOUSE | |
7829 setmouse(); | |
7830 #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
|
7831 #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
|
7832 /* 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
|
7833 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
|
7834 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7835 |
641 | 7836 if (p_smd && msg_silent == 0) |
7 | 7837 redraw_cmdline = TRUE; /* show visual mode later */ |
7838 #ifdef FEAT_CLIPBOARD | |
7839 /* Make sure the clipboard gets updated. Needed because start and | |
7840 * end may still be the same, and the selection needs to be owned */ | |
7841 clip_star.vmode = NUL; | |
7842 #endif | |
7843 | |
7844 /* Only need to redraw this line, unless still need to redraw an old | |
7845 * Visual area (when 'lazyredraw' is set). */ | |
7846 if (curwin->w_redr_type < INVERTED) | |
7847 { | |
7848 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7849 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7850 } | |
7851 } | |
7852 | |
7853 | |
7854 /* | |
7855 * CTRL-W: Window commands | |
7856 */ | |
7857 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7858 nv_window(cmdarg_T *cap) |
7 | 7859 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7860 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7861 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7862 /* "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
|
7863 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7864 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
|
7865 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7866 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7867 else if (!checkclearop(cap->oap)) |
7 | 7868 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7869 } | |
7870 | |
7871 /* | |
7872 * CTRL-Z: Suspend | |
7873 */ | |
7874 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7875 nv_suspend(cmdarg_T *cap) |
7 | 7876 { |
7877 clearop(cap->oap); | |
7878 if (VIsual_active) | |
7879 end_visual_mode(); /* stop Visual mode */ | |
7880 do_cmdline_cmd((char_u *)"st"); | |
7881 } | |
7882 | |
7883 /* | |
7884 * Commands starting with "g". | |
7885 */ | |
7886 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7887 nv_g_cmd(cmdarg_T *cap) |
7 | 7888 { |
7889 oparg_T *oap = cap->oap; | |
7890 pos_T tpos; | |
7891 int i; | |
7892 int flag = FALSE; | |
7893 | |
7894 switch (cap->nchar) | |
7895 { | |
6868 | 7896 case Ctrl_A: |
7897 case Ctrl_X: | |
7 | 7898 #ifdef MEM_PROFILE |
7899 /* | |
7900 * "g^A": dump log of used memory. | |
7901 */ | |
6868 | 7902 if (!VIsual_active && cap->nchar == Ctrl_A) |
7903 vim_mem_profile_dump(); | |
7904 else | |
7905 #endif | |
7906 /* | |
7907 * "g^A/g^X": sequentially increment visually selected region | |
7908 */ | |
7909 if (VIsual_active) | |
7910 { | |
7911 cap->arg = TRUE; | |
7912 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7913 cap->nchar = NUL; |
6868 | 7914 nv_addsub(cap); |
7915 } | |
7916 else | |
7917 clearopbeep(oap); | |
7 | 7918 break; |
7919 | |
7920 #ifdef FEAT_VREPLACE | |
7921 /* | |
7922 * "gR": Enter virtual replace mode. | |
7923 */ | |
7924 case 'R': | |
7925 cap->arg = TRUE; | |
7926 nv_Replace(cap); | |
7927 break; | |
7928 | |
7929 case 'r': | |
7930 nv_vreplace(cap); | |
7931 break; | |
7932 #endif | |
7933 | |
7934 case '&': | |
7935 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7936 break; | |
7937 | |
7938 /* | |
7939 * "gv": Reselect the previous Visual area. If Visual already active, | |
7940 * exchange previous and current Visual area. | |
7941 */ | |
7942 case 'v': | |
7943 if (checkclearop(oap)) | |
7944 break; | |
7945 | |
690 | 7946 if ( curbuf->b_visual.vi_start.lnum == 0 |
7947 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7948 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7949 beep_flush(); |
7950 else | |
7951 { | |
7952 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7953 if (VIsual_active) | |
7954 { | |
7955 i = VIsual_mode; | |
690 | 7956 VIsual_mode = curbuf->b_visual.vi_mode; |
7957 curbuf->b_visual.vi_mode = i; | |
7 | 7958 # ifdef FEAT_EVAL |
7959 curbuf->b_visual_mode_eval = i; | |
7960 # endif | |
7961 i = curwin->w_curswant; | |
690 | 7962 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7963 curbuf->b_visual.vi_curswant = i; | |
7964 | |
7965 tpos = curbuf->b_visual.vi_end; | |
7966 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7967 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7968 curbuf->b_visual.vi_start = VIsual; | |
7 | 7969 } |
7970 else | |
7971 { | |
690 | 7972 VIsual_mode = curbuf->b_visual.vi_mode; |
7973 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7974 tpos = curbuf->b_visual.vi_end; | |
7975 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7976 } |
7977 | |
7978 VIsual_active = TRUE; | |
7979 VIsual_reselect = TRUE; | |
7980 | |
7981 /* Set Visual to the start and w_cursor to the end of the Visual | |
7982 * area. Make sure they are on an existing character. */ | |
7983 check_cursor(); | |
7984 VIsual = curwin->w_cursor; | |
7985 curwin->w_cursor = tpos; | |
7986 check_cursor(); | |
7987 update_topline(); | |
7988 /* | |
7989 * When called from normal "g" command: start Select mode when | |
7990 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
7991 * start Select mode. | |
7992 */ | |
7993 if (cap->arg) | |
7994 VIsual_select = TRUE; | |
7995 else | |
7996 may_start_select('c'); | |
7997 #ifdef FEAT_MOUSE | |
7998 setmouse(); | |
7999 #endif | |
8000 #ifdef FEAT_CLIPBOARD | |
8001 /* Make sure the clipboard gets updated. Needed because start and | |
8002 * end are still the same, and the selection needs to be owned */ | |
8003 clip_star.vmode = NUL; | |
8004 #endif | |
8005 redraw_curbuf_later(INVERTED); | |
8006 showmode(); | |
8007 } | |
8008 break; | |
8009 /* | |
8010 * "gV": Don't reselect the previous Visual area after a Select mode | |
8011 * mapping of menu. | |
8012 */ | |
8013 case 'V': | |
8014 VIsual_reselect = FALSE; | |
8015 break; | |
8016 | |
8017 /* | |
8018 * "gh": start Select mode. | |
8019 * "gH": start Select line mode. | |
8020 * "g^H": start Select block mode. | |
8021 */ | |
8022 case K_BS: | |
8023 cap->nchar = Ctrl_H; | |
8024 /* FALLTHROUGH */ | |
8025 case 'h': | |
8026 case 'H': | |
8027 case Ctrl_H: | |
8028 # ifdef EBCDIC | |
8029 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8030 if (cap->nchar == Ctrl_H) | |
8031 cap->cmdchar = Ctrl_V; | |
8032 else | |
8033 # endif | |
8034 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8035 cap->arg = TRUE; | |
8036 nv_visual(cap); | |
8037 break; | |
3701 | 8038 |
8039 /* "gn", "gN" visually select next/previous search match | |
8040 * "gn" selects next match | |
8041 * "gN" selects previous match | |
8042 */ | |
8043 case 'N': | |
8044 case 'n': | |
8045 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8046 clearopbeep(oap); |
3701 | 8047 break; |
7 | 8048 |
8049 /* | |
8050 * "gj" and "gk" two new funny movement keys -- up and down | |
8051 * movement based on *screen* line rather than *file* line. | |
8052 */ | |
8053 case 'j': | |
8054 case K_DOWN: | |
8055 /* with 'nowrap' it works just like the normal "j" command; also when | |
8056 * in a closed fold */ | |
8057 if (!curwin->w_p_wrap | |
8058 #ifdef FEAT_FOLDING | |
8059 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8060 #endif | |
8061 ) | |
8062 { | |
8063 oap->motion_type = MLINE; | |
8064 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8065 } | |
8066 else | |
8067 i = nv_screengo(oap, FORWARD, cap->count1); | |
8068 if (i == FAIL) | |
8069 clearopbeep(oap); | |
8070 break; | |
8071 | |
8072 case 'k': | |
8073 case K_UP: | |
8074 /* with 'nowrap' it works just like the normal "k" command; also when | |
8075 * in a closed fold */ | |
8076 if (!curwin->w_p_wrap | |
8077 #ifdef FEAT_FOLDING | |
8078 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8079 #endif | |
8080 ) | |
8081 { | |
8082 oap->motion_type = MLINE; | |
8083 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8084 } | |
8085 else | |
8086 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8087 if (i == FAIL) | |
8088 clearopbeep(oap); | |
8089 break; | |
8090 | |
8091 /* | |
8092 * "gJ": join two lines without inserting a space. | |
8093 */ | |
8094 case 'J': | |
8095 nv_join(cap); | |
8096 break; | |
8097 | |
8098 /* | |
8099 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8100 * "gm": middle of "g0" and "g$". | |
8101 */ | |
8102 case '^': | |
8103 flag = TRUE; | |
8104 /* FALLTHROUGH */ | |
8105 | |
8106 case '0': | |
8107 case 'm': | |
8108 case K_HOME: | |
8109 case K_KHOME: | |
8110 oap->motion_type = MCHAR; | |
8111 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
|
8112 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8113 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8114 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8115 int width2 = width1 + curwin_col_off2(); |
8116 | |
8117 validate_virtcol(); | |
8118 i = 0; | |
8119 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8120 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8121 } | |
8122 else | |
8123 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8124 /* 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
|
8125 * '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
|
8126 * to the left. */ |
7 | 8127 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
|
8128 i += (curwin->w_width - curwin_col_off() |
7 | 8129 + ((curwin->w_p_wrap && i > 0) |
8130 ? curwin_col_off2() : 0)) / 2; | |
8131 coladvance((colnr_T)i); | |
8132 if (flag) | |
8133 { | |
8134 do | |
8135 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8136 while (VIM_ISWHITE(i) && oneright() == OK); |
7 | 8137 } |
8138 curwin->w_set_curswant = TRUE; | |
8139 break; | |
8140 | |
8141 case '_': | |
8142 /* "g_": to the last non-blank character in the line or <count> lines | |
8143 * downward. */ | |
8144 cap->oap->motion_type = MCHAR; | |
8145 cap->oap->inclusive = TRUE; | |
8146 curwin->w_curswant = MAXCOL; | |
8147 if (cursor_down((long)(cap->count1 - 1), | |
8148 cap->oap->op_type == OP_NOP) == FAIL) | |
8149 clearopbeep(cap->oap); | |
8150 else | |
8151 { | |
8152 char_u *ptr = ml_get_curline(); | |
8153 | |
8154 /* In Visual mode we may end up after the line. */ | |
8155 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8156 --curwin->w_cursor.col; | |
8157 | |
8158 /* Decrease the cursor column until it's on a non-blank. */ | |
8159 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
|
8160 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8161 --curwin->w_cursor.col; |
8162 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8163 adjust_for_sel(cap); |
7 | 8164 } |
8165 break; | |
8166 | |
8167 case '$': | |
8168 case K_END: | |
8169 case K_KEND: | |
8170 { | |
8171 int col_off = curwin_col_off(); | |
8172 | |
8173 oap->motion_type = MCHAR; | |
8174 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
|
8175 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8176 { |
8177 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8178 if (cap->count1 == 1) | |
8179 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8180 int width1 = curwin->w_width - col_off; |
7 | 8181 int width2 = width1 + curwin_col_off2(); |
8182 | |
8183 validate_virtcol(); | |
8184 i = width1 - 1; | |
8185 if (curwin->w_virtcol >= (colnr_T)width1) | |
8186 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8187 * width2; | |
8188 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8189 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8190 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8191 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8192 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8193 curwin->w_set_curswant = FALSE; |
7 | 8194 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8195 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8196 { | |
8197 /* | |
8198 * Check for landing on a character that got split at | |
8199 * the end of the line. We do not want to advance to | |
8200 * the next screen line. | |
8201 */ | |
8202 if (curwin->w_virtcol > (colnr_T)i) | |
8203 --curwin->w_cursor.col; | |
8204 } | |
8205 #endif | |
8206 } | |
8207 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8208 clearopbeep(oap); | |
8209 } | |
8210 else | |
8211 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8212 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8213 coladvance((colnr_T)i); |
40 | 8214 |
8215 /* Make sure we stick in this column. */ | |
8216 validate_virtcol(); | |
8217 curwin->w_curswant = curwin->w_virtcol; | |
8218 curwin->w_set_curswant = FALSE; | |
7 | 8219 } |
8220 } | |
8221 break; | |
8222 | |
8223 /* | |
8224 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8225 */ | |
8226 case '*': | |
8227 case '#': | |
8228 #if POUND != '#' | |
8229 case POUND: /* pound sign (sometimes equal to '#') */ | |
8230 #endif | |
8231 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8232 case ']': /* :tselect for current identifier */ | |
8233 nv_ident(cap); | |
8234 break; | |
8235 | |
8236 /* | |
8237 * ge and gE: go back to end of word | |
8238 */ | |
8239 case 'e': | |
8240 case 'E': | |
8241 oap->motion_type = MCHAR; | |
8242 curwin->w_set_curswant = TRUE; | |
8243 oap->inclusive = TRUE; | |
8244 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8245 clearopbeep(oap); | |
8246 break; | |
8247 | |
8248 /* | |
8249 * "g CTRL-G": display info about cursor position | |
8250 */ | |
8251 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8252 cursor_pos_info(NULL); |
7 | 8253 break; |
8254 | |
8255 /* | |
8256 * "gi": start Insert at the last position. | |
8257 */ | |
8258 case 'i': | |
8259 if (curbuf->b_last_insert.lnum != 0) | |
8260 { | |
8261 curwin->w_cursor = curbuf->b_last_insert; | |
8262 check_cursor_lnum(); | |
8263 i = (int)STRLEN(ml_get_curline()); | |
8264 if (curwin->w_cursor.col > (colnr_T)i) | |
8265 { | |
8266 #ifdef FEAT_VIRTUALEDIT | |
8267 if (virtual_active()) | |
8268 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8269 #endif | |
8270 curwin->w_cursor.col = i; | |
8271 } | |
8272 } | |
8273 cap->cmdchar = 'i'; | |
8274 nv_edit(cap); | |
8275 break; | |
8276 | |
8277 /* | |
8278 * "gI": Start insert in column 1. | |
8279 */ | |
8280 case 'I': | |
8281 beginline(0); | |
8282 if (!checkclearopq(oap)) | |
8283 invoke_edit(cap, FALSE, 'g', FALSE); | |
8284 break; | |
8285 | |
8286 #ifdef FEAT_SEARCHPATH | |
8287 /* | |
8288 * "gf": goto file, edit file under cursor | |
8289 * "]f" and "[f": can also be used. | |
8290 */ | |
8291 case 'f': | |
681 | 8292 case 'F': |
7 | 8293 nv_gotofile(cap); |
8294 break; | |
8295 #endif | |
8296 | |
8297 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8298 case '\'': | |
8299 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8300 /* FALLTHROUGH */ |
7 | 8301 case '`': |
8302 nv_gomark(cap); | |
8303 break; | |
8304 | |
8305 /* | |
8306 * "gs": Goto sleep. | |
8307 */ | |
8308 case 's': | |
8309 do_sleep(cap->count1 * 1000L); | |
8310 break; | |
8311 | |
8312 /* | |
8313 * "ga": Display the ascii value of the character under the | |
8314 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8315 */ | |
8316 case 'a': | |
8317 do_ascii(NULL); | |
8318 break; | |
8319 | |
8320 #ifdef FEAT_MBYTE | |
8321 /* | |
8322 * "g8": Display the bytes used for the UTF-8 character under the | |
8323 * cursor. It is displayed in hex. | |
775 | 8324 * "8g8" finds illegal byte sequence. |
7 | 8325 */ |
8326 case '8': | |
775 | 8327 if (cap->count0 == 8) |
8328 utf_find_illegal(); | |
8329 else | |
8330 show_utf8(); | |
7 | 8331 break; |
8332 #endif | |
8333 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8334 /* "g<": show scrollback text */ |
447 | 8335 case '<': |
8336 show_sb_text(); | |
8337 break; | |
8338 | |
7 | 8339 /* |
8340 * "gg": Goto the first line in file. With a count it goes to | |
8341 * that line number like for "G". -- webb | |
8342 */ | |
8343 case 'g': | |
8344 cap->arg = FALSE; | |
8345 nv_goto(cap); | |
8346 break; | |
8347 | |
8348 /* | |
8349 * Two-character operators: | |
8350 * "gq" Format text | |
8351 * "gw" Format text and keep cursor position | |
8352 * "g~" Toggle the case of the text. | |
8353 * "gu" Change text to lower case. | |
8354 * "gU" Change text to upper case. | |
8355 * "g?" rot13 encoding | |
602 | 8356 * "g@" call 'operatorfunc' |
7 | 8357 */ |
8358 case 'q': | |
8359 case 'w': | |
8360 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
|
8361 /* FALLTHROUGH */ |
7 | 8362 case '~': |
8363 case 'u': | |
8364 case 'U': | |
8365 case '?': | |
602 | 8366 case '@': |
7 | 8367 nv_operator(cap); |
8368 break; | |
8369 | |
8370 /* | |
1188 | 8371 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8372 * current function |
8373 * "gD": idem, but in the current file. | |
8374 */ | |
8375 case 'd': | |
8376 case 'D': | |
523 | 8377 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8378 break; |
8379 | |
8380 #ifdef FEAT_MOUSE | |
8381 /* | |
8382 * g<*Mouse> : <C-*mouse> | |
8383 */ | |
8384 case K_MIDDLEMOUSE: | |
8385 case K_MIDDLEDRAG: | |
8386 case K_MIDDLERELEASE: | |
8387 case K_LEFTMOUSE: | |
8388 case K_LEFTDRAG: | |
8389 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8390 case K_MOUSEMOVE: |
7 | 8391 case K_RIGHTMOUSE: |
8392 case K_RIGHTDRAG: | |
8393 case K_RIGHTRELEASE: | |
8394 case K_X1MOUSE: | |
8395 case K_X1DRAG: | |
8396 case K_X1RELEASE: | |
8397 case K_X2MOUSE: | |
8398 case K_X2DRAG: | |
8399 case K_X2RELEASE: | |
8400 mod_mask = MOD_MASK_CTRL; | |
8401 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8402 break; | |
8403 #endif | |
8404 | |
8405 case K_IGNORE: | |
8406 break; | |
8407 | |
8408 /* | |
8409 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8410 */ | |
8411 case 'p': | |
8412 case 'P': | |
8413 nv_put(cap); | |
8414 break; | |
8415 | |
8416 #ifdef FEAT_BYTEOFF | |
8417 /* "go": goto byte count from start of buffer */ | |
8418 case 'o': | |
8419 goto_byte(cap->count0); | |
8420 break; | |
8421 #endif | |
8422 | |
8423 /* "gQ": improved Ex mode */ | |
8424 case 'Q': | |
633 | 8425 if (text_locked()) |
7 | 8426 { |
8427 clearopbeep(cap->oap); | |
633 | 8428 text_locked_msg(); |
7 | 8429 break; |
8430 } | |
631 | 8431 |
7 | 8432 if (!checkclearopq(oap)) |
8433 do_exmode(TRUE); | |
8434 break; | |
8435 | |
8436 #ifdef FEAT_JUMPLIST | |
8437 case ',': | |
8438 nv_pcmark(cap); | |
8439 break; | |
8440 | |
8441 case ';': | |
8442 cap->count1 = -cap->count1; | |
8443 nv_pcmark(cap); | |
8444 break; | |
8445 #endif | |
8446 | |
667 | 8447 case 't': |
3630 | 8448 if (!checkclearop(oap)) |
8449 goto_tabpage((int)cap->count0); | |
667 | 8450 break; |
682 | 8451 case 'T': |
3630 | 8452 if (!checkclearop(oap)) |
8453 goto_tabpage(-(int)cap->count1); | |
682 | 8454 break; |
667 | 8455 |
750 | 8456 case '+': |
8457 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8458 if (!checkclearopq(oap)) | |
771 | 8459 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
|
8460 FALSE, FALSE, FALSE); |
750 | 8461 break; |
8462 | |
7 | 8463 default: |
8464 clearopbeep(oap); | |
8465 break; | |
8466 } | |
8467 } | |
8468 | |
8469 /* | |
8470 * Handle "o" and "O" commands. | |
8471 */ | |
8472 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8473 n_opencmd(cmdarg_T *cap) |
7 | 8474 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8475 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8476 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8477 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8478 |
7 | 8479 if (!checkclearopq(cap->oap)) |
8480 { | |
8481 #ifdef FEAT_FOLDING | |
8482 if (cap->cmdchar == 'O') | |
8483 /* Open above the first line of a folded sequence of lines */ | |
8484 (void)hasFolding(curwin->w_cursor.lnum, | |
8485 &curwin->w_cursor.lnum, NULL); | |
8486 else | |
8487 /* Open below the last line of a folded sequence of lines */ | |
8488 (void)hasFolding(curwin->w_cursor.lnum, | |
8489 NULL, &curwin->w_cursor.lnum); | |
8490 #endif | |
8491 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8492 (cap->cmdchar == 'O' ? 1 : 0)), | |
8493 (linenr_T)(curwin->w_cursor.lnum + | |
8494 (cap->cmdchar == 'o' ? 1 : 0)) | |
8495 ) == OK | |
8496 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8497 #ifdef FEAT_COMMENTS | |
8498 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8499 #endif | |
8500 0, 0)) | |
8501 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8502 #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
|
8503 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
|
8504 update_single_line(curwin, oldline); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8505 #endif |
164 | 8506 /* When '#' is in 'cpoptions' ignore the count. */ |
8507 if (vim_strchr(p_cpo, CPO_HASH) != NULL) | |
8508 cap->count1 = 1; | |
6834 | 8509 #ifdef FEAT_SYN_HL |
6821 | 8510 if (curwin->w_p_cul) |
8511 /* force redraw of cursorline */ | |
8512 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8513 #endif |
7 | 8514 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8515 } | |
8516 } | |
8517 } | |
8518 | |
8519 /* | |
8520 * "." command: redo last change. | |
8521 */ | |
8522 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8523 nv_dot(cmdarg_T *cap) |
7 | 8524 { |
8525 if (!checkclearopq(cap->oap)) | |
8526 { | |
8527 /* | |
8528 * If "restart_edit" is TRUE, the last but one command is repeated | |
8529 * instead of the last command (inserting text). This is used for | |
8530 * CTRL-O <.> in insert mode. | |
8531 */ | |
8532 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8533 clearopbeep(cap->oap); | |
8534 } | |
8535 } | |
8536 | |
8537 /* | |
8538 * CTRL-R: undo undo | |
8539 */ | |
8540 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8541 nv_redo(cmdarg_T *cap) |
7 | 8542 { |
8543 if (!checkclearopq(cap->oap)) | |
8544 { | |
8545 u_redo((int)cap->count1); | |
8546 curwin->w_set_curswant = TRUE; | |
8547 } | |
8548 } | |
8549 | |
8550 /* | |
8551 * Handle "U" command. | |
8552 */ | |
8553 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8554 nv_Undo(cmdarg_T *cap) |
7 | 8555 { |
8556 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8557 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8558 { |
8559 /* translate "gUU" to "gUgU" */ | |
8560 cap->cmdchar = 'g'; | |
8561 cap->nchar = 'U'; | |
8562 nv_operator(cap); | |
8563 } | |
8564 else if (!checkclearopq(cap->oap)) | |
8565 { | |
8566 u_undoline(); | |
8567 curwin->w_set_curswant = TRUE; | |
8568 } | |
8569 } | |
8570 | |
8571 /* | |
8572 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8573 * single character. | |
8574 */ | |
8575 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8576 nv_tilde(cmdarg_T *cap) |
7 | 8577 { |
5735 | 8578 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
7 | 8579 n_swapchar(cap); |
8580 else | |
8581 nv_operator(cap); | |
8582 } | |
8583 | |
8584 /* | |
8585 * Handle an operator command. | |
8586 * The actual work is done by do_pending_operator(). | |
8587 */ | |
8588 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8589 nv_operator(cmdarg_T *cap) |
7 | 8590 { |
8591 int op_type; | |
8592 | |
8593 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
8594 | |
8595 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8596 nv_lineop(cap); | |
8597 else if (!checkclearop(cap->oap)) | |
8598 { | |
8599 cap->oap->start = curwin->w_cursor; | |
8600 cap->oap->op_type = op_type; | |
1490 | 8601 #ifdef FEAT_EVAL |
8602 set_op_var(op_type); | |
8603 #endif | |
8604 } | |
8605 } | |
8606 | |
8607 #ifdef FEAT_EVAL | |
8608 /* | |
8609 * Set v:operator to the characters for "optype". | |
8610 */ | |
8611 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8612 set_op_var(int optype) |
1490 | 8613 { |
8614 char_u opchars[3]; | |
8615 | |
8616 if (optype == OP_NOP) | |
8617 set_vim_var_string(VV_OP, NULL, 0); | |
8618 else | |
8619 { | |
8620 opchars[0] = get_op_char(optype); | |
8621 opchars[1] = get_extra_op_char(optype); | |
8622 opchars[2] = NUL; | |
8623 set_vim_var_string(VV_OP, opchars, -1); | |
8624 } | |
8625 } | |
8626 #endif | |
7 | 8627 |
8628 /* | |
8629 * Handle linewise operator "dd", "yy", etc. | |
8630 * | |
8631 * "_" is is a strange motion command that helps make operators more logical. | |
8632 * It is actually implemented, but not documented in the real Vi. This motion | |
8633 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8634 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8635 * "d3_" works to delete 3 lines. | |
8636 */ | |
8637 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8638 nv_lineop(cmdarg_T *cap) |
7 | 8639 { |
8640 cap->oap->motion_type = MLINE; | |
8641 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8642 clearopbeep(cap->oap); | |
4011 | 8643 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8644 && cap->oap->motion_force != 'v' | |
8645 && cap->oap->motion_force != Ctrl_V) | |
7 | 8646 || cap->oap->op_type == OP_LSHIFT |
8647 || cap->oap->op_type == OP_RSHIFT) | |
8648 beginline(BL_SOL | BL_FIX); | |
8649 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8650 beginline(BL_WHITE | BL_FIX); | |
8651 } | |
8652 | |
8653 /* | |
8654 * <Home> command. | |
8655 */ | |
8656 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8657 nv_home(cmdarg_T *cap) |
7 | 8658 { |
180 | 8659 /* CTRL-HOME is like "gg" */ |
8660 if (mod_mask & MOD_MASK_CTRL) | |
8661 nv_goto(cap); | |
8662 else | |
8663 { | |
8664 cap->count0 = 1; | |
8665 nv_pipe(cap); | |
8666 } | |
229 | 8667 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8668 one-character line). */ | |
7 | 8669 } |
8670 | |
8671 /* | |
8672 * "|" command. | |
8673 */ | |
8674 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8675 nv_pipe(cmdarg_T *cap) |
7 | 8676 { |
8677 cap->oap->motion_type = MCHAR; | |
8678 cap->oap->inclusive = FALSE; | |
8679 beginline(0); | |
8680 if (cap->count0 > 0) | |
8681 { | |
8682 coladvance((colnr_T)(cap->count0 - 1)); | |
8683 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8684 } | |
8685 else | |
8686 curwin->w_curswant = 0; | |
8687 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8688 * we ended; differs if line is too short */ |
7 | 8689 curwin->w_set_curswant = FALSE; |
8690 } | |
8691 | |
8692 /* | |
8693 * Handle back-word command "b" and "B". | |
8694 * cap->arg is 1 for "B" | |
8695 */ | |
8696 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8697 nv_bck_word(cmdarg_T *cap) |
7 | 8698 { |
8699 cap->oap->motion_type = MCHAR; | |
8700 cap->oap->inclusive = FALSE; | |
8701 curwin->w_set_curswant = TRUE; | |
8702 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8703 clearopbeep(cap->oap); | |
8704 #ifdef FEAT_FOLDING | |
8705 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8706 foldOpenCursor(); | |
8707 #endif | |
8708 } | |
8709 | |
8710 /* | |
8711 * Handle word motion commands "e", "E", "w" and "W". | |
8712 * cap->arg is TRUE for "E" and "W". | |
8713 */ | |
8714 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8715 nv_wordcmd(cmdarg_T *cap) |
7 | 8716 { |
8717 int n; | |
8718 int word_end; | |
8719 int flag = FALSE; | |
1573 | 8720 pos_T startpos = curwin->w_cursor; |
7 | 8721 |
8722 /* | |
8723 * Set inclusive for the "E" and "e" command. | |
8724 */ | |
8725 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8726 word_end = TRUE; | |
8727 else | |
8728 word_end = FALSE; | |
8729 cap->oap->inclusive = word_end; | |
8730 | |
8731 /* | |
8732 * "cw" and "cW" are a special case. | |
8733 */ | |
8734 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8735 { | |
8736 n = gchar_cursor(); | |
8737 if (n != NUL) /* not an empty line */ | |
8738 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8739 if (VIM_ISWHITE(n)) |
7 | 8740 { |
8741 /* | |
8742 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8743 * changes one character, not all blanks until the start of | |
8744 * the next word. Only do this when the 'w' flag is included | |
8745 * in 'cpoptions'. | |
8746 */ | |
8747 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8748 { | |
8749 cap->oap->inclusive = TRUE; | |
8750 cap->oap->motion_type = MCHAR; | |
8751 return; | |
8752 } | |
8753 } | |
8754 else | |
8755 { | |
8756 /* | |
8757 * This is a little strange. To match what the real Vi does, | |
8758 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8759 * that we are not on a space or a TAB. This seems impolite | |
8760 * at first, but it's really more what we mean when we say | |
8761 * 'cw'. | |
8762 * Another strangeness: When standing on the end of a word | |
4352 | 8763 * "ce" will change until the end of the next word, but "cw" |
7 | 8764 * will change only one character! This is done by setting |
8765 * flag. | |
8766 */ | |
8767 cap->oap->inclusive = TRUE; | |
8768 word_end = TRUE; | |
8769 flag = TRUE; | |
8770 } | |
8771 } | |
8772 } | |
8773 | |
8774 cap->oap->motion_type = MCHAR; | |
8775 curwin->w_set_curswant = TRUE; | |
8776 if (word_end) | |
8777 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8778 else | |
8779 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8780 | |
1573 | 8781 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8782 * 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
|
8783 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8784 adjust_cursor(cap->oap); |
7 | 8785 |
8786 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8787 clearopbeep(cap->oap); | |
8788 else | |
8789 { | |
8790 adjust_for_sel(cap); | |
8791 #ifdef FEAT_FOLDING | |
8792 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8793 foldOpenCursor(); | |
8794 #endif | |
8795 } | |
8796 } | |
8797 | |
8798 /* | |
1505 | 8799 * Used after a movement command: If the cursor ends up on the NUL after the |
8800 * end of the line, may move it back to the last character and make the motion | |
8801 * inclusive. | |
8802 */ | |
8803 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8804 adjust_cursor(oparg_T *oap) |
1505 | 8805 { |
8806 /* The cursor cannot remain on the NUL when: | |
8807 * - the column is > 0 | |
8808 * - not in Visual mode or 'selection' is "o" | |
8809 * - 'virtualedit' is not "all" and not "onemore". | |
8810 */ | |
8811 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8812 && (!VIsual_active || *p_sel == 'o') | |
8813 #ifdef FEAT_VIRTUALEDIT | |
8814 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8815 #endif | |
8816 ) | |
8817 { | |
8818 --curwin->w_cursor.col; | |
8819 #ifdef FEAT_MBYTE | |
8820 /* prevent cursor from moving on the trail byte */ | |
8821 if (has_mbyte) | |
8822 mb_adjust_cursor(); | |
8823 #endif | |
8824 oap->inclusive = TRUE; | |
8825 } | |
8826 } | |
8827 | |
8828 /* | |
7 | 8829 * "0" and "^" commands. |
8830 * cap->arg is the argument for beginline(). | |
8831 */ | |
8832 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8833 nv_beginline(cmdarg_T *cap) |
7 | 8834 { |
8835 cap->oap->motion_type = MCHAR; | |
8836 cap->oap->inclusive = FALSE; | |
8837 beginline(cap->arg); | |
8838 #ifdef FEAT_FOLDING | |
8839 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8840 foldOpenCursor(); | |
8841 #endif | |
557 | 8842 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8843 one-character line). */ | |
7 | 8844 } |
8845 | |
8846 /* | |
8847 * In exclusive Visual mode, may include the last character. | |
8848 */ | |
8849 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8850 adjust_for_sel(cmdarg_T *cap) |
7 | 8851 { |
8852 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
|
8853 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8854 { |
5735 | 8855 #ifdef FEAT_MBYTE |
7 | 8856 if (has_mbyte) |
8857 inc_cursor(); | |
8858 else | |
5735 | 8859 #endif |
7 | 8860 ++curwin->w_cursor.col; |
8861 cap->oap->inclusive = FALSE; | |
8862 } | |
8863 } | |
8864 | |
8865 /* | |
8866 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8867 * Should check VIsual_mode before calling this. | |
8868 * Returns TRUE when backed up to the previous line. | |
8869 */ | |
8870 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8871 unadjust_for_sel(void) |
7 | 8872 { |
8873 pos_T *pp; | |
8874 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8875 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
|
8876 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8877 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8878 pp = &curwin->w_cursor; |
8879 else | |
8880 pp = &VIsual; | |
8881 #ifdef FEAT_VIRTUALEDIT | |
8882 if (pp->coladd > 0) | |
8883 --pp->coladd; | |
8884 else | |
8885 #endif | |
8886 if (pp->col > 0) | |
8887 { | |
8888 --pp->col; | |
8889 #ifdef FEAT_MBYTE | |
2933 | 8890 mb_adjustpos(curbuf, pp); |
7 | 8891 #endif |
8892 } | |
8893 else if (pp->lnum > 1) | |
8894 { | |
8895 --pp->lnum; | |
8896 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8897 return TRUE; | |
8898 } | |
8899 } | |
8900 return FALSE; | |
8901 } | |
8902 | |
8903 /* | |
8904 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8905 */ | |
8906 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8907 nv_select(cmdarg_T *cap) |
7 | 8908 { |
8909 if (VIsual_active) | |
8910 VIsual_select = TRUE; | |
8911 else if (VIsual_reselect) | |
8912 { | |
8913 cap->nchar = 'v'; /* fake "gv" command */ | |
8914 cap->arg = TRUE; | |
8915 nv_g_cmd(cap); | |
8916 } | |
8917 } | |
8918 | |
8919 | |
8920 /* | |
8921 * "G", "gg", CTRL-END, CTRL-HOME. | |
8922 * cap->arg is TRUE for "G". | |
8923 */ | |
8924 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8925 nv_goto(cmdarg_T *cap) |
7 | 8926 { |
8927 linenr_T lnum; | |
8928 | |
8929 if (cap->arg) | |
8930 lnum = curbuf->b_ml.ml_line_count; | |
8931 else | |
8932 lnum = 1L; | |
8933 cap->oap->motion_type = MLINE; | |
8934 setpcmark(); | |
8935 | |
8936 /* When a count is given, use it instead of the default lnum */ | |
8937 if (cap->count0 != 0) | |
8938 lnum = cap->count0; | |
8939 if (lnum < 1L) | |
8940 lnum = 1L; | |
8941 else if (lnum > curbuf->b_ml.ml_line_count) | |
8942 lnum = curbuf->b_ml.ml_line_count; | |
8943 curwin->w_cursor.lnum = lnum; | |
8944 beginline(BL_SOL | BL_FIX); | |
8945 #ifdef FEAT_FOLDING | |
8946 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8947 foldOpenCursor(); | |
8948 #endif | |
8949 } | |
8950 | |
8951 /* | |
8952 * CTRL-\ in Normal mode. | |
8953 */ | |
8954 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8955 nv_normal(cmdarg_T *cap) |
7 | 8956 { |
8957 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8958 { | |
8959 clearop(cap->oap); | |
643 | 8960 if (restart_edit != 0 && mode_displayed) |
7 | 8961 clear_cmdline = TRUE; /* unshow mode later */ |
8962 restart_edit = 0; | |
8963 #ifdef FEAT_CMDWIN | |
8964 if (cmdwin_type != 0) | |
8965 cmdwin_result = Ctrl_C; | |
8966 #endif | |
8967 if (VIsual_active) | |
8968 { | |
8969 end_visual_mode(); /* stop Visual */ | |
8970 redraw_curbuf_later(INVERTED); | |
8971 } | |
8972 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8973 if (cap->nchar == Ctrl_G && p_im) | |
8974 restart_edit = 'a'; | |
8975 } | |
8976 else | |
8977 clearopbeep(cap->oap); | |
8978 } | |
8979 | |
8980 /* | |
8981 * ESC in Normal mode: beep, but don't flush buffers. | |
8982 * Don't even beep if we are canceling a command. | |
8983 */ | |
8984 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8985 nv_esc(cmdarg_T *cap) |
7 | 8986 { |
8987 int no_reason; | |
8988 | |
8989 no_reason = (cap->oap->op_type == OP_NOP | |
8990 && cap->opcount == 0 | |
8991 && cap->count0 == 0 | |
8992 && cap->oap->regname == 0 | |
8993 && !p_im); | |
8994 | |
8995 if (cap->arg) /* TRUE for CTRL-C */ | |
8996 { | |
8997 if (restart_edit == 0 | |
8998 #ifdef FEAT_CMDWIN | |
8999 && cmdwin_type == 0 | |
9000 #endif | |
9001 && !VIsual_active | |
9002 && 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
|
9003 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9004 |
9005 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9006 * set again below when halfway a mapping. */ | |
9007 if (!p_im) | |
9008 restart_edit = 0; | |
9009 #ifdef FEAT_CMDWIN | |
9010 if (cmdwin_type != 0) | |
9011 { | |
9012 cmdwin_result = K_IGNORE; | |
9013 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9014 return; | |
9015 } | |
9016 #endif | |
9017 } | |
9018 | |
9019 if (VIsual_active) | |
9020 { | |
9021 end_visual_mode(); /* stop Visual */ | |
9022 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9023 curwin->w_set_curswant = TRUE; | |
9024 redraw_curbuf_later(INVERTED); | |
9025 } | |
5735 | 9026 else if (no_reason) |
6949 | 9027 vim_beep(BO_ESC); |
7 | 9028 clearop(cap->oap); |
9029 | |
9030 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9031 * 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
|
9032 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9033 restart_edit = 'a'; |
9034 } | |
9035 | |
9036 /* | |
9037 * 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
|
9038 * Also handle K_PS, start bracketed paste. |
7 | 9039 */ |
9040 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9041 nv_edit(cmdarg_T *cap) |
7 | 9042 { |
9043 /* <Insert> is equal to "i" */ | |
9044 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9045 cap->cmdchar = 'i'; | |
9046 | |
9047 /* in Visual mode "A" and "I" are an operator */ | |
9048 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
|
9049 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9050 #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
|
9051 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
|
9052 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9053 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
|
9054 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
|
9055 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
|
9056 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9057 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9058 #endif |
7 | 9059 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
|
9060 } |
7 | 9061 |
9062 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 9063 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9064 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 9065 { |
9066 #ifdef FEAT_TEXTOBJ | |
9067 nv_object(cap); | |
9068 #else | |
9069 clearopbeep(cap->oap); | |
9070 #endif | |
9071 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9072 #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
|
9073 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
|
9074 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9075 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
|
9076 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
|
9077 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9078 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9079 #endif |
7 | 9080 else if (!curbuf->b_p_ma && !p_im) |
9081 { | |
9082 /* Only give this error when 'insertmode' is off. */ | |
9083 EMSG(_(e_modifiable)); | |
9084 clearop(cap->oap); | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9085 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9086 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9087 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9088 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9089 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
|
9090 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9091 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
|
9092 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
|
9093 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9094 /* 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
|
9095 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
|
9096 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9097 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
|
9098 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
|
9099 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9100 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9101 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
|
9102 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
|
9103 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
|
9104 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
|
9105 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
|
9106 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
|
9107 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9108 /* 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
|
9109 * 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
|
9110 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
|
9111 && 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
|
9112 inc_cursor(); |
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 /* 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
|
9115 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
|
9116 } |
7 | 9117 else if (!checkclearopq(cap->oap)) |
9118 { | |
9119 switch (cap->cmdchar) | |
9120 { | |
9121 case 'A': /* "A"ppend after the line */ | |
9122 curwin->w_set_curswant = TRUE; | |
9123 #ifdef FEAT_VIRTUALEDIT | |
9124 if (ve_flags == VE_ALL) | |
9125 { | |
9126 int save_State = State; | |
9127 | |
4352 | 9128 /* Pretend Insert mode here to allow the cursor on the |
7 | 9129 * character past the end of the line */ |
9130 State = INSERT; | |
9131 coladvance((colnr_T)MAXCOL); | |
9132 State = save_State; | |
9133 } | |
9134 else | |
9135 #endif | |
9136 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9137 break; | |
9138 | |
9139 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9140 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9141 beginline(BL_WHITE); | |
9142 else | |
9143 beginline(BL_WHITE|BL_FIX); | |
7 | 9144 break; |
9145 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9146 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
|
9147 /* 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
|
9148 * 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
|
9149 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
|
9150 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9151 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9152 |
7 | 9153 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9154 #ifdef FEAT_VIRTUALEDIT | |
9155 /* increment coladd when in virtual space, increment the | |
9156 * column otherwise, also to append after an unprintable char */ | |
9157 if (virtual_active() | |
9158 && (curwin->w_cursor.coladd > 0 | |
9159 || *ml_get_cursor() == NUL | |
9160 || *ml_get_cursor() == TAB)) | |
9161 curwin->w_cursor.coladd++; | |
9162 else | |
9163 #endif | |
9164 if (*ml_get_cursor() != NUL) | |
9165 inc_cursor(); | |
9166 break; | |
9167 } | |
9168 | |
9169 #ifdef FEAT_VIRTUALEDIT | |
9170 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9171 { | |
9172 int save_State = State; | |
9173 | |
4352 | 9174 /* Pretend Insert mode here to allow the cursor on the |
7 | 9175 * character past the end of the line */ |
9176 State = INSERT; | |
9177 coladvance(getviscol()); | |
9178 State = save_State; | |
9179 } | |
9180 #endif | |
9181 | |
9182 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9183 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9184 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
|
9185 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9186 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9187 } |
9188 | |
9189 /* | |
9190 * Invoke edit() and take care of "restart_edit" and the return value. | |
9191 */ | |
9192 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9193 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9194 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9195 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9196 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9197 int startln) |
7 | 9198 { |
9199 int restart_edit_save = 0; | |
9200 | |
9201 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9202 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9203 * it. */ | |
9204 if (repl || !stuff_empty()) | |
9205 restart_edit_save = restart_edit; | |
9206 else | |
9207 restart_edit_save = 0; | |
9208 | |
9209 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9210 restart_edit = 0; | |
9211 | |
9212 if (edit(cmd, startln, cap->count1)) | |
9213 cap->retval |= CA_COMMAND_BUSY; | |
9214 | |
9215 if (restart_edit == 0) | |
9216 restart_edit = restart_edit_save; | |
9217 } | |
9218 | |
9219 #ifdef FEAT_TEXTOBJ | |
9220 /* | |
9221 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9222 */ | |
9223 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9224 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9225 cmdarg_T *cap) |
7 | 9226 { |
9227 int flag; | |
9228 int include; | |
9229 char_u *mps_save; | |
9230 | |
9231 if (cap->cmdchar == 'i') | |
9232 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9233 else | |
9234 include = TRUE; /* "ax" = an object: include white space */ | |
9235 | |
9236 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9237 mps_save = curbuf->b_p_mps; | |
9238 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9239 | |
9240 switch (cap->nchar) | |
9241 { | |
9242 case 'w': /* "aw" = a word */ | |
9243 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9244 break; | |
9245 case 'W': /* "aW" = a WORD */ | |
9246 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9247 break; | |
9248 case 'b': /* "ab" = a braces block */ | |
9249 case '(': | |
9250 case ')': | |
9251 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9252 break; | |
9253 case 'B': /* "aB" = a Brackets block */ | |
9254 case '{': | |
9255 case '}': | |
9256 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9257 break; | |
9258 case '[': /* "a[" = a [] block */ | |
9259 case ']': | |
9260 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9261 break; | |
9262 case '<': /* "a<" = a <> block */ | |
9263 case '>': | |
9264 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9265 break; | |
420 | 9266 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9267 /* Do not adjust oap->end in do_pending_operator() |
9268 * otherwise there are different results for 'dit' | |
9269 * (note leading whitespace in last line): | |
9270 * 1) <b> 2) <b> | |
9271 * foobar foobar | |
9272 * </b> </b> | |
9273 */ | |
9274 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9275 flag = current_tagblock(cap->oap, cap->count1, include); |
9276 break; | |
7 | 9277 case 'p': /* "ap" = a paragraph */ |
9278 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9279 break; | |
9280 case 's': /* "as" = a sentence */ | |
9281 flag = current_sent(cap->oap, cap->count1, include); | |
9282 break; | |
12 | 9283 case '"': /* "a"" = a double quoted string */ |
9284 case '\'': /* "a'" = a single quoted string */ | |
9285 case '`': /* "a`" = a backtick quoted string */ | |
9286 flag = current_quote(cap->oap, cap->count1, include, | |
9287 cap->nchar); | |
9288 break; | |
7 | 9289 #if 0 /* TODO */ |
9290 case 'S': /* "aS" = a section */ | |
9291 case 'f': /* "af" = a filename */ | |
9292 case 'u': /* "au" = a URL */ | |
9293 #endif | |
9294 default: | |
9295 flag = FAIL; | |
9296 break; | |
9297 } | |
9298 | |
9299 curbuf->b_p_mps = mps_save; | |
9300 if (flag == FAIL) | |
9301 clearopbeep(cap->oap); | |
9302 adjust_cursor_col(); | |
9303 curwin->w_set_curswant = TRUE; | |
9304 } | |
9305 #endif | |
9306 | |
9307 /* | |
9308 * "q" command: Start/stop recording. | |
9309 * "q:", "q/", "q?": edit command-line in command-line window. | |
9310 */ | |
9311 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9312 nv_record(cmdarg_T *cap) |
7 | 9313 { |
9314 if (cap->oap->op_type == OP_FORMAT) | |
9315 { | |
9316 /* "gqq" is the same as "gqgq": format line */ | |
9317 cap->cmdchar = 'g'; | |
9318 cap->nchar = 'q'; | |
9319 nv_operator(cap); | |
9320 } | |
9321 else if (!checkclearop(cap->oap)) | |
9322 { | |
9323 #ifdef FEAT_CMDWIN | |
9324 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9325 { | |
9326 stuffcharReadbuff(cap->nchar); | |
9327 stuffcharReadbuff(K_CMDWIN); | |
9328 } | |
9329 else | |
9330 #endif | |
9331 /* (stop) recording into a named register, unless executing a | |
9332 * register */ | |
9333 if (!Exec_reg && do_record(cap->nchar) == FAIL) | |
9334 clearopbeep(cap->oap); | |
9335 } | |
9336 } | |
9337 | |
9338 /* | |
9339 * Handle the "@r" command. | |
9340 */ | |
9341 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9342 nv_at(cmdarg_T *cap) |
7 | 9343 { |
9344 if (checkclearop(cap->oap)) | |
9345 return; | |
9346 #ifdef FEAT_EVAL | |
9347 if (cap->nchar == '=') | |
9348 { | |
9349 if (get_expr_register() == NUL) | |
9350 return; | |
9351 } | |
9352 #endif | |
9353 while (cap->count1-- && !got_int) | |
9354 { | |
1034 | 9355 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9356 { |
9357 clearopbeep(cap->oap); | |
9358 break; | |
9359 } | |
9360 line_breakcheck(); | |
9361 } | |
9362 } | |
9363 | |
9364 /* | |
9365 * Handle the CTRL-U and CTRL-D commands. | |
9366 */ | |
9367 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9368 nv_halfpage(cmdarg_T *cap) |
7 | 9369 { |
9370 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9371 || (cap->cmdchar == Ctrl_D | |
9372 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9373 clearopbeep(cap->oap); | |
9374 else if (!checkclearop(cap->oap)) | |
9375 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9376 } | |
9377 | |
9378 /* | |
9379 * Handle "J" or "gJ" command. | |
9380 */ | |
9381 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9382 nv_join(cmdarg_T *cap) |
7 | 9383 { |
9384 if (VIsual_active) /* join the visual lines */ | |
9385 nv_operator(cap); | |
5735 | 9386 else if (!checkclearop(cap->oap)) |
7 | 9387 { |
9388 if (cap->count0 <= 1) | |
9389 cap->count0 = 2; /* default for join is two lines! */ | |
9390 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9391 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
|
9392 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9393 /* 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
|
9394 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9395 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9396 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9397 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9398 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9399 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
|
9400 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9401 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9402 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9403 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
|
9404 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
|
9405 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9406 } |
9407 } | |
9408 | |
9409 /* | |
9410 * "P", "gP", "p" and "gp" commands. | |
9411 */ | |
9412 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9413 nv_put(cmdarg_T *cap) |
7 | 9414 { |
9415 int regname = 0; | |
9416 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9417 int empty = FALSE; |
236 | 9418 int was_visual = FALSE; |
7 | 9419 int dir; |
9420 int flags = 0; | |
9421 | |
9422 if (cap->oap->op_type != OP_NOP) | |
9423 { | |
9424 #ifdef FEAT_DIFF | |
9425 /* "dp" is ":diffput" */ | |
9426 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9427 { | |
9428 clearop(cap->oap); | |
6314 | 9429 nv_diffgetput(TRUE, cap->opcount); |
7 | 9430 } |
9431 else | |
9432 #endif | |
9433 clearopbeep(cap->oap); | |
9434 } | |
9435 else | |
9436 { | |
9437 dir = (cap->cmdchar == 'P' | |
9438 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9439 ? BACKWARD : FORWARD; | |
9440 prep_redo_cmd(cap); | |
9441 if (cap->cmdchar == 'g') | |
9442 flags |= PUT_CURSEND; | |
9443 | |
9444 if (VIsual_active) | |
9445 { | |
9446 /* Putting in Visual mode: The put text replaces the selected | |
9447 * text. First delete the selected text, then put the new text. | |
9448 * Need to save and restore the registers that the delete | |
9449 * overwrites if the old contents is being put. | |
9450 */ | |
236 | 9451 was_visual = TRUE; |
7 | 9452 regname = cap->oap->regname; |
5735 | 9453 #ifdef FEAT_CLIPBOARD |
7 | 9454 adjust_clip_reg(®name); |
5735 | 9455 #endif |
5682 | 9456 if (regname == 0 || regname == '"' |
4013 | 9457 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9458 #ifdef FEAT_CLIPBOARD |
7 | 9459 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9460 #endif |
7 | 9461 |
9462 ) | |
9463 { | |
4013 | 9464 /* The delete is going to overwrite the register we want to |
7 | 9465 * put, save it first. */ |
9466 reg1 = get_register(regname, TRUE); | |
9467 } | |
9468 | |
9469 /* Now delete the selected text. */ | |
9470 cap->cmdchar = 'd'; | |
9471 cap->nchar = NUL; | |
9472 cap->oap->regname = NUL; | |
9473 nv_operator(cap); | |
9474 do_pending_operator(cap, 0, FALSE); | |
84 | 9475 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9476 |
9477 /* delete PUT_LINE_BACKWARD; */ | |
9478 cap->oap->regname = regname; | |
9479 | |
9480 if (reg1 != NULL) | |
9481 { | |
9482 /* Delete probably changed the register we want to put, save | |
9483 * it first. Then put back what was there before the delete. */ | |
9484 reg2 = get_register(regname, FALSE); | |
9485 put_register(regname, reg1); | |
9486 } | |
9487 | |
9488 /* When deleted a linewise Visual area, put the register as | |
9489 * lines to avoid it joined with the next line. When deletion was | |
9490 * characterwise, split a line when putting lines. */ | |
9491 if (VIsual_mode == 'V') | |
9492 flags |= PUT_LINE; | |
9493 else if (VIsual_mode == 'v') | |
9494 flags |= PUT_LINE_SPLIT; | |
9495 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9496 flags |= PUT_LINE_FORWARD; | |
9497 dir = BACKWARD; | |
9498 if ((VIsual_mode != 'V' | |
9499 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9500 || (VIsual_mode == 'V' | |
9501 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9502 /* cursor is at the end of the line or end of file, put | |
9503 * forward. */ | |
9504 dir = FORWARD; | |
5365 | 9505 /* May have been reset in do_put(). */ |
9506 VIsual_active = TRUE; | |
7 | 9507 } |
9508 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9509 | |
9510 /* If a register was saved, put it back now. */ | |
9511 if (reg2 != NULL) | |
9512 put_register(regname, reg2); | |
236 | 9513 |
9514 /* What to reselect with "gv"? Selecting the just put text seems to | |
9515 * be the most useful, since the original text was removed. */ | |
9516 if (was_visual) | |
9517 { | |
690 | 9518 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9519 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
|
9520 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9521 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9522 inc(&curbuf->b_visual.vi_end); |
236 | 9523 } |
9524 | |
84 | 9525 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9526 * line that needs to be deleted now. */ |
84 | 9527 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9528 { |
84 | 9529 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9530 |
9531 /* If the cursor was in that line, move it to the end of the last | |
9532 * line. */ | |
9533 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9534 { | |
9535 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9536 coladvance((colnr_T)MAXCOL); | |
9537 } | |
9538 } | |
7 | 9539 auto_format(FALSE, TRUE); |
9540 } | |
9541 } | |
9542 | |
9543 /* | |
9544 * "o" and "O" commands. | |
9545 */ | |
9546 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9547 nv_open(cmdarg_T *cap) |
7 | 9548 { |
9549 #ifdef FEAT_DIFF | |
9550 /* "do" is ":diffget" */ | |
9551 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9552 { | |
9553 clearop(cap->oap); | |
6314 | 9554 nv_diffgetput(FALSE, cap->opcount); |
7 | 9555 } |
9556 else | |
9557 #endif | |
9558 if (VIsual_active) /* switch start and end of visual */ | |
9559 v_swap_corners(cap->cmdchar); | |
9560 else | |
9561 n_opencmd(cap); | |
9562 } | |
9563 | |
9564 #ifdef FEAT_NETBEANS_INTG | |
9565 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9566 nv_nbcmd(cmdarg_T *cap) |
7 | 9567 { |
9568 netbeans_keycommand(cap->nchar); | |
9569 } | |
9570 #endif | |
9571 | |
9572 #ifdef FEAT_DND | |
9573 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9574 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9575 { |
9576 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9577 } | |
9578 #endif | |
203 | 9579 |
9580 /* | |
9581 * Trigger CursorHold event. | |
9582 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9583 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9584 */ | |
9585 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9586 nv_cursorhold(cmdarg_T *cap) |
203 | 9587 { |
9588 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9589 did_cursorhold = TRUE; | |
226 | 9590 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9591 } | |
6866 | 9592 |
9593 /* | |
7001 | 9594 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9595 */ |
9596 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9597 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9598 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9599 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9600 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9601 { |
9602 colnr_T start, end; | |
9603 | |
7001 | 9604 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
|
9605 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9606 return; |
9607 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9608 oap->block_mode = TRUE; |
6866 | 9609 |
9610 #ifdef FEAT_MBYTE | |
9611 /* prevent from moving onto a trail byte */ | |
9612 if (has_mbyte) | |
9613 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9614 #endif | |
9615 | |
9616 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9617 |
9618 if (!redo_VIsual_busy) | |
9619 { | |
9620 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9621 | |
9622 if (start < oap->start_vcol) | |
9623 oap->start_vcol = start; | |
9624 if (end > oap->end_vcol) | |
9625 { | |
9626 if (initial && *p_sel == 'e' && start >= 1 | |
9627 && start - 1 >= oap->end_vcol) | |
9628 oap->end_vcol = start - 1; | |
9629 else | |
9630 oap->end_vcol = end; | |
9631 } | |
9632 } | |
9633 | |
6866 | 9634 /* if '$' was used, get oap->end_vcol from longest line */ |
9635 if (curwin->w_curswant == MAXCOL) | |
9636 { | |
9637 curwin->w_cursor.col = MAXCOL; | |
9638 oap->end_vcol = 0; | |
9639 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9640 curwin->w_cursor.lnum <= oap->end.lnum; | |
9641 ++curwin->w_cursor.lnum) | |
9642 { | |
9643 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9644 if (end > oap->end_vcol) | |
9645 oap->end_vcol = end; | |
9646 } | |
9647 } | |
9648 else if (redo_VIsual_busy) | |
9649 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9650 /* | |
9651 * Correct oap->end.col and oap->start.col to be the | |
9652 * upper-left and lower-right corner of the block area. | |
9653 * | |
9654 * (Actually, this does convert column positions into character | |
9655 * positions) | |
9656 */ | |
9657 curwin->w_cursor.lnum = oap->end.lnum; | |
9658 coladvance(oap->end_vcol); | |
9659 oap->end = curwin->w_cursor; | |
9660 | |
9661 curwin->w_cursor = oap->start; | |
9662 coladvance(oap->start_vcol); | |
9663 oap->start = curwin->w_cursor; | |
9664 } |