Mercurial > vim
annotate src/normal.c @ 12136:60cf03e59402 v8.0.0948
patch 8.0.0948: crash if timer closes window while dragging status line
commit https://github.com/vim/vim/commit/989a70c590c2bd109eb362d3a0e48cb1427ae13d
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 16 22:46:01 2017 +0200
patch 8.0.0948: crash if timer closes window while dragging status line
Problem: Crash if timer closes window while dragging status line.
Solution: Check if the window still exists. (Yasuhiro Matsumoto, closes
#1979)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 16 Aug 2017 23:00:05 +0200 |
parents | e83c6c10320c |
children | 5d82470552ce |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * normal.c: Contains the main routine for processing characters in command | |
11 * mode. Communicates closely with the code in ops.c to handle | |
12 * the operators. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * The Visual area is remembered for reselection. | |
19 */ | |
20 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
21 static linenr_T resel_VIsual_line_count; /* number of lines */ | |
3125 | 22 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
5682 | 23 static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
7 | 24 |
25 static int restart_VIsual_select = 0; | |
26 | |
2667 | 27 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
28 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 29 #endif |
7 | 30 static int |
3531 | 31 #ifdef __BORLANDC__ |
32 _RTLENTRYF | |
33 #endif | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 nv_compare(const void *s1, const void *s2); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
35 static int find_command(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void op_colon(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
37 static void op_function(oparg_T *oap); |
5735 | 38 #if defined(FEAT_MOUSE) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
39 static void find_start_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
40 static void find_end_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
41 static int get_mouse_class(char_u *p); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
42 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
43 static void prep_redo_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 static void prep_redo(int regname, long, int, int, int, int, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
45 static int checkclearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
46 static int checkclearopq(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
47 static void clearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 static void clearopbeep(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
49 static void unshift_special(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
50 static void may_clear_cmdline(void); |
7 | 51 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 static void del_from_showcmd(int); |
7 | 53 #endif |
54 | |
55 /* | |
56 * nv_*(): functions called to handle Normal and Visual mode commands. | |
57 * n_*(): functions called to handle Normal mode commands. | |
58 * v_*(): functions called to handle Visual mode commands. | |
59 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
60 static void nv_ignore(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
61 static void nv_nop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
62 static void nv_error(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
63 static void nv_help(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
64 static void nv_addsub(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
65 static void nv_page(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
66 static void nv_gd(oparg_T *oap, int nchar, int thisblock); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
67 static int nv_screengo(oparg_T *oap, int dir, long dist); |
7 | 68 #ifdef FEAT_MOUSE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 static void nv_mousescroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
70 static void nv_mouse(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
71 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
72 static void nv_scroll_line(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
73 static void nv_zet(cmdarg_T *cap); |
7 | 74 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
75 static void nv_ver_scrollbar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
76 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 77 #endif |
685 | 78 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
79 static void nv_tabline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
80 static void nv_tabmenu(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
81 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
82 static void nv_exmode(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
83 static void nv_colon(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
84 static void nv_ctrlg(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
85 static void nv_ctrlh(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
86 static void nv_clear(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
87 static void nv_ctrlo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
88 static void nv_hat(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
89 static void nv_Zet(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
90 static void nv_ident(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
91 static void nv_tagpop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 static void nv_scroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
93 static void nv_right(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 static void nv_left(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 static void nv_up(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
96 static void nv_down(cmdarg_T *cap); |
7 | 97 #ifdef FEAT_SEARCHPATH |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
98 static void nv_gotofile(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
99 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
100 static void nv_end(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
101 static void nv_dollar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
102 static void nv_search(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
103 static void nv_next(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
104 static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
105 static void nv_csearch(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
106 static void nv_brackets(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
107 static void nv_percent(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
108 static void nv_brace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
109 static void nv_mark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
110 static void nv_findpar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
111 static void nv_undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
112 static void nv_kundo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
113 static void nv_Replace(cmdarg_T *cap); |
7 | 114 #ifdef FEAT_VREPLACE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
115 static void nv_vreplace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
116 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
117 static void v_swap_corners(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
118 static void nv_replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
119 static void n_swapchar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
120 static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
121 static void v_visop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
122 static void nv_subst(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
123 static void nv_abbrev(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
124 static void nv_optrans(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
125 static void nv_gomark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
126 static void nv_pcmark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
127 static void nv_regname(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
128 static void nv_visual(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
129 static void n_start_visual_mode(int c); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
130 static void nv_window(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
131 static void nv_suspend(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
132 static void nv_g_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
133 static void n_opencmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
134 static void nv_dot(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
135 static void nv_redo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
136 static void nv_Undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
137 static void nv_tilde(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
138 static void nv_operator(cmdarg_T *cap); |
1490 | 139 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
140 static void set_op_var(int optype); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
141 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
142 static void nv_lineop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
143 static void nv_home(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
144 static void nv_pipe(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
145 static void nv_bck_word(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
146 static void nv_wordcmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
147 static void nv_beginline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
148 static void adjust_cursor(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
149 static void adjust_for_sel(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
150 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
151 static void nv_select(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
152 static void nv_goto(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
153 static void nv_normal(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
154 static void nv_esc(cmdarg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
155 static void nv_edit(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
156 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 157 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
158 static void nv_object(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
159 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
160 static void nv_record(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
161 static void nv_at(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
162 static void nv_halfpage(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
163 static void nv_join(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
164 static void nv_put(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
165 static void nv_open(cmdarg_T *cap); |
7 | 166 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
167 static void nv_nbcmd(cmdarg_T *cap); |
7 | 168 #endif |
169 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
170 static void nv_drop(cmdarg_T *cap); |
7 | 171 #endif |
203 | 172 #ifdef FEAT_AUTOCMD |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
173 static void nv_cursorhold(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
174 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
175 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 176 |
1728 | 177 static char *e_noident = N_("E349: No identifier under cursor"); |
178 | |
7 | 179 /* |
180 * Function to be called for a Normal or Visual mode command. | |
181 * The argument is a cmdarg_T. | |
182 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
183 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 184 |
185 /* Values for cmd_flags. */ | |
186 #define NV_NCH 0x01 /* may need to get a second char */ | |
187 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
188 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
189 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
190 | |
191 #define NV_SS 0x10 /* may start selection */ | |
192 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
193 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
194 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
195 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
196 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
197 | |
198 /* | |
199 * Generally speaking, every Normal mode command should either clear any | |
200 * pending operator (with *clearop*()), or set the motion type variable | |
201 * oap->motion_type. | |
202 * | |
203 * When a cursor motion command is made, it is marked as being a character or | |
204 * line oriented motion. Then, if an operator is in effect, the operation | |
205 * becomes character or line oriented accordingly. | |
206 */ | |
207 | |
208 /* | |
209 * This table contains one entry for every Normal or Visual mode command. | |
210 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
211 * It is faster when all keys from zero to '~' are present. | |
212 */ | |
213 static const struct nv_cmd | |
214 { | |
215 int cmd_char; /* (first) command character */ | |
216 nv_func_T cmd_func; /* function for this command */ | |
217 short_u cmd_flags; /* NV_ flags */ | |
218 short cmd_arg; /* value for ca.arg */ | |
219 } nv_cmds[] = | |
220 { | |
221 {NUL, nv_error, 0, 0}, | |
222 {Ctrl_A, nv_addsub, 0, 0}, | |
223 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
224 {Ctrl_C, nv_esc, 0, TRUE}, | |
225 {Ctrl_D, nv_halfpage, 0, 0}, | |
226 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
227 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
228 {Ctrl_G, nv_ctrlg, 0, 0}, | |
229 {Ctrl_H, nv_ctrlh, 0, 0}, | |
230 {Ctrl_I, nv_pcmark, 0, 0}, | |
231 {NL, nv_down, 0, FALSE}, | |
232 {Ctrl_K, nv_error, 0, 0}, | |
233 {Ctrl_L, nv_clear, 0, 0}, | |
376 | 234 {Ctrl_M, nv_down, 0, TRUE}, |
7 | 235 {Ctrl_N, nv_down, NV_STS, FALSE}, |
236 {Ctrl_O, nv_ctrlo, 0, 0}, | |
237 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 238 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 239 {Ctrl_R, nv_redo, 0, 0}, |
240 {Ctrl_S, nv_ignore, 0, 0}, | |
241 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
242 {Ctrl_U, nv_halfpage, 0, 0}, | |
243 {Ctrl_V, nv_visual, 0, FALSE}, | |
244 {'V', nv_visual, 0, FALSE}, | |
245 {'v', nv_visual, 0, FALSE}, | |
246 {Ctrl_W, nv_window, 0, 0}, | |
247 {Ctrl_X, nv_addsub, 0, 0}, | |
248 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
249 {Ctrl_Z, nv_suspend, 0, 0}, | |
250 {ESC, nv_esc, 0, FALSE}, | |
251 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
252 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
253 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
254 {Ctrl__, nv_error, 0, 0}, | |
255 {' ', nv_right, 0, 0}, | |
256 {'!', nv_operator, 0, 0}, | |
257 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
258 {'#', nv_ident, 0, 0}, | |
259 {'$', nv_dollar, 0, 0}, | |
260 {'%', nv_percent, 0, 0}, | |
261 {'&', nv_optrans, 0, 0}, | |
262 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
263 {'(', nv_brace, 0, BACKWARD}, | |
264 {')', nv_brace, 0, FORWARD}, | |
265 {'*', nv_ident, 0, 0}, | |
266 {'+', nv_down, 0, TRUE}, | |
267 {',', nv_csearch, 0, TRUE}, | |
268 {'-', nv_up, 0, TRUE}, | |
269 {'.', nv_dot, NV_KEEPREG, 0}, | |
270 {'/', nv_search, 0, FALSE}, | |
271 {'0', nv_beginline, 0, 0}, | |
272 {'1', nv_ignore, 0, 0}, | |
273 {'2', nv_ignore, 0, 0}, | |
274 {'3', nv_ignore, 0, 0}, | |
275 {'4', nv_ignore, 0, 0}, | |
276 {'5', nv_ignore, 0, 0}, | |
277 {'6', nv_ignore, 0, 0}, | |
278 {'7', nv_ignore, 0, 0}, | |
279 {'8', nv_ignore, 0, 0}, | |
280 {'9', nv_ignore, 0, 0}, | |
281 {':', nv_colon, 0, 0}, | |
282 {';', nv_csearch, 0, FALSE}, | |
283 {'<', nv_operator, NV_RL, 0}, | |
284 {'=', nv_operator, 0, 0}, | |
285 {'>', nv_operator, NV_RL, 0}, | |
286 {'?', nv_search, 0, FALSE}, | |
287 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
288 {'A', nv_edit, 0, 0}, | |
289 {'B', nv_bck_word, 0, 1}, | |
290 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
291 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
292 {'E', nv_wordcmd, 0, TRUE}, | |
293 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
294 {'G', nv_goto, 0, TRUE}, | |
295 {'H', nv_scroll, 0, 0}, | |
296 {'I', nv_edit, 0, 0}, | |
297 {'J', nv_join, 0, 0}, | |
298 {'K', nv_ident, 0, 0}, | |
299 {'L', nv_scroll, 0, 0}, | |
300 {'M', nv_scroll, 0, 0}, | |
301 {'N', nv_next, 0, SEARCH_REV}, | |
302 {'O', nv_open, 0, 0}, | |
303 {'P', nv_put, 0, 0}, | |
304 {'Q', nv_exmode, NV_NCW, 0}, | |
305 {'R', nv_Replace, 0, FALSE}, | |
306 {'S', nv_subst, NV_KEEPREG, 0}, | |
307 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
308 {'U', nv_Undo, 0, 0}, | |
309 {'W', nv_wordcmd, 0, TRUE}, | |
310 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
311 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
312 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
313 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
314 {'\\', nv_error, 0, 0}, | |
315 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
316 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
317 {'_', nv_lineop, 0, 0}, | |
318 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
319 {'a', nv_edit, NV_NCH, 0}, | |
320 {'b', nv_bck_word, 0, 0}, | |
321 {'c', nv_operator, 0, 0}, | |
322 {'d', nv_operator, 0, 0}, | |
323 {'e', nv_wordcmd, 0, FALSE}, | |
324 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
325 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
326 {'h', nv_left, NV_RL, 0}, | |
327 {'i', nv_edit, NV_NCH, 0}, | |
328 {'j', nv_down, 0, FALSE}, | |
329 {'k', nv_up, 0, FALSE}, | |
330 {'l', nv_right, NV_RL, 0}, | |
331 {'m', nv_mark, NV_NCH_NOP, 0}, | |
332 {'n', nv_next, 0, 0}, | |
333 {'o', nv_open, 0, 0}, | |
334 {'p', nv_put, 0, 0}, | |
335 {'q', nv_record, NV_NCH, 0}, | |
336 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
337 {'s', nv_subst, NV_KEEPREG, 0}, | |
338 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
339 {'u', nv_undo, 0, 0}, | |
340 {'w', nv_wordcmd, 0, FALSE}, | |
341 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
342 {'y', nv_operator, 0, 0}, | |
343 {'z', nv_zet, NV_NCH_ALW, 0}, | |
344 {'{', nv_findpar, 0, BACKWARD}, | |
345 {'|', nv_pipe, 0, 0}, | |
346 {'}', nv_findpar, 0, FORWARD}, | |
347 {'~', nv_tilde, 0, 0}, | |
348 | |
349 /* pound sign */ | |
350 {POUND, nv_ident, 0, 0}, | |
351 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
352 {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
353 {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
354 {K_MOUSELEFT, nv_mousescroll, 0, MSCR_LEFT}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
355 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 356 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
357 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
358 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
359 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
360 {K_LEFTRELEASE_NM, nv_mouse, 0, 0}, | |
361 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, | |
362 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
363 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
364 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
365 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
366 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
367 {K_X1MOUSE, nv_mouse, 0, 0}, | |
368 {K_X1DRAG, nv_mouse, 0, 0}, | |
369 {K_X1RELEASE, nv_mouse, 0, 0}, | |
370 {K_X2MOUSE, nv_mouse, 0, 0}, | |
371 {K_X2DRAG, nv_mouse, 0, 0}, | |
372 {K_X2RELEASE, nv_mouse, 0, 0}, | |
373 #endif | |
819 | 374 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 375 {K_NOP, nv_nop, 0, 0}, |
7 | 376 {K_INS, nv_edit, 0, 0}, |
377 {K_KINS, nv_edit, 0, 0}, | |
378 {K_BS, nv_ctrlh, 0, 0}, | |
379 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
380 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
381 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
382 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
383 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
384 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
385 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
386 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
387 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
388 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
389 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
390 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
391 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
392 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
393 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
394 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
395 {K_S_END, nv_end, NV_SS, FALSE}, | |
396 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
397 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
398 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
399 {K_S_HOME, nv_home, NV_SS, 0}, | |
400 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
401 {K_DEL, nv_abbrev, 0, 0}, | |
402 {K_KDEL, nv_abbrev, 0, 0}, | |
403 {K_UNDO, nv_kundo, 0, 0}, | |
404 {K_HELP, nv_help, NV_NCW, 0}, | |
405 {K_F1, nv_help, NV_NCW, 0}, | |
406 {K_XF1, nv_help, NV_NCW, 0}, | |
407 {K_SELECT, nv_select, 0, 0}, | |
408 #ifdef FEAT_GUI | |
409 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
410 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
411 #endif | |
685 | 412 #ifdef FEAT_GUI_TABLINE |
413 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 414 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 415 #endif |
7 | 416 #ifdef FEAT_FKMAP |
9399
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
417 {K_F8, farsi_f8, 0, 0}, |
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
418 {K_F9, farsi_f9, 0, 0}, |
7 | 419 #endif |
420 #ifdef FEAT_NETBEANS_INTG | |
421 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
422 #endif | |
423 #ifdef FEAT_DND | |
424 {K_DROP, nv_drop, NV_STS, 0}, | |
425 #endif | |
203 | 426 #ifdef FEAT_AUTOCMD |
819 | 427 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
203 | 428 #endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
429 {K_PS, nv_edit, 0, 0}, |
7 | 430 }; |
431 | |
432 /* Number of commands in nv_cmds[]. */ | |
433 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
434 | |
435 /* Sorted index of commands in nv_cmds[]. */ | |
436 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
437 | |
438 /* The highest index for which | |
439 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
440 static int nv_max_linear; | |
441 | |
442 /* | |
443 * Compare functions for qsort() below, that checks the command character | |
444 * through the index in nv_cmd_idx[]. | |
445 */ | |
446 static int | |
447 #ifdef __BORLANDC__ | |
448 _RTLENTRYF | |
449 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
450 nv_compare(const void *s1, const void *s2) |
7 | 451 { |
452 int c1, c2; | |
453 | |
454 /* The commands are sorted on absolute value. */ | |
455 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
456 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
457 if (c1 < 0) | |
458 c1 = -c1; | |
459 if (c2 < 0) | |
460 c2 = -c2; | |
461 return c1 - c2; | |
462 } | |
463 | |
464 /* | |
465 * Initialize the nv_cmd_idx[] table. | |
466 */ | |
467 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
468 init_normal_cmds(void) |
7 | 469 { |
470 int i; | |
471 | |
472 /* Fill the index table with a one to one relation. */ | |
1877 | 473 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 474 nv_cmd_idx[i] = i; |
475 | |
476 /* Sort the commands by the command character. */ | |
477 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
478 | |
479 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 480 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 481 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
482 break; | |
483 nv_max_linear = i - 1; | |
484 } | |
485 | |
486 /* | |
487 * Search for a command in the commands table. | |
488 * Returns -1 for invalid command. | |
489 */ | |
490 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
491 find_command(int cmdchar) |
7 | 492 { |
493 int i; | |
494 int idx; | |
495 int top, bot; | |
496 int c; | |
497 | |
498 #ifdef FEAT_MBYTE | |
499 /* A multi-byte character is never a command. */ | |
500 if (cmdchar >= 0x100) | |
501 return -1; | |
502 #endif | |
503 | |
504 /* We use the absolute value of the character. Special keys have a | |
505 * negative value, but are sorted on their absolute value. */ | |
506 if (cmdchar < 0) | |
507 cmdchar = -cmdchar; | |
508 | |
509 /* If the character is in the first part: The character is the index into | |
510 * nv_cmd_idx[]. */ | |
511 if (cmdchar <= nv_max_linear) | |
512 return nv_cmd_idx[cmdchar]; | |
513 | |
514 /* Perform a binary search. */ | |
515 bot = nv_max_linear + 1; | |
516 top = NV_CMDS_SIZE - 1; | |
517 idx = -1; | |
518 while (bot <= top) | |
519 { | |
520 i = (top + bot) / 2; | |
521 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
522 if (c < 0) | |
523 c = -c; | |
524 if (cmdchar == c) | |
525 { | |
526 idx = nv_cmd_idx[i]; | |
527 break; | |
528 } | |
529 if (cmdchar > c) | |
530 bot = i + 1; | |
531 else | |
532 top = i - 1; | |
533 } | |
534 return idx; | |
535 } | |
536 | |
537 /* | |
538 * Execute a command in Normal mode. | |
539 */ | |
540 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
541 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
542 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
543 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 544 { |
545 cmdarg_T ca; /* command arguments */ | |
546 int c; | |
547 int ctrl_w = FALSE; /* got CTRL-W command */ | |
548 int old_col = curwin->w_curswant; | |
549 #ifdef FEAT_CMDL_INFO | |
550 int need_flushbuf; /* need to call out_flush() */ | |
551 #endif | |
552 pos_T old_pos; /* cursor position before command */ | |
553 int mapped_len; | |
554 static int old_mapped_len = 0; | |
555 int idx; | |
1751 | 556 #ifdef FEAT_EVAL |
557 int set_prevcount = FALSE; | |
558 #endif | |
7 | 559 |
560 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
561 ca.oap = oap; | |
1692 | 562 |
563 /* Use a count remembered from before entering an operator. After typing | |
564 * "3d" we return from normal_cmd() and come back here, the "3" is | |
565 * remembered in "opcount". */ | |
7 | 566 ca.opcount = opcount; |
567 | |
568 /* | |
569 * If there is an operator pending, then the command we take this time | |
570 * will terminate it. Finish_op tells us to finish the operation before | |
571 * returning this time (unless the operation was cancelled). | |
572 */ | |
573 #ifdef CURSOR_SHAPE | |
574 c = finish_op; | |
575 #endif | |
576 finish_op = (oap->op_type != OP_NOP); | |
577 #ifdef CURSOR_SHAPE | |
578 if (finish_op != c) | |
579 { | |
580 ui_cursor_shape(); /* may show different cursor shape */ | |
581 # ifdef FEAT_MOUSESHAPE | |
582 update_mouseshape(-1); | |
583 # endif | |
584 } | |
585 #endif | |
586 | |
1692 | 587 /* When not finishing an operator and no register name typed, reset the |
588 * count. */ | |
7 | 589 if (!finish_op && !oap->regname) |
1751 | 590 { |
7 | 591 ca.opcount = 0; |
1751 | 592 #ifdef FEAT_EVAL |
593 set_prevcount = TRUE; | |
594 #endif | |
595 } | |
7 | 596 |
1692 | 597 #ifdef FEAT_AUTOCMD |
598 /* Restore counts from before receiving K_CURSORHOLD. This means after | |
599 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
600 * "3 * 2". */ | |
601 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
602 { | |
603 ca.opcount = oap->prev_opcount; | |
604 ca.count0 = oap->prev_count0; | |
605 oap->prev_opcount = 0; | |
606 oap->prev_count0 = 0; | |
607 } | |
608 #endif | |
609 | |
7 | 610 mapped_len = typebuf_maplen(); |
611 | |
612 State = NORMAL_BUSY; | |
613 #ifdef USE_ON_FLY_SCROLL | |
614 dont_scroll = FALSE; /* allow scrolling here */ | |
615 #endif | |
616 | |
2667 | 617 #ifdef FEAT_EVAL |
618 /* Set v:count here, when called from main() and not a stuffed | |
619 * command, so that v:count can be used in an expression mapping | |
5649 | 620 * when there is no count. Do set it for redo. */ |
621 if (toplevel && readbuf1_empty()) | |
2667 | 622 set_vcount_ca(&ca, &set_prevcount); |
623 #endif | |
624 | |
7 | 625 /* |
626 * Get the command character from the user. | |
627 */ | |
628 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
629 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 630 |
631 /* | |
632 * If a mapping was started in Visual or Select mode, remember the length | |
633 * of the mapping. This is used below to not return to Insert mode for as | |
634 * long as the mapping is being executed. | |
635 */ | |
636 if (restart_edit == 0) | |
637 old_mapped_len = 0; | |
638 else if (old_mapped_len | |
819 | 639 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 640 old_mapped_len = typebuf_maplen(); |
641 | |
642 if (c == NUL) | |
643 c = K_ZERO; | |
644 | |
645 /* | |
646 * In Select mode, typed text replaces the selection. | |
647 */ | |
648 if (VIsual_active | |
649 && VIsual_select | |
650 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
651 { | |
275 | 652 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
653 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
654 * restart automatically. | |
1051 | 655 * Insert the typed character in the typeahead buffer, so that it can |
656 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 657 ins_char_typebuf(c); |
275 | 658 if (restart_edit != 0) |
659 c = 'd'; | |
660 else | |
661 c = 'c'; | |
695 | 662 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 663 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 664 } |
665 | |
666 #ifdef FEAT_CMDL_INFO | |
667 need_flushbuf = add_to_showcmd(c); | |
668 #endif | |
669 | |
670 getcount: | |
671 if (!(VIsual_active && VIsual_select)) | |
672 { | |
673 /* | |
674 * Handle a count before a command and compute ca.count0. | |
675 * Note that '0' is a command and not the start of a count, but it's | |
676 * part of a count after other digits. | |
677 */ | |
678 while ( (c >= '1' && c <= '9') | |
679 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
680 { | |
681 if (c == K_DEL || c == K_KDEL) | |
682 { | |
683 ca.count0 /= 10; | |
684 #ifdef FEAT_CMDL_INFO | |
685 del_from_showcmd(4); /* delete the digit and ~@% */ | |
686 #endif | |
687 } | |
688 else | |
689 ca.count0 = ca.count0 * 10 + (c - '0'); | |
690 if (ca.count0 < 0) /* got too large! */ | |
691 ca.count0 = 999999999L; | |
1425 | 692 #ifdef FEAT_EVAL |
693 /* Set v:count here, when called from main() and not a stuffed | |
694 * command, so that v:count can be used in an expression mapping | |
5649 | 695 * right after the count. Do set it for redo. */ |
696 if (toplevel && readbuf1_empty()) | |
2667 | 697 set_vcount_ca(&ca, &set_prevcount); |
1425 | 698 #endif |
7 | 699 if (ctrl_w) |
700 { | |
701 ++no_mapping; | |
702 ++allow_keys; /* no mapping for nchar, but keys */ | |
703 } | |
704 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 705 c = plain_vgetc(); |
7 | 706 LANGMAP_ADJUST(c, TRUE); |
707 --no_zero_mapping; | |
708 if (ctrl_w) | |
709 { | |
710 --no_mapping; | |
711 --allow_keys; | |
712 } | |
713 #ifdef FEAT_CMDL_INFO | |
714 need_flushbuf |= add_to_showcmd(c); | |
715 #endif | |
716 } | |
717 | |
718 /* | |
719 * If we got CTRL-W there may be a/another count | |
720 */ | |
721 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
722 { | |
723 ctrl_w = TRUE; | |
724 ca.opcount = ca.count0; /* remember first count */ | |
725 ca.count0 = 0; | |
726 ++no_mapping; | |
727 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 728 c = plain_vgetc(); /* get next character */ |
7 | 729 LANGMAP_ADJUST(c, TRUE); |
730 --no_mapping; | |
731 --allow_keys; | |
732 #ifdef FEAT_CMDL_INFO | |
733 need_flushbuf |= add_to_showcmd(c); | |
734 #endif | |
735 goto getcount; /* jump back */ | |
736 } | |
737 } | |
738 | |
1692 | 739 #ifdef FEAT_AUTOCMD |
740 if (c == K_CURSORHOLD) | |
741 { | |
742 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
743 * the same when coming back here after handling K_CURSORHOLD. */ | |
744 oap->prev_opcount = ca.opcount; | |
745 oap->prev_count0 = ca.count0; | |
746 } | |
747 else | |
748 #endif | |
749 if (ca.opcount != 0) | |
750 { | |
751 /* | |
752 * If we're in the middle of an operator (including after entering a | |
753 * yank buffer with '"') AND we had a count before the operator, then | |
754 * that count overrides the current value of ca.count0. | |
755 * What this means effectively, is that commands like "3dw" get turned | |
756 * into "d3w" which makes things fall into place pretty neatly. | |
757 * If you give a count before AND after the operator, they are | |
758 * multiplied. | |
759 */ | |
7 | 760 if (ca.count0) |
761 ca.count0 *= ca.opcount; | |
762 else | |
763 ca.count0 = ca.opcount; | |
764 } | |
765 | |
766 /* | |
767 * Always remember the count. It will be set to zero (on the next call, | |
768 * above) when there is no pending operator. | |
769 * When called from main(), save the count for use by the "count" built-in | |
770 * variable. | |
771 */ | |
772 ca.opcount = ca.count0; | |
773 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
774 | |
775 #ifdef FEAT_EVAL | |
776 /* | |
777 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 778 * Do set it for redo. |
7 | 779 */ |
5649 | 780 if (toplevel && readbuf1_empty()) |
1751 | 781 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 782 #endif |
783 | |
784 /* | |
785 * Find the command character in the table of commands. | |
786 * For CTRL-W we already got nchar when looking for a count. | |
787 */ | |
788 if (ctrl_w) | |
789 { | |
790 ca.nchar = c; | |
791 ca.cmdchar = Ctrl_W; | |
792 } | |
793 else | |
794 ca.cmdchar = c; | |
795 idx = find_command(ca.cmdchar); | |
796 if (idx < 0) | |
797 { | |
798 /* Not a known command: beep. */ | |
799 clearopbeep(oap); | |
800 goto normal_end; | |
801 } | |
631 | 802 |
633 | 803 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 804 { |
5848 | 805 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 806 clearopbeep(oap); |
633 | 807 text_locked_msg(); |
7 | 808 goto normal_end; |
809 } | |
819 | 810 #ifdef FEAT_AUTOCMD |
811 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) | |
812 goto normal_end; | |
813 #endif | |
7 | 814 |
815 /* | |
816 * In Visual/Select mode, a few keys are handled in a special way. | |
817 */ | |
818 if (VIsual_active) | |
819 { | |
820 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
821 if (km_stopsel | |
822 && (nv_cmds[idx].cmd_flags & NV_STS) | |
823 && !(mod_mask & MOD_MASK_SHIFT)) | |
824 { | |
825 end_visual_mode(); | |
826 redraw_curbuf_later(INVERTED); | |
827 } | |
828 | |
829 /* Keys that work different when 'keymodel' contains "startsel" */ | |
830 if (km_startsel) | |
831 { | |
832 if (nv_cmds[idx].cmd_flags & NV_SS) | |
833 { | |
834 unshift_special(&ca); | |
835 idx = find_command(ca.cmdchar); | |
840 | 836 if (idx < 0) |
837 { | |
838 /* Just in case */ | |
839 clearopbeep(oap); | |
840 goto normal_end; | |
841 } | |
7 | 842 } |
843 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
844 && (mod_mask & MOD_MASK_SHIFT)) | |
845 { | |
846 mod_mask &= ~MOD_MASK_SHIFT; | |
847 } | |
848 } | |
849 } | |
850 | |
851 #ifdef FEAT_RIGHTLEFT | |
852 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
853 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
854 { | |
855 /* Invert horizontal movements and operations. Only when typed by the | |
856 * user directly, not when the result of a mapping or "x" translated | |
857 * to "dl". */ | |
858 switch (ca.cmdchar) | |
859 { | |
860 case 'l': ca.cmdchar = 'h'; break; | |
861 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
862 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
863 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
864 case 'h': ca.cmdchar = 'l'; break; | |
865 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
866 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
867 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
868 case '>': ca.cmdchar = '<'; break; | |
869 case '<': ca.cmdchar = '>'; break; | |
870 } | |
871 idx = find_command(ca.cmdchar); | |
872 } | |
873 #endif | |
874 | |
875 /* | |
876 * Get an additional character if we need one. | |
877 */ | |
878 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
879 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
880 && oap->op_type == OP_NOP) | |
881 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
882 || (ca.cmdchar == 'q' | |
883 && oap->op_type == OP_NOP | |
884 && !Recording | |
885 && !Exec_reg) | |
886 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') | |
5735 | 887 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 888 { |
889 int *cp; | |
890 int repl = FALSE; /* get character for replace mode */ | |
891 int lit = FALSE; /* get extra character literally */ | |
892 int langmap_active = FALSE; /* using :lmap mappings */ | |
893 int lang; /* getting a text character */ | |
894 #ifdef USE_IM_CONTROL | |
895 int save_smd; /* saved value of p_smd */ | |
896 #endif | |
897 | |
898 ++no_mapping; | |
899 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 900 #ifdef FEAT_AUTOCMD |
901 /* Don't generate a CursorHold event here, most commands can't handle | |
902 * it, e.g., nv_replace(), nv_csearch(). */ | |
903 did_cursorhold = TRUE; | |
904 #endif | |
7 | 905 if (ca.cmdchar == 'g') |
906 { | |
907 /* | |
908 * For 'g' get the next character now, so that we can check for | |
909 * "gr", "g'" and "g`". | |
910 */ | |
1389 | 911 ca.nchar = plain_vgetc(); |
7 | 912 LANGMAP_ADJUST(ca.nchar, TRUE); |
913 #ifdef FEAT_CMDL_INFO | |
914 need_flushbuf |= add_to_showcmd(ca.nchar); | |
915 #endif | |
916 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 917 || ca.nchar == Ctrl_BSL) |
7 | 918 { |
919 cp = &ca.extra_char; /* need to get a third character */ | |
920 if (ca.nchar != 'r') | |
921 lit = TRUE; /* get it literally */ | |
922 else | |
923 repl = TRUE; /* get it in replace mode */ | |
924 } | |
925 else | |
926 cp = NULL; /* no third character needed */ | |
927 } | |
928 else | |
929 { | |
930 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
931 repl = TRUE; | |
932 cp = &ca.nchar; | |
933 } | |
934 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
935 | |
936 /* | |
937 * Get a second or third character. | |
938 */ | |
939 if (cp != NULL) | |
940 { | |
941 #ifdef CURSOR_SHAPE | |
942 if (repl) | |
943 { | |
944 State = REPLACE; /* pretend Replace mode */ | |
945 ui_cursor_shape(); /* show different cursor shape */ | |
946 } | |
947 #endif | |
948 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
949 { | |
950 /* Allow mappings defined with ":lmap". */ | |
951 --no_mapping; | |
952 --allow_keys; | |
953 if (repl) | |
954 State = LREPLACE; | |
955 else | |
956 State = LANGMAP; | |
957 langmap_active = TRUE; | |
958 } | |
959 #ifdef USE_IM_CONTROL | |
960 save_smd = p_smd; | |
961 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
962 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
963 im_set_active(TRUE); | |
964 #endif | |
965 | |
1389 | 966 *cp = plain_vgetc(); |
7 | 967 |
968 if (langmap_active) | |
969 { | |
970 /* Undo the decrement done above */ | |
971 ++no_mapping; | |
972 ++allow_keys; | |
973 State = NORMAL_BUSY; | |
974 } | |
975 #ifdef USE_IM_CONTROL | |
976 if (lang) | |
977 { | |
978 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
979 im_save_status(&curbuf->b_p_iminsert); | |
980 im_set_active(FALSE); | |
981 } | |
982 p_smd = save_smd; | |
983 #endif | |
984 #ifdef CURSOR_SHAPE | |
985 State = NORMAL_BUSY; | |
986 #endif | |
987 #ifdef FEAT_CMDL_INFO | |
988 need_flushbuf |= add_to_showcmd(*cp); | |
989 #endif | |
990 | |
991 if (!lit) | |
992 { | |
993 #ifdef FEAT_DIGRAPHS | |
994 /* Typing CTRL-K gets a digraph. */ | |
995 if (*cp == Ctrl_K | |
996 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
997 || cp == &ca.extra_char) | |
998 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
999 { | |
1000 c = get_digraph(FALSE); | |
1001 if (c > 0) | |
1002 { | |
1003 *cp = c; | |
1004 # ifdef FEAT_CMDL_INFO | |
1005 /* Guessing how to update showcmd here... */ | |
1006 del_from_showcmd(3); | |
1007 need_flushbuf |= add_to_showcmd(*cp); | |
1008 # endif | |
1009 } | |
1010 } | |
1011 #endif | |
1012 | |
1013 /* adjust chars > 127, except after "tTfFr" commands */ | |
1014 LANGMAP_ADJUST(*cp, !lang); | |
1015 #ifdef FEAT_RIGHTLEFT | |
1016 /* adjust Hebrew mapped char */ | |
1017 if (p_hkmap && lang && KeyTyped) | |
1018 *cp = hkmap(*cp); | |
1019 # ifdef FEAT_FKMAP | |
1020 /* adjust Farsi mapped char */ | |
1021 if (p_fkmap && lang && KeyTyped) | |
1022 *cp = fkmap(*cp); | |
1023 # endif | |
1024 #endif | |
1025 } | |
1026 | |
1027 /* | |
1028 * When the next character is CTRL-\ a following CTRL-N means the | |
1029 * command is aborted and we go to Normal mode. | |
1030 */ | |
1031 if (cp == &ca.extra_char | |
1032 && ca.nchar == Ctrl_BSL | |
1033 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
1034 { | |
1035 ca.cmdchar = Ctrl_BSL; | |
1036 ca.nchar = ca.extra_char; | |
1037 idx = find_command(ca.cmdchar); | |
1038 } | |
3908 | 1039 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1040 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1041 else if (*cp == Ctrl_BSL) |
1042 { | |
1043 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1044 | |
1045 /* There is a busy wait here when typing "f<C-\>" and then | |
1046 * something different from CTRL-N. Can't be avoided. */ | |
1047 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1048 { | |
1049 do_sleep(towait > 50L ? 50L : towait); | |
1050 towait -= 50L; | |
1051 } | |
1052 if (c > 0) | |
1053 { | |
1389 | 1054 c = plain_vgetc(); |
7 | 1055 if (c != Ctrl_N && c != Ctrl_G) |
1056 vungetc(c); | |
1057 else | |
1058 { | |
1059 ca.cmdchar = Ctrl_BSL; | |
1060 ca.nchar = c; | |
1061 idx = find_command(ca.cmdchar); | |
1062 } | |
1063 } | |
1064 } | |
1065 | |
1066 #ifdef FEAT_MBYTE | |
1067 /* When getting a text character and the next character is a | |
1068 * multi-byte character, it could be a composing character. | |
6071 | 1069 * However, don't wait for it to arrive. Also, do enable mapping, |
1070 * because if it's put back with vungetc() it's too late to apply | |
1071 * mapping. */ | |
1072 --no_mapping; | |
7 | 1073 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1074 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1075 { | |
1389 | 1076 c = plain_vgetc(); |
7 | 1077 if (!utf_iscomposing(c)) |
1078 { | |
1079 vungetc(c); /* it wasn't, put it back */ | |
1080 break; | |
1081 } | |
1082 else if (ca.ncharC1 == 0) | |
1083 ca.ncharC1 = c; | |
1084 else | |
1085 ca.ncharC2 = c; | |
1086 } | |
6071 | 1087 ++no_mapping; |
7 | 1088 #endif |
1089 } | |
1090 --no_mapping; | |
1091 --allow_keys; | |
1092 } | |
1093 | |
1094 #ifdef FEAT_CMDL_INFO | |
1095 /* | |
1096 * Flush the showcmd characters onto the screen so we can see them while | |
1097 * the command is being executed. Only do this when the shown command was | |
1098 * actually displayed, otherwise this will slow down a lot when executing | |
1099 * mappings. | |
1100 */ | |
1101 if (need_flushbuf) | |
1102 out_flush(); | |
1103 #endif | |
203 | 1104 #ifdef FEAT_AUTOCMD |
1727 | 1105 if (ca.cmdchar != K_IGNORE) |
1106 did_cursorhold = FALSE; | |
203 | 1107 #endif |
7 | 1108 |
1109 State = NORMAL; | |
1110 | |
1111 if (ca.nchar == ESC) | |
1112 { | |
1113 clearop(oap); | |
1114 if (restart_edit == 0 && goto_im()) | |
1115 restart_edit = 'a'; | |
1116 goto normal_end; | |
1117 } | |
1118 | |
24 | 1119 if (ca.cmdchar != K_IGNORE) |
1120 { | |
1121 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1122 msg_col = 0; | |
1123 } | |
7 | 1124 |
1125 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1126 | |
1127 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1128 * mode. */ | |
1129 if (!VIsual_active && km_startsel) | |
1130 { | |
1131 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1132 { | |
1133 start_selection(); | |
1134 unshift_special(&ca); | |
1135 idx = find_command(ca.cmdchar); | |
1136 } | |
1137 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1138 && (mod_mask & MOD_MASK_SHIFT)) | |
1139 { | |
1140 start_selection(); | |
1141 mod_mask &= ~MOD_MASK_SHIFT; | |
1142 } | |
1143 } | |
1144 | |
1145 /* | |
1146 * Execute the command! | |
1147 * Call the command function found in the commands table. | |
1148 */ | |
1149 ca.arg = nv_cmds[idx].cmd_arg; | |
1150 (nv_cmds[idx].cmd_func)(&ca); | |
1151 | |
1152 /* | |
1153 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1154 * need it later. | |
1155 */ | |
1156 if (!finish_op | |
1157 && !oap->op_type | |
1158 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1159 { | |
1160 clearop(oap); | |
1161 #ifdef FEAT_EVAL | |
2821 | 1162 { |
1163 int regname = 0; | |
2829 | 1164 |
2821 | 1165 /* Adjust the register according to 'clipboard', so that when |
1166 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1167 # ifdef FEAT_CLIPBOARD |
2821 | 1168 adjust_clip_reg(®name); |
2829 | 1169 # endif |
2821 | 1170 set_reg_var(regname); |
1171 } | |
7 | 1172 #endif |
1173 } | |
1174 | |
570 | 1175 /* Get the length of mapped chars again after typing a count, second |
36 | 1176 * character or "z333<cr>". */ |
1177 if (old_mapped_len > 0) | |
1178 old_mapped_len = typebuf_maplen(); | |
1179 | |
7 | 1180 /* |
1181 * If an operation is pending, handle it... | |
1182 */ | |
1183 do_pending_operator(&ca, old_col, FALSE); | |
1184 | |
1185 /* | |
1186 * Wait for a moment when a message is displayed that will be overwritten | |
1187 * by the mode message. | |
1188 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1189 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1190 * In Visual mode, it's more important to keep the Visual area updated | |
1191 * than keeping a message (e.g. from a /pat search). | |
1192 * Only do this if the command was typed, not from a mapping. | |
1193 * Don't wait when emsg_silent is non-zero. | |
1194 * Also wait a bit after an error message, e.g. for "^O:". | |
1195 * Don't redraw the screen, it would remove the message. | |
1196 */ | |
1197 if ( ((p_smd | |
641 | 1198 && msg_silent == 0 |
7 | 1199 && (restart_edit != 0 |
1200 || (VIsual_active | |
1201 && old_pos.lnum == curwin->w_cursor.lnum | |
1202 && old_pos.col == curwin->w_cursor.col) | |
1203 ) | |
1204 && (clear_cmdline | |
1205 || redraw_cmdline) | |
1206 && (msg_didout || (msg_didany && msg_scroll)) | |
1207 && !msg_nowait | |
1208 && KeyTyped) | |
1209 || (restart_edit != 0 | |
1210 && !VIsual_active | |
1211 && (msg_scroll | |
1212 || emsg_on_display))) | |
1213 && oap->regname == 0 | |
1214 && !(ca.retval & CA_COMMAND_BUSY) | |
1215 && stuff_empty() | |
1216 && typebuf_typed() | |
1217 && emsg_silent == 0 | |
1218 && !did_wait_return | |
1219 && oap->op_type == OP_NOP) | |
1220 { | |
1221 int save_State = State; | |
1222 | |
1223 /* Draw the cursor with the right shape here */ | |
1224 if (restart_edit != 0) | |
1225 State = INSERT; | |
1226 | |
1227 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1228 * delay */ | |
1229 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1230 { | |
1231 char_u *kmsg; | |
1232 | |
1233 kmsg = keep_msg; | |
1234 keep_msg = NULL; | |
1235 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1236 update_screen(0); | |
1237 /* now reset it, otherwise it's put in the history again */ | |
1238 keep_msg = kmsg; | |
1239 msg_attr(kmsg, keep_msg_attr); | |
1240 vim_free(kmsg); | |
1241 } | |
1242 setcursor(); | |
1243 cursor_on(); | |
1244 out_flush(); | |
1245 if (msg_scroll || emsg_on_display) | |
1246 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1247 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1248 State = save_State; | |
1249 | |
1250 msg_scroll = FALSE; | |
1251 emsg_on_display = FALSE; | |
1252 } | |
1253 | |
1254 /* | |
1255 * Finish up after executing a Normal mode command. | |
1256 */ | |
1257 normal_end: | |
1258 | |
1259 msg_nowait = FALSE; | |
1260 | |
1261 /* Reset finish_op, in case it was set */ | |
1262 #ifdef CURSOR_SHAPE | |
1263 c = finish_op; | |
1264 #endif | |
1265 finish_op = FALSE; | |
1266 #ifdef CURSOR_SHAPE | |
1267 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1268 * mode or did a replace command. */ | |
1269 if (c || ca.cmdchar == 'r') | |
1270 { | |
1271 ui_cursor_shape(); /* may show different cursor shape */ | |
1272 # ifdef FEAT_MOUSESHAPE | |
1273 update_mouseshape(-1); | |
1274 # endif | |
1275 } | |
1276 #endif | |
1277 | |
1278 #ifdef FEAT_CMDL_INFO | |
1692 | 1279 if (oap->op_type == OP_NOP && oap->regname == 0 |
1280 # ifdef FEAT_AUTOCMD | |
1281 && ca.cmdchar != K_CURSORHOLD | |
1282 # endif | |
1283 ) | |
7 | 1284 clear_showcmd(); |
1285 #endif | |
1286 | |
1287 checkpcmark(); /* check if we moved since setting pcmark */ | |
1288 vim_free(ca.searchbuf); | |
1289 | |
1290 #ifdef FEAT_MBYTE | |
1291 if (has_mbyte) | |
1292 mb_adjust_cursor(); | |
1293 #endif | |
1294 | |
1295 #ifdef FEAT_SCROLLBIND | |
1296 if (curwin->w_p_scb && toplevel) | |
1297 { | |
1298 validate_cursor(); /* may need to update w_leftcol */ | |
1299 do_check_scrollbind(TRUE); | |
1300 } | |
1301 #endif | |
1302 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1303 #ifdef FEAT_CURSORBIND |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1304 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1305 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1306 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
|
1307 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1308 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1309 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1310 |
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
|
1311 #ifdef FEAT_TERMINAL |
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1312 /* don't go to Insert mode from Terminal-Job mode */ |
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
|
1313 if (term_use_loop()) |
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
|
1314 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
|
1315 #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
|
1316 |
7 | 1317 /* |
1318 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1319 * if still inside a mapping that started in Visual mode). | |
1320 * May switch from Visual to Select mode after CTRL-O command. | |
1321 */ | |
1322 if ( oap->op_type == OP_NOP | |
1323 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1324 || restart_VIsual_select == 1) | |
1325 && !(ca.retval & CA_COMMAND_BUSY) | |
1326 && stuff_empty() | |
1327 && oap->regname == 0) | |
1328 { | |
1329 if (restart_VIsual_select == 1) | |
1330 { | |
1331 VIsual_select = TRUE; | |
1332 showmode(); | |
1333 restart_VIsual_select = 0; | |
1334 } | |
5735 | 1335 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1336 (void)edit(restart_edit, FALSE, 1L); |
1337 } | |
1338 | |
1339 if (restart_VIsual_select == 2) | |
1340 restart_VIsual_select = 1; | |
1341 | |
1342 /* Save count before an operator for next time. */ | |
1343 opcount = ca.opcount; | |
1344 } | |
1345 | |
2667 | 1346 #ifdef FEAT_EVAL |
1347 /* | |
1348 * Set v:count and v:count1 according to "cap". | |
1349 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1350 */ | |
1351 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1352 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1353 { |
1354 long count = cap->count0; | |
1355 | |
1356 /* multiply with cap->opcount the same way as above */ | |
1357 if (cap->opcount != 0) | |
1358 count = cap->opcount * (count == 0 ? 1 : count); | |
1359 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1360 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1361 } | |
1362 #endif | |
1363 | |
7 | 1364 /* |
1365 * Handle an operator after visual mode or when the movement is finished | |
1366 */ | |
1367 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1368 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1369 { |
1370 oparg_T *oap = cap->oap; | |
1371 pos_T old_cursor; | |
1372 int empty_region_error; | |
1373 int restart_edit_save; | |
6266 | 1374 #ifdef FEAT_LINEBREAK |
1375 int lbr_saved = curwin->w_p_lbr; | |
1376 #endif | |
7 | 1377 |
1378 /* The visual area is remembered for redo */ | |
1379 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1380 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1381 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1382 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
|
1383 static int redo_VIsual_arg; /* extra argument */ |
5735 | 1384 #ifdef FEAT_VIRTUALEDIT |
7 | 1385 int include_line_break = FALSE; |
1386 #endif | |
1387 | |
1388 #if defined(FEAT_CLIPBOARD) | |
1389 /* | |
1390 * Yank the visual area into the GUI selection register before we operate | |
1391 * on it and lose it forever. | |
1392 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1393 * This could call do_pending_operator() recursively, but that's OK | |
1394 * because gui_yank will be TRUE for the nested call. | |
1395 */ | |
3674 | 1396 if ((clip_star.available || clip_plus.available) |
7 | 1397 && oap->op_type != OP_NOP |
1398 && !gui_yank | |
1399 && VIsual_active | |
1400 && !redo_VIsual_busy | |
1401 && oap->regname == 0) | |
1402 clip_auto_select(); | |
1403 #endif | |
1404 old_cursor = curwin->w_cursor; | |
1405 | |
1406 /* | |
1407 * If an operation is pending, handle it... | |
1408 */ | |
5735 | 1409 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1410 { | |
6497 | 1411 #ifdef FEAT_LINEBREAK |
1412 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1413 if (curwin->w_p_lbr) |
1414 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1415 curwin->w_p_lbr = FALSE; |
1416 #endif | |
7 | 1417 oap->is_VIsual = VIsual_active; |
1418 if (oap->motion_force == 'V') | |
1419 oap->motion_type = MLINE; | |
1420 else if (oap->motion_force == 'v') | |
1421 { | |
1422 /* If the motion was linewise, "inclusive" will not have been set. | |
1423 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1424 if (oap->motion_type == MLINE) | |
1425 oap->inclusive = FALSE; | |
1426 /* If the motion already was characterwise, toggle "inclusive" */ | |
1427 else if (oap->motion_type == MCHAR) | |
1428 oap->inclusive = !oap->inclusive; | |
1429 oap->motion_type = MCHAR; | |
1430 } | |
1431 else if (oap->motion_force == Ctrl_V) | |
1432 { | |
1433 /* Change line- or characterwise motion into Visual block mode. */ | |
1434 VIsual_active = TRUE; | |
1435 VIsual = oap->start; | |
1436 VIsual_mode = Ctrl_V; | |
1437 VIsual_select = FALSE; | |
1438 VIsual_reselect = FALSE; | |
1439 } | |
1440 | |
4337 | 1441 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1442 /* Never redo "zf" (define fold). */ | |
7 | 1443 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
4337 | 1444 && ((!VIsual_active || oap->motion_force) |
1445 /* Also redo Operator-pending Visual mode mappings */ | |
1446 || (VIsual_active && cap->cmdchar == ':' | |
1447 && oap->op_type != OP_COLON)) | |
164 | 1448 && cap->cmdchar != 'D' |
7 | 1449 #ifdef FEAT_FOLDING |
1450 && oap->op_type != OP_FOLD | |
1451 && oap->op_type != OP_FOLDOPEN | |
1452 && oap->op_type != OP_FOLDOPENREC | |
1453 && oap->op_type != OP_FOLDCLOSE | |
1454 && oap->op_type != OP_FOLDCLOSEREC | |
1455 && oap->op_type != OP_FOLDDEL | |
1456 && oap->op_type != OP_FOLDDELREC | |
1457 #endif | |
1458 ) | |
1459 { | |
1460 prep_redo(oap->regname, cap->count0, | |
1461 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1462 oap->motion_force, cap->cmdchar, cap->nchar); | |
1463 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1464 { | |
1465 /* | |
1466 * If 'cpoptions' does not contain 'r', insert the search | |
1467 * pattern to really repeat the same command. | |
1468 */ | |
1469 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1470 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1471 AppendToRedobuff(NL_STR); |
1472 } | |
1473 else if (cap->cmdchar == ':') | |
1474 { | |
1475 /* do_cmdline() has stored the first typed line in | |
1476 * "repeat_cmdline". When several lines are typed repeating | |
1477 * won't be possible. */ | |
1478 if (repeat_cmdline == NULL) | |
1479 ResetRedobuff(); | |
1480 else | |
1481 { | |
620 | 1482 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1483 AppendToRedobuff(NL_STR); |
1484 vim_free(repeat_cmdline); | |
1485 repeat_cmdline = NULL; | |
1486 } | |
1487 } | |
1488 } | |
1489 | |
1490 if (redo_VIsual_busy) | |
1491 { | |
3125 | 1492 /* Redo of an operation on a Visual area. Use the same size from |
1493 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1494 oap->start = curwin->w_cursor; |
1495 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1496 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1497 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1498 VIsual_mode = redo_VIsual_mode; | |
3125 | 1499 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1500 { |
3125 | 1501 if (VIsual_mode == 'v') |
1502 { | |
1503 if (redo_VIsual_line_count <= 1) | |
1504 { | |
1505 validate_virtcol(); | |
1506 curwin->w_curswant = | |
1507 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1508 } | |
1509 else | |
1510 curwin->w_curswant = redo_VIsual_vcol; | |
1511 } | |
7 | 1512 else |
3125 | 1513 { |
1514 curwin->w_curswant = MAXCOL; | |
1515 } | |
1516 coladvance(curwin->w_curswant); | |
7 | 1517 } |
1518 cap->count0 = redo_VIsual_count; | |
1519 if (redo_VIsual_count != 0) | |
1520 cap->count1 = redo_VIsual_count; | |
1521 else | |
1522 cap->count1 = 1; | |
1523 } | |
1524 else if (VIsual_active) | |
1525 { | |
999 | 1526 if (!gui_yank) |
1527 { | |
1528 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1529 curbuf->b_visual.vi_start = VIsual; | |
1530 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1531 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1532 if (VIsual_mode_orig != NUL) |
1533 { | |
1534 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1535 VIsual_mode_orig = NUL; | |
1536 } | |
999 | 1537 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1538 # ifdef FEAT_EVAL |
999 | 1539 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1540 # endif |
999 | 1541 } |
7 | 1542 |
1543 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1544 * characterwise selection. |
1545 * Special case: gH<Del> deletes the last line. */ | |
1546 if (VIsual_select && VIsual_mode == 'V' | |
1547 && cap->oap->op_type != OP_DELETE) | |
7 | 1548 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1549 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1550 { |
1551 VIsual.col = 0; | |
1552 curwin->w_cursor.col = | |
1553 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1554 } | |
1555 else | |
1556 { | |
1557 curwin->w_cursor.col = 0; | |
1558 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1559 } | |
1560 VIsual_mode = 'v'; | |
1561 } | |
1562 /* If 'selection' is "exclusive", backup one character for | |
1563 * charwise selections. */ | |
1564 else if (VIsual_mode == 'v') | |
1565 { | |
1566 # ifdef FEAT_VIRTUALEDIT | |
1567 include_line_break = | |
1568 # endif | |
1569 unadjust_for_sel(); | |
1570 } | |
1571 | |
1572 oap->start = VIsual; | |
1573 if (VIsual_mode == 'V') | |
1574 oap->start.col = 0; | |
1575 } | |
1576 | |
1577 /* | |
1578 * Set oap->start to the first position of the operated text, oap->end | |
1579 * to the end of the operated text. w_cursor is equal to oap->start. | |
1580 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1581 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1582 { |
1583 #ifdef FEAT_FOLDING | |
1584 /* Include folded lines completely. */ | |
1585 if (!VIsual_active) | |
1586 { | |
1587 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1588 oap->start.col = 0; | |
1589 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1590 &curwin->w_cursor.lnum)) | |
1591 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1592 } | |
1593 #endif | |
1594 oap->end = curwin->w_cursor; | |
1595 curwin->w_cursor = oap->start; | |
1596 | |
1597 /* w_virtcol may have been updated; if the cursor goes back to its | |
1598 * previous position w_virtcol becomes invalid and isn't updated | |
1599 * automatically. */ | |
1600 curwin->w_valid &= ~VALID_VIRTCOL; | |
1601 } | |
1602 else | |
1603 { | |
1604 #ifdef FEAT_FOLDING | |
1605 /* Include folded lines completely. */ | |
1606 if (!VIsual_active && oap->motion_type == MLINE) | |
1607 { | |
1608 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1609 NULL)) | |
1610 curwin->w_cursor.col = 0; | |
1611 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1612 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1613 } | |
1614 #endif | |
1615 oap->end = oap->start; | |
1616 oap->start = curwin->w_cursor; | |
1617 } | |
1618 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1619 /* 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
|
1620 check_pos(curwin->w_buffer, &oap->end); |
7 | 1621 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1622 | |
1623 #ifdef FEAT_VIRTUALEDIT | |
1624 /* Set "virtual_op" before resetting VIsual_active. */ | |
1625 virtual_op = virtual_active(); | |
1626 #endif | |
1627 | |
1628 if (VIsual_active || redo_VIsual_busy) | |
1629 { | |
6866 | 1630 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1631 |
1632 if (!redo_VIsual_busy && !gui_yank) | |
1633 { | |
1634 /* | |
1635 * Prepare to reselect and redo Visual: this is based on the | |
1636 * size of the Visual text | |
1637 */ | |
1638 resel_VIsual_mode = VIsual_mode; | |
1639 if (curwin->w_curswant == MAXCOL) | |
3125 | 1640 resel_VIsual_vcol = MAXCOL; |
7 | 1641 else |
3125 | 1642 { |
1643 if (VIsual_mode != Ctrl_V) | |
1644 getvvcol(curwin, &(oap->end), | |
1645 NULL, NULL, &oap->end_vcol); | |
1646 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1647 { | |
1648 if (VIsual_mode != Ctrl_V) | |
1649 getvvcol(curwin, &(oap->start), | |
1650 &oap->start_vcol, NULL, NULL); | |
1651 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1652 } | |
1653 else | |
1654 resel_VIsual_vcol = oap->end_vcol; | |
1655 } | |
7 | 1656 resel_VIsual_line_count = oap->line_count; |
1657 } | |
1658 | |
1659 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
1660 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | |
1661 && oap->op_type != OP_COLON | |
1662 #ifdef FEAT_FOLDING | |
1663 && oap->op_type != OP_FOLD | |
1664 && oap->op_type != OP_FOLDOPEN | |
1665 && oap->op_type != OP_FOLDOPENREC | |
1666 && oap->op_type != OP_FOLDCLOSE | |
1667 && oap->op_type != OP_FOLDCLOSEREC | |
1668 && oap->op_type != OP_FOLDDEL | |
1669 && oap->op_type != OP_FOLDDELREC | |
1670 #endif | |
1671 && oap->motion_force == NUL | |
1672 ) | |
1673 { | |
1674 /* Prepare for redoing. Only use the nchar field for "r", | |
1675 * otherwise it might be the second char of the operator. */ | |
3701 | 1676 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1677 || cap->nchar == 'N')) | |
5523 | 1678 prep_redo(oap->regname, cap->count0, |
1679 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1680 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1681 else if (cap->cmdchar != ':') |
3701 | 1682 prep_redo(oap->regname, 0L, NUL, 'v', |
1683 get_op_char(oap->op_type), | |
1684 get_extra_op_char(oap->op_type), | |
1685 oap->op_type == OP_REPLACE | |
1686 ? cap->nchar : NUL); | |
7 | 1687 if (!redo_VIsual_busy) |
1688 { | |
1689 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1690 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1691 redo_VIsual_line_count = resel_VIsual_line_count; |
1692 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1693 redo_VIsual_arg = cap->arg; |
7 | 1694 } |
1695 } | |
1696 | |
1697 /* | |
1698 * oap->inclusive defaults to TRUE. | |
1699 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1700 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1701 */ | |
1702 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1703 oap->inclusive = TRUE; | |
1704 if (VIsual_mode == 'V') | |
1705 oap->motion_type = MLINE; | |
1706 else | |
1707 { | |
1708 oap->motion_type = MCHAR; | |
1709 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1710 #ifdef FEAT_VIRTUALEDIT |
7 | 1711 && (include_line_break || !virtual_op) |
5735 | 1712 #endif |
7 | 1713 ) |
1714 { | |
1715 oap->inclusive = FALSE; | |
1716 /* Try to include the newline, unless it's an operator | |
2957 | 1717 * that works on lines only. */ |
6826 | 1718 if (*p_sel != 'o' |
1719 && !op_on_lines(oap->op_type) | |
1720 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1721 { |
6826 | 1722 ++oap->end.lnum; |
1723 oap->end.col = 0; | |
5735 | 1724 #ifdef FEAT_VIRTUALEDIT |
6826 | 1725 oap->end.coladd = 0; |
1726 #endif | |
1727 ++oap->line_count; | |
7 | 1728 } |
1729 } | |
1730 } | |
1731 | |
1732 redo_VIsual_busy = FALSE; | |
592 | 1733 |
7 | 1734 /* |
1735 * Switch Visual off now, so screen updating does | |
1736 * not show inverted text when the screen is redrawn. | |
1737 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1738 * no screen redraw, so it is done here to remove the inverted | |
1739 * part. | |
1740 */ | |
1741 if (!gui_yank) | |
1742 { | |
1743 VIsual_active = FALSE; | |
5735 | 1744 #ifdef FEAT_MOUSE |
7 | 1745 setmouse(); |
1746 mouse_dragging = 0; | |
5735 | 1747 #endif |
6979 | 1748 may_clear_cmdline(); |
7 | 1749 if ((oap->op_type == OP_YANK |
1750 || oap->op_type == OP_COLON | |
592 | 1751 || oap->op_type == OP_FUNCTION |
7 | 1752 || oap->op_type == OP_FILTER) |
1753 && oap->motion_force == NUL) | |
6497 | 1754 { |
1755 #ifdef FEAT_LINEBREAK | |
1756 /* make sure redrawing is correct */ | |
1757 curwin->w_p_lbr = lbr_saved; | |
1758 #endif | |
7 | 1759 redraw_curbuf_later(INVERTED); |
6497 | 1760 } |
7 | 1761 } |
1762 } | |
1763 | |
1764 #ifdef FEAT_MBYTE | |
1765 /* Include the trailing byte of a multi-byte char. */ | |
1766 if (has_mbyte && oap->inclusive) | |
1767 { | |
1768 int l; | |
1769 | |
474 | 1770 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1771 if (l > 1) |
1772 oap->end.col += l - 1; | |
1773 } | |
1774 #endif | |
1775 curwin->w_set_curswant = TRUE; | |
1776 | |
1777 /* | |
1778 * oap->empty is set when start and end are the same. The inclusive | |
1779 * flag affects this too, unless yanking and the end is on a NUL. | |
1780 */ | |
1781 oap->empty = (oap->motion_type == MCHAR | |
1782 && (!oap->inclusive | |
1783 || (oap->op_type == OP_YANK | |
1784 && 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
|
1785 && EQUAL_POS(oap->start, oap->end) |
7 | 1786 #ifdef FEAT_VIRTUALEDIT |
1787 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1788 #endif | |
1789 ); | |
1790 /* | |
1791 * For delete, change and yank, it's an error to operate on an | |
1792 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1793 */ | |
1794 empty_region_error = (oap->empty | |
1795 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1796 | |
1797 /* Force a redraw when operating on an empty Visual region, when | |
1798 * 'modifiable is off or creating a fold. */ | |
1799 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1800 #ifdef FEAT_FOLDING |
7 | 1801 || oap->op_type == OP_FOLD |
5735 | 1802 #endif |
7 | 1803 )) |
6497 | 1804 { |
1805 #ifdef FEAT_LINEBREAK | |
1806 curwin->w_p_lbr = lbr_saved; | |
1807 #endif | |
7 | 1808 redraw_curbuf_later(INVERTED); |
6497 | 1809 } |
7 | 1810 |
1811 /* | |
1812 * If the end of an operator is in column one while oap->motion_type | |
1813 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1814 * character in the previous line. If op_start is on or before the | |
1815 * first non-blank in the line, the operator becomes linewise | |
1816 * (strange, but that's the way vi does it). | |
1817 */ | |
1818 if ( oap->motion_type == MCHAR | |
1819 && oap->inclusive == FALSE | |
1820 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1821 && oap->end.col == 0 | |
1822 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1823 && !oap->block_mode |
7 | 1824 && oap->line_count > 1) |
1825 { | |
1826 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1827 --oap->line_count; | |
1828 --oap->end.lnum; | |
1829 if (inindent(0)) | |
1830 oap->motion_type = MLINE; | |
1831 else | |
1832 { | |
1833 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1834 if (oap->end.col) | |
1835 { | |
1836 --oap->end.col; | |
1837 oap->inclusive = TRUE; | |
1838 } | |
1839 } | |
1840 } | |
1841 else | |
1842 oap->end_adjusted = FALSE; | |
1843 | |
1844 switch (oap->op_type) | |
1845 { | |
1846 case OP_LSHIFT: | |
1847 case OP_RSHIFT: | |
5735 | 1848 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1849 auto_format(FALSE, TRUE); |
1850 break; | |
1851 | |
1852 case OP_JOIN_NS: | |
1853 case OP_JOIN: | |
1854 if (oap->line_count < 2) | |
1855 oap->line_count = 2; | |
1856 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1857 curbuf->b_ml.ml_line_count) | |
1858 beep_flush(); | |
1859 else | |
1860 { | |
5735 | 1861 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1862 TRUE, TRUE, TRUE); |
7 | 1863 auto_format(FALSE, TRUE); |
1864 } | |
1865 break; | |
1866 | |
1867 case OP_DELETE: | |
1868 VIsual_reselect = FALSE; /* don't reselect now */ | |
1869 if (empty_region_error) | |
3324 | 1870 { |
6949 | 1871 vim_beep(BO_OPER); |
3324 | 1872 CancelRedo(); |
1873 } | |
7 | 1874 else |
1875 { | |
1876 (void)op_delete(oap); | |
1877 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1878 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1879 auto_format(FALSE, TRUE); | |
1880 } | |
1881 break; | |
1882 | |
1883 case OP_YANK: | |
1884 if (empty_region_error) | |
1885 { | |
1886 if (!gui_yank) | |
3324 | 1887 { |
6949 | 1888 vim_beep(BO_OPER); |
3324 | 1889 CancelRedo(); |
1890 } | |
7 | 1891 } |
1892 else | |
6497 | 1893 { |
1894 #ifdef FEAT_LINEBREAK | |
1895 curwin->w_p_lbr = lbr_saved; | |
1896 #endif | |
7 | 1897 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1898 } |
7 | 1899 check_cursor_col(); |
1900 break; | |
1901 | |
1902 case OP_CHANGE: | |
1903 VIsual_reselect = FALSE; /* don't reselect now */ | |
1904 if (empty_region_error) | |
3324 | 1905 { |
6949 | 1906 vim_beep(BO_OPER); |
3324 | 1907 CancelRedo(); |
1908 } | |
7 | 1909 else |
1910 { | |
1911 /* This is a new edit command, not a restart. Need to | |
1912 * remember it to make 'insertmode' work with mappings for | |
1913 * Visual mode. But do this only once and not when typed and | |
1914 * 'insertmode' isn't set. */ | |
1915 if (p_im || !KeyTyped) | |
1916 restart_edit_save = restart_edit; | |
1917 else | |
1918 restart_edit_save = 0; | |
1919 restart_edit = 0; | |
6497 | 1920 #ifdef FEAT_LINEBREAK |
1921 /* Restore linebreak, so that when the user edits it looks as | |
1922 * before. */ | |
6866 | 1923 if (curwin->w_p_lbr != lbr_saved) |
1924 { | |
1925 curwin->w_p_lbr = lbr_saved; | |
1926 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1927 } | |
6497 | 1928 #endif |
7 | 1929 /* Reset finish_op now, don't want it set inside edit(). */ |
1930 finish_op = FALSE; | |
1931 if (op_change(oap)) /* will call edit() */ | |
1932 cap->retval |= CA_COMMAND_BUSY; | |
1933 if (restart_edit == 0) | |
1934 restart_edit = restart_edit_save; | |
1935 } | |
1936 break; | |
1937 | |
1938 case OP_FILTER: | |
1939 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1940 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1941 else | |
1942 bangredo = TRUE; /* do_bang() will put cmd in redo buffer */ | |
1943 | |
1944 case OP_INDENT: | |
1945 case OP_COLON: | |
1946 | |
1947 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1948 /* | |
1949 * If 'equalprg' is empty, do the indenting internally. | |
1950 */ | |
1951 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1952 { | |
1953 # ifdef FEAT_LISP | |
1954 if (curbuf->b_p_lisp) | |
1955 { | |
1956 op_reindent(oap, get_lisp_indent); | |
1957 break; | |
1958 } | |
1959 # endif | |
1960 # ifdef FEAT_CINDENT | |
1961 op_reindent(oap, | |
1962 # ifdef FEAT_EVAL | |
1963 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1964 # endif | |
1965 get_c_indent); | |
1966 break; | |
1967 # endif | |
1968 } | |
1969 #endif | |
1970 | |
1971 op_colon(oap); | |
1972 break; | |
1973 | |
1974 case OP_TILDE: | |
1975 case OP_UPPER: | |
1976 case OP_LOWER: | |
1977 case OP_ROT13: | |
1978 if (empty_region_error) | |
3324 | 1979 { |
6949 | 1980 vim_beep(BO_OPER); |
3324 | 1981 CancelRedo(); |
1982 } | |
7 | 1983 else |
1984 op_tilde(oap); | |
1985 check_cursor_col(); | |
1986 break; | |
1987 | |
1988 case OP_FORMAT: | |
667 | 1989 #if defined(FEAT_EVAL) |
1990 if (*curbuf->b_p_fex != NUL) | |
1991 op_formatexpr(oap); /* use expression */ | |
1992 else | |
1993 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1994 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1995 op_colon(oap); /* use external command */ |
1996 else | |
1997 op_format(oap, FALSE); /* use internal function */ | |
1998 break; | |
1999 | |
2000 case OP_FORMAT2: | |
2001 op_format(oap, TRUE); /* use internal function */ | |
2002 break; | |
2003 | |
592 | 2004 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2005 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2006 /* 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
|
2007 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2008 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2009 #endif |
592 | 2010 op_function(oap); /* call 'operatorfunc' */ |
2011 break; | |
2012 | |
7 | 2013 case OP_INSERT: |
2014 case OP_APPEND: | |
2015 VIsual_reselect = FALSE; /* don't reselect now */ | |
2016 #ifdef FEAT_VISUALEXTRA | |
2017 if (empty_region_error) | |
3324 | 2018 { |
6949 | 2019 vim_beep(BO_OPER); |
3324 | 2020 CancelRedo(); |
2021 } | |
7 | 2022 else |
2023 { | |
2024 /* This is a new edit command, not a restart. Need to | |
2025 * remember it to make 'insertmode' work with mappings for | |
2026 * Visual mode. But do this only once. */ | |
2027 restart_edit_save = restart_edit; | |
2028 restart_edit = 0; | |
6497 | 2029 #ifdef FEAT_LINEBREAK |
2030 /* Restore linebreak, so that when the user edits it looks as | |
2031 * before. */ | |
6866 | 2032 if (curwin->w_p_lbr != lbr_saved) |
2033 { | |
2034 curwin->w_p_lbr = lbr_saved; | |
2035 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2036 } | |
6497 | 2037 #endif |
7 | 2038 op_insert(oap, cap->count1); |
6497 | 2039 #ifdef FEAT_LINEBREAK |
2040 /* Reset linebreak, so that formatting works correctly. */ | |
2041 curwin->w_p_lbr = FALSE; | |
2042 #endif | |
7 | 2043 |
2044 /* TODO: when inserting in several lines, should format all | |
2045 * the lines. */ | |
2046 auto_format(FALSE, TRUE); | |
2047 | |
2048 if (restart_edit == 0) | |
2049 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
|
2050 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
|
2051 cap->retval |= CA_COMMAND_BUSY; |
7 | 2052 } |
2053 #else | |
6949 | 2054 vim_beep(BO_OPER); |
7 | 2055 #endif |
2056 break; | |
2057 | |
2058 case OP_REPLACE: | |
2059 VIsual_reselect = FALSE; /* don't reselect now */ | |
2060 #ifdef FEAT_VISUALEXTRA | |
2061 if (empty_region_error) | |
2062 #endif | |
3324 | 2063 { |
6949 | 2064 vim_beep(BO_OPER); |
3324 | 2065 CancelRedo(); |
2066 } | |
7 | 2067 #ifdef FEAT_VISUALEXTRA |
2068 else | |
6497 | 2069 { |
6866 | 2070 # ifdef FEAT_LINEBREAK |
6497 | 2071 /* Restore linebreak, so that when the user edits it looks as |
2072 * before. */ | |
6866 | 2073 if (curwin->w_p_lbr != lbr_saved) |
2074 { | |
2075 curwin->w_p_lbr = lbr_saved; | |
2076 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2077 } | |
2078 # endif | |
7 | 2079 op_replace(oap, cap->nchar); |
6497 | 2080 } |
7 | 2081 #endif |
2082 break; | |
2083 | |
2084 #ifdef FEAT_FOLDING | |
2085 case OP_FOLD: | |
2086 VIsual_reselect = FALSE; /* don't reselect now */ | |
2087 foldCreate(oap->start.lnum, oap->end.lnum); | |
2088 break; | |
2089 | |
2090 case OP_FOLDOPEN: | |
2091 case OP_FOLDOPENREC: | |
2092 case OP_FOLDCLOSE: | |
2093 case OP_FOLDCLOSEREC: | |
2094 VIsual_reselect = FALSE; /* don't reselect now */ | |
2095 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2096 oap->op_type == OP_FOLDOPEN | |
2097 || oap->op_type == OP_FOLDOPENREC, | |
2098 oap->op_type == OP_FOLDOPENREC | |
2099 || oap->op_type == OP_FOLDCLOSEREC, | |
2100 oap->is_VIsual); | |
2101 break; | |
2102 | |
2103 case OP_FOLDDEL: | |
2104 case OP_FOLDDELREC: | |
2105 VIsual_reselect = FALSE; /* don't reselect now */ | |
2106 deleteFold(oap->start.lnum, oap->end.lnum, | |
2107 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2108 break; | |
2109 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2110 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2111 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2112 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2113 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2114 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2115 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2116 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2117 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2118 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2119 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2120 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2121 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2122 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2123 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
|
2124 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2125 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2126 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2127 break; |
7 | 2128 default: |
2129 clearopbeep(oap); | |
2130 } | |
2131 #ifdef FEAT_VIRTUALEDIT | |
2132 virtual_op = MAYBE; | |
2133 #endif | |
2134 if (!gui_yank) | |
2135 { | |
2136 /* | |
2137 * if 'sol' not set, go back to old column for some commands | |
2138 */ | |
2139 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2140 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2141 || oap->op_type == OP_DELETE)) | |
6497 | 2142 { |
2143 #ifdef FEAT_LINEBREAK | |
2144 curwin->w_p_lbr = FALSE; | |
2145 #endif | |
7 | 2146 coladvance(curwin->w_curswant = old_col); |
6497 | 2147 } |
7 | 2148 } |
2149 else | |
2150 { | |
2151 curwin->w_cursor = old_cursor; | |
2152 } | |
2153 oap->block_mode = FALSE; | |
2154 clearop(oap); | |
2155 } | |
6266 | 2156 #ifdef FEAT_LINEBREAK |
2157 curwin->w_p_lbr = lbr_saved; | |
2158 #endif | |
7 | 2159 } |
2160 | |
2161 /* | |
2162 * Handle indent and format operators and visual mode ":". | |
2163 */ | |
2164 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2165 op_colon(oparg_T *oap) |
7 | 2166 { |
2167 stuffcharReadbuff(':'); | |
2168 if (oap->is_VIsual) | |
2169 stuffReadbuff((char_u *)"'<,'>"); | |
2170 else | |
2171 { | |
2172 /* | |
2173 * Make the range look nice, so it can be repeated. | |
2174 */ | |
2175 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2176 stuffcharReadbuff('.'); | |
2177 else | |
2178 stuffnumReadbuff((long)oap->start.lnum); | |
2179 if (oap->end.lnum != oap->start.lnum) | |
2180 { | |
2181 stuffcharReadbuff(','); | |
2182 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2183 stuffcharReadbuff('.'); | |
2184 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2185 stuffcharReadbuff('$'); | |
2186 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2187 { | |
2188 stuffReadbuff((char_u *)".+"); | |
2189 stuffnumReadbuff((long)oap->line_count - 1); | |
2190 } | |
2191 else | |
2192 stuffnumReadbuff((long)oap->end.lnum); | |
2193 } | |
2194 } | |
2195 if (oap->op_type != OP_COLON) | |
2196 stuffReadbuff((char_u *)"!"); | |
2197 if (oap->op_type == OP_INDENT) | |
2198 { | |
2199 #ifndef FEAT_CINDENT | |
2200 if (*get_equalprg() == NUL) | |
2201 stuffReadbuff((char_u *)"indent"); | |
2202 else | |
2203 #endif | |
2204 stuffReadbuff(get_equalprg()); | |
2205 stuffReadbuff((char_u *)"\n"); | |
2206 } | |
2207 else if (oap->op_type == OP_FORMAT) | |
2208 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2209 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
|
2210 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
|
2211 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
|
2212 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2213 else |
7 | 2214 stuffReadbuff((char_u *)"fmt"); |
216 | 2215 stuffReadbuff((char_u *)"\n']"); |
7 | 2216 } |
2217 | |
2218 /* | |
2219 * do_cmdline() does the rest | |
2220 */ | |
2221 } | |
2222 | |
592 | 2223 /* |
602 | 2224 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2225 */ |
690 | 2226 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2227 op_function(oparg_T *oap UNUSED) |
592 | 2228 { |
2229 #ifdef FEAT_EVAL | |
2230 char_u *(argv[1]); | |
4133 | 2231 # ifdef FEAT_VIRTUALEDIT |
3431 | 2232 int save_virtual_op = virtual_op; |
4133 | 2233 # endif |
592 | 2234 |
2235 if (*p_opfunc == NUL) | |
2236 EMSG(_("E774: 'operatorfunc' is empty")); | |
2237 else | |
2238 { | |
2239 /* Set '[ and '] marks to text to be operated on. */ | |
2240 curbuf->b_op_start = oap->start; | |
2241 curbuf->b_op_end = oap->end; | |
2242 if (oap->motion_type != MLINE && !oap->inclusive) | |
2243 /* Exclude the end position. */ | |
2244 decl(&curbuf->b_op_end); | |
2245 | |
2246 if (oap->block_mode) | |
2247 argv[0] = (char_u *)"block"; | |
2248 else if (oap->motion_type == MLINE) | |
2249 argv[0] = (char_u *)"line"; | |
2250 else | |
2251 argv[0] = (char_u *)"char"; | |
3431 | 2252 |
4133 | 2253 # ifdef FEAT_VIRTUALEDIT |
3431 | 2254 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2255 * function. */ | |
2256 virtual_op = MAYBE; | |
4133 | 2257 # endif |
3431 | 2258 |
592 | 2259 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
3431 | 2260 |
4133 | 2261 # ifdef FEAT_VIRTUALEDIT |
3431 | 2262 virtual_op = save_virtual_op; |
4133 | 2263 # endif |
592 | 2264 } |
2265 #else | |
2266 EMSG(_("E775: Eval feature not available")); | |
2267 #endif | |
2268 } | |
2269 | |
7 | 2270 #if defined(FEAT_MOUSE) || defined(PROTO) |
2271 /* | |
2272 * Do the appropriate action for the current mouse click in the current mode. | |
2273 * Not used for Command-line mode. | |
2274 * | |
2275 * Normal Mode: | |
2276 * event modi- position visual change action | |
2277 * fier cursor window | |
2278 * left press - yes end yes | |
2279 * left press C yes end yes "^]" (2) | |
2280 * left press S yes end yes "*" (2) | |
2281 * left drag - yes start if moved no | |
2282 * left relse - yes start if moved no | |
2283 * middle press - yes if not active no put register | |
2284 * middle press - yes if active no yank and put | |
2285 * right press - yes start or extend yes | |
2286 * right press S yes no change yes "#" (2) | |
2287 * right drag - yes extend no | |
2288 * right relse - yes extend no | |
2289 * | |
2290 * Insert or Replace Mode: | |
2291 * event modi- position visual change action | |
2292 * fier cursor window | |
2293 * left press - yes (cannot be active) yes | |
2294 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2295 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2296 * left drag - yes start or extend (1) no CTRL-O (1) | |
2297 * left relse - yes start or extend (1) no CTRL-O (1) | |
2298 * middle press - no (cannot be active) no put register | |
2299 * right press - yes start or extend yes CTRL-O | |
2300 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2301 * | |
2302 * (1) only if mouse pointer moved since press | |
2303 * (2) only if click is in same buffer | |
2304 * | |
2305 * Return TRUE if start_arrow() should be called for edit mode. | |
2306 */ | |
2307 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2308 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2309 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
|
2310 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2311 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
|
2312 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2313 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2314 { |
2315 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2316 static int got_click = FALSE; /* got a click some time back */ | |
2317 | |
2318 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2319 int is_click; /* If FALSE it's a drag or release event */ | |
2320 int is_drag; /* If TRUE it's a drag event */ | |
2321 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2322 pos_T start_visual; | |
2323 int moved; /* Has cursor moved? */ | |
2324 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
|
2325 #ifdef FEAT_WINDOWS |
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
|
2326 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2327 int in_sep_line; /* mouse in vertical separator line */ |
2328 #endif | |
2329 int c1, c2; | |
2330 #if defined(FEAT_FOLDING) | |
2331 pos_T save_cursor; | |
2332 #endif | |
2333 win_T *old_curwin = curwin; | |
2334 static pos_T orig_cursor; | |
2335 colnr_T leftcol, rightcol; | |
2336 pos_T end_visual; | |
2337 int diff; | |
2338 int old_active = VIsual_active; | |
2339 int old_mode = VIsual_mode; | |
2340 int regname; | |
2341 | |
2342 #if defined(FEAT_FOLDING) | |
2343 save_cursor = curwin->w_cursor; | |
2344 #endif | |
2345 | |
2346 /* | |
2347 * When GUI is active, always recognize mouse events, otherwise: | |
2348 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2349 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2350 * - For command line and insert mode 'mouse' is checked before calling | |
2351 * do_mouse(). | |
2352 */ | |
2353 if (do_always) | |
2354 do_always = FALSE; | |
2355 else | |
2356 #ifdef FEAT_GUI | |
2357 if (!gui.in_use) | |
2358 #endif | |
2359 { | |
2360 if (VIsual_active) | |
2361 { | |
2362 if (!mouse_has(MOUSE_VISUAL)) | |
2363 return FALSE; | |
2364 } | |
5735 | 2365 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2366 return FALSE; |
2367 } | |
2368 | |
4221 | 2369 for (;;) |
2370 { | |
2371 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2372 if (is_drag) | |
2373 { | |
2374 /* If the next character is the same mouse event then use that | |
2375 * one. Speeds up dragging the status line. */ | |
2376 if (vpeekc() != NUL) | |
2377 { | |
2378 int nc; | |
2379 int save_mouse_row = mouse_row; | |
2380 int save_mouse_col = mouse_col; | |
2381 | |
2382 /* Need to get the character, peeking doesn't get the actual | |
2383 * one. */ | |
2384 nc = safe_vgetc(); | |
2385 if (c == nc) | |
2386 continue; | |
2387 vungetc(nc); | |
2388 mouse_row = save_mouse_row; | |
2389 mouse_col = save_mouse_col; | |
2390 } | |
2391 } | |
2392 break; | |
2393 } | |
7 | 2394 |
2395 #ifdef FEAT_MOUSESHAPE | |
2396 /* May have stopped dragging the status or separator line. The pointer is | |
2397 * most likely still on the status or separator line. */ | |
2398 if (!is_drag && drag_status_line) | |
2399 { | |
2400 drag_status_line = FALSE; | |
2401 update_mouseshape(SHAPE_IDX_STATUS); | |
2402 } | |
2403 if (!is_drag && drag_sep_line) | |
2404 { | |
2405 drag_sep_line = FALSE; | |
2406 update_mouseshape(SHAPE_IDX_VSEP); | |
2407 } | |
2408 #endif | |
2409 | |
2410 /* | |
2411 * Ignore drag and release events if we didn't get a click. | |
2412 */ | |
2413 if (is_click) | |
2414 got_click = TRUE; | |
2415 else | |
2416 { | |
2417 if (!got_click) /* didn't get click, ignore */ | |
2418 return FALSE; | |
2419 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
|
2420 { |
7 | 2421 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
|
2422 #ifdef FEAT_WINDOWS |
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
|
2423 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
|
2424 { |
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
|
2425 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
|
2426 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
|
2427 } |
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 #endif |
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
|
2429 } |
7 | 2430 } |
2431 | |
2432 /* | |
2433 * CTRL right mouse button does CTRL-T | |
2434 */ | |
2435 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2436 { | |
2437 if (State & INSERT) | |
2438 stuffcharReadbuff(Ctrl_O); | |
2439 if (count > 1) | |
2440 stuffnumReadbuff(count); | |
2441 stuffcharReadbuff(Ctrl_T); | |
2442 got_click = FALSE; /* ignore drag&release now */ | |
2443 return FALSE; | |
2444 } | |
2445 | |
2446 /* | |
2447 * CTRL only works with left mouse button | |
2448 */ | |
2449 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2450 return FALSE; | |
2451 | |
2452 /* | |
2453 * When a modifier is down, ignore drag and release events, as well as | |
2454 * multiple clicks and the middle mouse button. | |
2455 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2456 */ | |
179 | 2457 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2458 | MOD_MASK_META)) | |
7 | 2459 && (!is_click |
2460 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2461 || which_button == MOUSE_MIDDLE) | |
598 | 2462 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2463 && mouse_model_popup() |
2464 && which_button == MOUSE_LEFT) | |
598 | 2465 && !((mod_mask & MOD_MASK_ALT) |
2466 && !mouse_model_popup() | |
2467 && which_button == MOUSE_RIGHT) | |
7 | 2468 ) |
2469 return FALSE; | |
2470 | |
2471 /* | |
2472 * If the button press was used as the movement command for an operator | |
2473 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2474 * drag/release events. | |
2475 */ | |
2476 if (!is_click && which_button == MOUSE_MIDDLE) | |
2477 return FALSE; | |
2478 | |
2479 if (oap != NULL) | |
2480 regname = oap->regname; | |
2481 else | |
2482 regname = 0; | |
2483 | |
2484 /* | |
2485 * Middle mouse button does a 'put' of the selected text | |
2486 */ | |
2487 if (which_button == MOUSE_MIDDLE) | |
2488 { | |
2489 if (State == NORMAL) | |
2490 { | |
2491 /* | |
2492 * If an operator was pending, we don't know what the user wanted | |
2493 * to do. Go back to normal mode: Clear the operator and beep(). | |
2494 */ | |
2495 if (oap != NULL && oap->op_type != OP_NOP) | |
2496 { | |
2497 clearopbeep(oap); | |
2498 return FALSE; | |
2499 } | |
2500 | |
2501 /* | |
2502 * If visual was active, yank the highlighted text and put it | |
2503 * before the mouse pointer position. | |
1016 | 2504 * In Select mode replace the highlighted text with the clipboard. |
7 | 2505 */ |
2506 if (VIsual_active) | |
2507 { | |
1016 | 2508 if (VIsual_select) |
2509 { | |
2510 stuffcharReadbuff(Ctrl_G); | |
1019 | 2511 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2512 } |
2513 else | |
2514 { | |
2515 stuffcharReadbuff('y'); | |
2516 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2517 } | |
7 | 2518 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2519 return FALSE; | |
2520 } | |
2521 /* | |
2522 * The rest is below jump_to_mouse() | |
2523 */ | |
2524 } | |
2525 | |
2526 else if ((State & INSERT) == 0) | |
2527 return FALSE; | |
2528 | |
2529 /* | |
2530 * Middle click in insert mode doesn't move the mouse, just insert the | |
2531 * contents of a register. '.' register is special, can't insert that | |
2532 * with do_put(). | |
2533 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2534 * happens for the GUI). | |
2535 */ | |
2536 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2537 { | |
2538 if (regname == '.') | |
2539 insert_reg(regname, TRUE); | |
2540 else | |
2541 { | |
2542 #ifdef FEAT_CLIPBOARD | |
2543 if (clip_star.available && regname == 0) | |
2544 regname = '*'; | |
2545 #endif | |
2546 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2547 insert_reg(regname, TRUE); | |
2548 else | |
2549 { | |
2550 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2551 | |
2552 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2553 AppendCharToRedobuff(Ctrl_R); | |
2554 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2555 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2556 } | |
2557 } | |
2558 return FALSE; | |
2559 } | |
2560 } | |
2561 | |
2562 /* When dragging or button-up stay in the same window. */ | |
2563 if (!is_click) | |
2564 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2565 | |
2566 start_visual.lnum = 0; | |
2567 | |
671 | 2568 #ifdef FEAT_WINDOWS |
2569 /* Check for clicking in the tab page line. */ | |
2570 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2571 { | |
1619 | 2572 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
|
2573 { |
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
|
2574 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
|
2575 { |
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
|
2576 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2577 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
|
2578 ? 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
|
2579 } |
1619 | 2580 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
|
2581 } |
671 | 2582 |
2583 /* click in a tab selects that tab page */ | |
2584 if (is_click | |
2585 # ifdef FEAT_CMDWIN | |
2586 && cmdwin_type == 0 | |
2587 # endif | |
681 | 2588 && mouse_col < Columns) |
2589 { | |
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
|
2590 in_tab_line = TRUE; |
681 | 2591 c1 = TabPageIdxs[mouse_col]; |
2592 if (c1 >= 0) | |
2593 { | |
682 | 2594 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2595 { | |
2596 /* double click opens new page */ | |
681 | 2597 end_visual_mode(); |
682 | 2598 tabpage_new(); |
2599 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2600 } | |
2601 else | |
2602 { | |
2603 /* Go to specified tab page, or next one if not clicking | |
2604 * on a label. */ | |
2605 goto_tabpage(c1); | |
2606 | |
2607 /* It's like clicking on the status line of a window. */ | |
2608 if (curwin != old_curwin) | |
2609 end_visual_mode(); | |
2610 } | |
681 | 2611 } |
2612 else if (c1 < 0) | |
2613 { | |
2614 tabpage_T *tp; | |
2615 | |
2616 /* Close the current or specified tab page. */ | |
2617 if (c1 == -999) | |
2618 tp = curtab; | |
2619 else | |
2620 tp = find_tabpage(-c1); | |
2621 if (tp == curtab) | |
2622 { | |
2623 if (first_tabpage->tp_next != NULL) | |
2624 tabpage_close(FALSE); | |
2625 } | |
2626 else if (tp != NULL) | |
2627 tabpage_close_other(tp, FALSE); | |
2628 } | |
2629 } | |
2630 return TRUE; | |
671 | 2631 } |
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
|
2632 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
|
2633 { |
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
|
2634 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
|
2635 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
|
2636 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
|
2637 } |
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 |
671 | 2639 #endif |
2640 | |
7 | 2641 /* |
2642 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2643 * right button up -> pop-up menu | |
2644 * shift-left button -> right button | |
598 | 2645 * alt-left button -> alt-right button |
7 | 2646 */ |
2647 if (mouse_model_popup()) | |
2648 { | |
2649 if (which_button == MOUSE_RIGHT | |
2650 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2651 { | |
2652 /* | |
2653 * NOTE: Ignore right button down and drag mouse events. | |
2654 * Windows only shows the popup menu on the button up event. | |
2655 */ | |
936 | 2656 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
2657 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) | |
7 | 2658 if (!is_click) |
2659 return FALSE; | |
2660 #endif | |
2661 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) | |
2662 if (is_click || is_drag) | |
2663 return FALSE; | |
2664 #endif | |
573 | 2665 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2666 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
2667 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) | |
2668 if (gui.in_use) | |
2669 { | |
2670 jump_flags = 0; | |
2671 if (STRCMP(p_mousem, "popup_setpos") == 0) | |
2672 { | |
2673 /* First set the cursor position before showing the popup | |
2674 * menu. */ | |
2675 if (VIsual_active) | |
2676 { | |
2677 pos_T m_pos; | |
2678 | |
2679 /* | |
2680 * set MOUSE_MAY_STOP_VIS if we are outside the | |
2681 * selection or the current window (might have false | |
2682 * negative here) | |
2683 */ | |
2684 if (mouse_row < W_WINROW(curwin) | |
2685 || mouse_row | |
2686 > (W_WINROW(curwin) + curwin->w_height)) | |
2687 jump_flags = MOUSE_MAY_STOP_VIS; | |
2688 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) | |
2689 jump_flags = MOUSE_MAY_STOP_VIS; | |
2690 else | |
2691 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2692 if ((LT_POS(curwin->w_cursor, VIsual) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2693 && (LT_POS(m_pos, curwin->w_cursor) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2694 || LT_POS(VIsual, m_pos))) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2695 || (LT_POS(VIsual, curwin->w_cursor) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2696 && (LT_POS(m_pos, VIsual) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2697 || LT_POS(curwin->w_cursor, m_pos)))) |
7 | 2698 { |
2699 jump_flags = MOUSE_MAY_STOP_VIS; | |
2700 } | |
2701 else if (VIsual_mode == Ctrl_V) | |
2702 { | |
2703 getvcols(curwin, &curwin->w_cursor, &VIsual, | |
2704 &leftcol, &rightcol); | |
2705 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); | |
2706 if (m_pos.col < leftcol || m_pos.col > rightcol) | |
2707 jump_flags = MOUSE_MAY_STOP_VIS; | |
2708 } | |
2709 } | |
2710 } | |
2711 else | |
2712 jump_flags = MOUSE_MAY_STOP_VIS; | |
2713 } | |
2714 if (jump_flags) | |
2715 { | |
2716 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); | |
5735 | 2717 update_curbuf(VIsual_active ? INVERTED : VALID); |
7 | 2718 setcursor(); |
2719 out_flush(); /* Update before showing popup menu */ | |
2720 } | |
2721 # ifdef FEAT_MENU | |
2722 gui_show_popupmenu(); | |
2723 # endif | |
2724 return (jump_flags & CURSOR_MOVED) != 0; | |
2725 } | |
2726 else | |
2727 return FALSE; | |
2728 #else | |
2729 return FALSE; | |
2730 #endif | |
2731 } | |
598 | 2732 if (which_button == MOUSE_LEFT |
2733 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2734 { |
2735 which_button = MOUSE_RIGHT; | |
2736 mod_mask &= ~MOD_MASK_SHIFT; | |
2737 } | |
2738 } | |
2739 | |
2740 if ((State & (NORMAL | INSERT)) | |
2741 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2742 { | |
2743 if (which_button == MOUSE_LEFT) | |
2744 { | |
2745 if (is_click) | |
2746 { | |
2747 /* stop Visual mode for a left click in a window, but not when | |
2748 * on a status line */ | |
2749 if (VIsual_active) | |
2750 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2751 } | |
2752 else if (mouse_has(MOUSE_VISUAL)) | |
2753 jump_flags |= MOUSE_MAY_VIS; | |
2754 } | |
2755 else if (which_button == MOUSE_RIGHT) | |
2756 { | |
2757 if (is_click && VIsual_active) | |
2758 { | |
2759 /* | |
2760 * Remember the start and end of visual before moving the | |
2761 * cursor. | |
2762 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2763 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2764 { |
2765 start_visual = curwin->w_cursor; | |
2766 end_visual = VIsual; | |
2767 } | |
2768 else | |
2769 { | |
2770 start_visual = VIsual; | |
2771 end_visual = curwin->w_cursor; | |
2772 } | |
2773 } | |
2774 jump_flags |= MOUSE_FOCUS; | |
2775 if (mouse_has(MOUSE_VISUAL)) | |
2776 jump_flags |= MOUSE_MAY_VIS; | |
2777 } | |
2778 } | |
2779 | |
2780 /* | |
2781 * If an operator is pending, ignore all drags and releases until the | |
2782 * next mouse click. | |
2783 */ | |
2784 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2785 { | |
2786 got_click = FALSE; | |
2787 oap->motion_type = MCHAR; | |
2788 } | |
2789 | |
2790 /* When releasing the button let jump_to_mouse() know. */ | |
2791 if (!is_click && !is_drag) | |
2792 jump_flags |= MOUSE_RELEASED; | |
2793 | |
2794 /* | |
2795 * JUMP! | |
2796 */ | |
2797 jump_flags = jump_to_mouse(jump_flags, | |
2798 oap == NULL ? NULL : &(oap->inclusive), which_button); | |
2799 moved = (jump_flags & CURSOR_MOVED); | |
2800 in_status_line = (jump_flags & IN_STATUS_LINE); | |
8651
8a106a24d128
commit https://github.com/vim/vim/commit/829c8e369630a7cbbdac015d8177b7fde25e2f19
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2801 #ifdef FEAT_WINDOWS |
7 | 2802 in_sep_line = (jump_flags & IN_SEP_LINE); |
8651
8a106a24d128
commit https://github.com/vim/vim/commit/829c8e369630a7cbbdac015d8177b7fde25e2f19
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2803 #endif |
7 | 2804 |
2805 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2806 if (isNetbeansBuffer(curbuf) |
7 | 2807 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2808 { | |
2809 int key = KEY2TERMCAP1(c); | |
2810 | |
2811 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2812 || key == (int)KE_RIGHTRELEASE) | |
2813 netbeans_button_release(which_button); | |
2814 } | |
2815 #endif | |
2816 | |
2817 /* When jumping to another window, clear a pending operator. That's a bit | |
2818 * friendlier than beeping and not jumping to that window. */ | |
2819 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2820 clearop(oap); | |
2821 | |
2822 #ifdef FEAT_FOLDING | |
2823 if (mod_mask == 0 | |
2824 && !is_drag | |
2825 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2826 && which_button == MOUSE_LEFT) | |
2827 { | |
2828 /* open or close a fold at this line */ | |
2829 if (jump_flags & MOUSE_FOLD_OPEN) | |
2830 openFold(curwin->w_cursor.lnum, 1L); | |
2831 else | |
2832 closeFold(curwin->w_cursor.lnum, 1L); | |
2833 /* don't move the cursor if still in the same window */ | |
2834 if (curwin == old_curwin) | |
2835 curwin->w_cursor = save_cursor; | |
2836 } | |
2837 #endif | |
2838 | |
2839 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2840 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2841 { | |
2842 clip_modeless(which_button, is_click, is_drag); | |
2843 return FALSE; | |
2844 } | |
2845 #endif | |
2846 | |
2847 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2848 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2849 if (VIsual_active && is_drag && p_so) |
2850 { | |
2851 /* In the very first line, allow scrolling one line */ | |
2852 if (mouse_row == 0) | |
2853 mouse_dragging = 2; | |
2854 else | |
2855 mouse_dragging = 1; | |
2856 } | |
2857 | |
2858 /* When dragging the mouse above the window, scroll down. */ | |
2859 if (is_drag && mouse_row < 0 && !in_status_line) | |
2860 { | |
2861 scroll_redraw(FALSE, 1L); | |
2862 mouse_row = 0; | |
2863 } | |
2864 | |
2865 if (start_visual.lnum) /* right click in visual mode */ | |
2866 { | |
598 | 2867 /* When ALT is pressed make Visual mode blockwise. */ |
2868 if (mod_mask & MOD_MASK_ALT) | |
2869 VIsual_mode = Ctrl_V; | |
2870 | |
7 | 2871 /* |
2872 * In Visual-block mode, divide the area in four, pick up the corner | |
2873 * that is in the quarter that the cursor is in. | |
2874 */ | |
2875 if (VIsual_mode == Ctrl_V) | |
2876 { | |
2877 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2878 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2879 end_visual.col = leftcol; | |
2880 else | |
2881 end_visual.col = rightcol; | |
7009 | 2882 if (curwin->w_cursor.lnum >= |
7 | 2883 (start_visual.lnum + end_visual.lnum) / 2) |
2884 end_visual.lnum = start_visual.lnum; | |
2885 | |
2886 /* move VIsual to the right column */ | |
2887 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2888 curwin->w_cursor = end_visual; | |
2889 coladvance(end_visual.col); | |
2890 VIsual = curwin->w_cursor; | |
2891 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2892 } | |
2893 else | |
2894 { | |
2895 /* | |
2896 * If the click is before the start of visual, change the start. | |
2897 * If the click is after the end of visual, change the end. If | |
2898 * the click is inside the visual, change the closest side. | |
2899 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2900 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2901 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2902 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2903 VIsual = start_visual; |
2904 else | |
2905 { | |
2906 /* In the same line, compare column number */ | |
2907 if (end_visual.lnum == start_visual.lnum) | |
2908 { | |
2909 if (curwin->w_cursor.col - start_visual.col > | |
2910 end_visual.col - curwin->w_cursor.col) | |
2911 VIsual = start_visual; | |
2912 else | |
2913 VIsual = end_visual; | |
2914 } | |
2915 | |
2916 /* In different lines, compare line number */ | |
2917 else | |
2918 { | |
2919 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2920 (end_visual.lnum - curwin->w_cursor.lnum); | |
2921 | |
2922 if (diff > 0) /* closest to end */ | |
2923 VIsual = start_visual; | |
2924 else if (diff < 0) /* closest to start */ | |
2925 VIsual = end_visual; | |
2926 else /* in the middle line */ | |
2927 { | |
2928 if (curwin->w_cursor.col < | |
2929 (start_visual.col + end_visual.col) / 2) | |
2930 VIsual = end_visual; | |
2931 else | |
2932 VIsual = start_visual; | |
2933 } | |
2934 } | |
2935 } | |
2936 } | |
2937 } | |
2938 /* | |
2939 * If Visual mode started in insert mode, execute "CTRL-O" | |
2940 */ | |
2941 else if ((State & INSERT) && VIsual_active) | |
2942 stuffcharReadbuff(Ctrl_O); | |
2943 | |
2944 /* | |
2945 * Middle mouse click: Put text before cursor. | |
2946 */ | |
2947 if (which_button == MOUSE_MIDDLE) | |
2948 { | |
2949 #ifdef FEAT_CLIPBOARD | |
2950 if (clip_star.available && regname == 0) | |
2951 regname = '*'; | |
2952 #endif | |
2953 if (yank_register_mline(regname)) | |
2954 { | |
2955 if (mouse_past_bottom) | |
2956 dir = FORWARD; | |
2957 } | |
2958 else if (mouse_past_eol) | |
2959 dir = FORWARD; | |
2960 | |
2961 if (fixindent) | |
2962 { | |
2963 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2964 c2 = 'p'; | |
2965 } | |
2966 else | |
2967 { | |
2968 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2969 c2 = NUL; | |
2970 } | |
2971 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2972 | |
2973 /* | |
2974 * Remember where the paste started, so in edit() Insstart can be set | |
2975 * to this position | |
2976 */ | |
2977 if (restart_edit != 0) | |
2978 where_paste_started = curwin->w_cursor; | |
2979 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2980 } | |
2981 | |
2982 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | |
2983 /* | |
2984 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
2985 * error under the mouse pointer. | |
2986 */ | |
2987 else if (((mod_mask & MOD_MASK_CTRL) | |
2988 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
2989 && bt_quickfix(curbuf)) | |
2990 { | |
643 | 2991 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
|
2992 do_cmdline_cmd((char_u *)".cc"); |
643 | 2993 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
|
2994 do_cmdline_cmd((char_u *)".ll"); |
7 | 2995 got_click = FALSE; /* ignore drag&release now */ |
2996 } | |
2997 #endif | |
2998 | |
2999 /* | |
3000 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3001 * under the mouse pointer. | |
3002 */ | |
3003 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3004 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3005 { | |
3006 if (State & INSERT) | |
3007 stuffcharReadbuff(Ctrl_O); | |
3008 stuffcharReadbuff(Ctrl_RSB); | |
3009 got_click = FALSE; /* ignore drag&release now */ | |
3010 } | |
3011 | |
3012 /* | |
3013 * Shift-Mouse click searches for the next occurrence of the word under | |
3014 * the mouse pointer | |
3015 */ | |
3016 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3017 { | |
5735 | 3018 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3019 stuffcharReadbuff(Ctrl_O); |
3020 if (which_button == MOUSE_LEFT) | |
3021 stuffcharReadbuff('*'); | |
3022 else /* MOUSE_RIGHT */ | |
3023 stuffcharReadbuff('#'); | |
3024 } | |
3025 | |
3026 /* Handle double clicks, unless on status line */ | |
3027 else if (in_status_line) | |
3028 { | |
3029 #ifdef FEAT_MOUSESHAPE | |
3030 if ((is_drag || is_click) && !drag_status_line) | |
3031 { | |
3032 drag_status_line = TRUE; | |
3033 update_mouseshape(-1); | |
3034 } | |
3035 #endif | |
3036 } | |
8651
8a106a24d128
commit https://github.com/vim/vim/commit/829c8e369630a7cbbdac015d8177b7fde25e2f19
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3037 #ifdef FEAT_WINDOWS |
7 | 3038 else if (in_sep_line) |
3039 { | |
3040 # ifdef FEAT_MOUSESHAPE | |
3041 if ((is_drag || is_click) && !drag_sep_line) | |
3042 { | |
3043 drag_sep_line = TRUE; | |
3044 update_mouseshape(-1); | |
3045 } | |
3046 # endif | |
3047 } | |
8651
8a106a24d128
commit https://github.com/vim/vim/commit/829c8e369630a7cbbdac015d8177b7fde25e2f19
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3048 #endif |
7 | 3049 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3050 && mouse_has(MOUSE_VISUAL)) | |
3051 { | |
3052 if (is_click || !VIsual_active) | |
3053 { | |
3054 if (VIsual_active) | |
3055 orig_cursor = VIsual; | |
3056 else | |
3057 { | |
3058 check_visual_highlight(); | |
3059 VIsual = curwin->w_cursor; | |
3060 orig_cursor = VIsual; | |
3061 VIsual_active = TRUE; | |
3062 VIsual_reselect = TRUE; | |
3063 /* start Select mode if 'selectmode' contains "mouse" */ | |
3064 may_start_select('o'); | |
3065 setmouse(); | |
3066 } | |
3067 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3068 { |
3069 /* Double click with ALT pressed makes it blockwise. */ | |
3070 if (mod_mask & MOD_MASK_ALT) | |
3071 VIsual_mode = Ctrl_V; | |
3072 else | |
3073 VIsual_mode = 'v'; | |
3074 } | |
7 | 3075 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3076 VIsual_mode = 'V'; | |
3077 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3078 VIsual_mode = Ctrl_V; | |
3079 #ifdef FEAT_CLIPBOARD | |
3080 /* Make sure the clipboard gets updated. Needed because start and | |
3081 * end may still be the same, and the selection needs to be owned */ | |
3082 clip_star.vmode = NUL; | |
3083 #endif | |
3084 } | |
3085 /* | |
3086 * A double click selects a word or a block. | |
3087 */ | |
3088 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3089 { | |
3090 pos_T *pos = NULL; | |
300 | 3091 int gc; |
7 | 3092 |
3093 if (is_click) | |
3094 { | |
3095 /* If the character under the cursor (skipping white space) is | |
3096 * not a word character, try finding a match and select a (), | |
3097 * {}, [], #if/#endif, etc. block. */ | |
3098 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
|
3099 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3100 inc(&end_visual); |
3101 if (oap != NULL) | |
3102 oap->motion_type = MCHAR; | |
3103 if (oap != NULL | |
3104 && VIsual_mode == 'v' | |
3105 && !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
|
3106 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3107 && (pos = findmatch(oap, NUL)) != NULL) |
3108 { | |
3109 curwin->w_cursor = *pos; | |
3110 if (oap->motion_type == MLINE) | |
3111 VIsual_mode = 'V'; | |
3112 else if (*p_sel == 'e') | |
3113 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3114 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3115 ++VIsual.col; |
3116 else | |
3117 ++curwin->w_cursor.col; | |
3118 } | |
3119 } | |
3120 } | |
3121 | |
3122 if (pos == NULL && (is_click || is_drag)) | |
3123 { | |
3124 /* When not found a match or when dragging: extend to include | |
3125 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3126 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3127 { |
3128 find_start_of_word(&curwin->w_cursor); | |
3129 find_end_of_word(&VIsual); | |
3130 } | |
3131 else | |
3132 { | |
3133 find_start_of_word(&VIsual); | |
3134 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3135 #ifdef FEAT_MBYTE | |
3136 curwin->w_cursor.col += | |
474 | 3137 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3138 #else |
3139 ++curwin->w_cursor.col; | |
3140 #endif | |
3141 find_end_of_word(&curwin->w_cursor); | |
3142 } | |
3143 } | |
3144 curwin->w_set_curswant = TRUE; | |
3145 } | |
3146 if (is_click) | |
3147 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3148 } | |
3149 else if (VIsual_active && !old_active) | |
598 | 3150 { |
3151 if (mod_mask & MOD_MASK_ALT) | |
3152 VIsual_mode = Ctrl_V; | |
3153 else | |
3154 VIsual_mode = 'v'; | |
3155 } | |
7 | 3156 |
3157 /* If Visual mode changed show it later. */ | |
643 | 3158 if ((!VIsual_active && old_active && mode_displayed) |
3159 || (VIsual_active && p_smd && msg_silent == 0 | |
3160 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3161 redraw_cmdline = TRUE; |
3162 | |
3163 return moved; | |
3164 } | |
3165 | |
3166 /* | |
3167 * Move "pos" back to the start of the word it's in. | |
3168 */ | |
3169 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3170 find_start_of_word(pos_T *pos) |
7 | 3171 { |
3172 char_u *line; | |
3173 int cclass; | |
3174 int col; | |
3175 | |
3176 line = ml_get(pos->lnum); | |
3177 cclass = get_mouse_class(line + pos->col); | |
3178 | |
3179 while (pos->col > 0) | |
3180 { | |
3181 col = pos->col - 1; | |
3182 #ifdef FEAT_MBYTE | |
3183 col -= (*mb_head_off)(line, line + col); | |
3184 #endif | |
3185 if (get_mouse_class(line + col) != cclass) | |
3186 break; | |
3187 pos->col = col; | |
3188 } | |
3189 } | |
3190 | |
3191 /* | |
3192 * Move "pos" forward to the end of the word it's in. | |
3193 * When 'selection' is "exclusive", the position is just after the word. | |
3194 */ | |
3195 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3196 find_end_of_word(pos_T *pos) |
7 | 3197 { |
3198 char_u *line; | |
3199 int cclass; | |
3200 int col; | |
3201 | |
3202 line = ml_get(pos->lnum); | |
3203 if (*p_sel == 'e' && pos->col > 0) | |
3204 { | |
3205 --pos->col; | |
3206 #ifdef FEAT_MBYTE | |
3207 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3208 #endif | |
3209 } | |
3210 cclass = get_mouse_class(line + pos->col); | |
3211 while (line[pos->col] != NUL) | |
3212 { | |
3213 #ifdef FEAT_MBYTE | |
474 | 3214 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3215 #else |
3216 col = pos->col + 1; | |
3217 #endif | |
3218 if (get_mouse_class(line + col) != cclass) | |
3219 { | |
3220 if (*p_sel == 'e') | |
3221 pos->col = col; | |
3222 break; | |
3223 } | |
3224 pos->col = col; | |
3225 } | |
3226 } | |
3227 | |
3228 /* | |
3229 * Get class of a character for selection: same class means same word. | |
3230 * 0: blank | |
3231 * 1: punctuation groups | |
3232 * 2: normal word character | |
3233 * >2: multi-byte word character. | |
3234 */ | |
3235 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3236 get_mouse_class(char_u *p) |
7 | 3237 { |
3238 int c; | |
3239 | |
3240 #ifdef FEAT_MBYTE | |
3241 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3242 return mb_get_class(p); | |
3243 #endif | |
3244 | |
3245 c = *p; | |
3246 if (c == ' ' || c == '\t') | |
3247 return 0; | |
3248 | |
3249 if (vim_iswordc(c)) | |
3250 return 2; | |
3251 | |
3252 /* | |
3253 * There are a few special cases where we want certain combinations of | |
3254 * characters to be considered as a single word. These are things like | |
3255 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3256 * character is in its own class. |
7 | 3257 */ |
3258 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3259 return 1; | |
3260 return c; | |
3261 } | |
3262 #endif /* FEAT_MOUSE */ | |
3263 | |
3264 /* | |
3265 * Check if highlighting for visual mode is possible, give a warning message | |
3266 * if not. | |
3267 */ | |
3268 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3269 check_visual_highlight(void) |
7 | 3270 { |
3271 static int did_check = FALSE; | |
3272 | |
3273 if (full_screen) | |
3274 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3275 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3276 MSG(_("Warning: terminal cannot highlight")); |
3277 did_check = TRUE; | |
3278 } | |
3279 } | |
3280 | |
3281 /* | |
638 | 3282 * End Visual mode. |
7 | 3283 * This function should ALWAYS be called to end Visual mode, except from |
3284 * do_pending_operator(). | |
3285 */ | |
3286 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3287 end_visual_mode(void) |
7 | 3288 { |
3289 #ifdef FEAT_CLIPBOARD | |
3290 /* | |
3291 * If we are using the clipboard, then remember what was selected in case | |
3292 * we need to paste it somewhere while we still own the selection. | |
3293 * Only do this when the clipboard is already owned. Don't want to grab | |
3294 * the selection when hitting ESC. | |
3295 */ | |
3296 if (clip_star.available && clip_star.owned) | |
3297 clip_auto_select(); | |
3298 #endif | |
3299 | |
3300 VIsual_active = FALSE; | |
3301 #ifdef FEAT_MOUSE | |
3302 setmouse(); | |
3303 mouse_dragging = 0; | |
3304 #endif | |
3305 | |
3306 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3307 curbuf->b_visual.vi_mode = VIsual_mode; |
3308 curbuf->b_visual.vi_start = VIsual; | |
3309 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3310 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3311 #ifdef FEAT_EVAL |
3312 curbuf->b_visual_mode_eval = VIsual_mode; | |
3313 #endif | |
3314 #ifdef FEAT_VIRTUALEDIT | |
3315 if (!virtual_active()) | |
3316 curwin->w_cursor.coladd = 0; | |
3317 #endif | |
6979 | 3318 may_clear_cmdline(); |
7 | 3319 |
844 | 3320 adjust_cursor_eol(); |
7 | 3321 } |
3322 | |
3323 /* | |
3324 * Reset VIsual_active and VIsual_reselect. | |
3325 */ | |
3326 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3327 reset_VIsual_and_resel(void) |
7 | 3328 { |
3329 if (VIsual_active) | |
3330 { | |
3331 end_visual_mode(); | |
3332 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3333 } | |
3334 VIsual_reselect = FALSE; | |
3335 } | |
3336 | |
3337 /* | |
3338 * Reset VIsual_active and VIsual_reselect if it's set. | |
3339 */ | |
3340 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3341 reset_VIsual(void) |
7 | 3342 { |
3343 if (VIsual_active) | |
3344 { | |
3345 end_visual_mode(); | |
3346 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3347 VIsual_reselect = FALSE; | |
3348 } | |
3349 } | |
3350 | |
184 | 3351 #if defined(FEAT_BEVAL) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3352 static int find_is_eval_item(char_u *ptr, int *colp, int *nbp, int dir); |
7 | 3353 |
3354 /* | |
3355 * Check for a balloon-eval special item to include when searching for an | |
3356 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3357 * Returns TRUE if the character at "*ptr" should be included. | |
3358 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3359 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3360 * "bnp" points to a counter for square brackets. | |
3361 */ | |
3362 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3363 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3364 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3365 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3366 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3367 int dir) |
7 | 3368 { |
3369 /* Accept everything inside []. */ | |
3370 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3371 ++*bnp; | |
3372 if (*bnp > 0) | |
3373 { | |
3374 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3375 --*bnp; | |
3376 return TRUE; | |
3377 } | |
3378 | |
3379 /* skip over "s.var" */ | |
3380 if (*ptr == '.') | |
3381 return TRUE; | |
3382 | |
3383 /* two-character item: s->var */ | |
3384 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3385 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3386 { | |
3387 *colp += dir; | |
3388 return TRUE; | |
3389 } | |
3390 return FALSE; | |
3391 } | |
3392 #endif | |
3393 | |
3394 /* | |
3395 * Find the identifier under or to the right of the cursor. | |
3396 * "find_type" can have one of three values: | |
3397 * FIND_IDENT: find an identifier (keyword) | |
3398 * FIND_STRING: find any non-white string | |
3399 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3400 * FIND_EVAL: find text useful for C program debugging |
7 | 3401 * |
3402 * There are three steps: | |
3403 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3404 * already on one. | |
3405 * 2. Search backward for the start of this identifier/string. | |
3406 * This doesn't match the real Vi but I like it a little better and it | |
3407 * shouldn't bother anyone. | |
3408 * 3. Search forward to the end of this identifier/string. | |
3409 * When FIND_IDENT isn't defined, we backup until a blank. | |
3410 * | |
3411 * Returns the length of the string, or zero if no string is found. | |
3412 * If a string is found, a pointer to the string is put in "*string". This | |
3413 * string is not always NUL terminated. | |
3414 */ | |
3415 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3416 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3417 { |
3418 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3419 curwin->w_cursor.col, string, find_type); | |
3420 } | |
3421 | |
3422 /* | |
3423 * Like find_ident_under_cursor(), but for any window and any position. | |
3424 * However: Uses 'iskeyword' from the current window!. | |
3425 */ | |
3426 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3427 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3428 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3429 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3430 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3431 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3432 int find_type) |
7 | 3433 { |
3434 char_u *ptr; | |
3435 int col = 0; /* init to shut up GCC */ | |
3436 int i; | |
3437 #ifdef FEAT_MBYTE | |
3438 int this_class = 0; | |
3439 int prev_class; | |
3440 int prevcol; | |
3441 #endif | |
184 | 3442 #if defined(FEAT_BEVAL) |
7 | 3443 int bn = 0; /* bracket nesting */ |
3444 #endif | |
3445 | |
3446 /* | |
3447 * if i == 0: try to find an identifier | |
3448 * if i == 1: try to find any non-white string | |
3449 */ | |
3450 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3451 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3452 { | |
3453 /* | |
3454 * 1. skip to start of identifier/string | |
3455 */ | |
3456 col = startcol; | |
3457 #ifdef FEAT_MBYTE | |
3458 if (has_mbyte) | |
3459 { | |
3460 while (ptr[col] != NUL) | |
3461 { | |
184 | 3462 # if defined(FEAT_BEVAL) |
7 | 3463 /* Stop at a ']' to evaluate "a[x]". */ |
3464 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3465 break; | |
3466 # endif | |
3467 this_class = mb_get_class(ptr + col); | |
3468 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3469 break; | |
474 | 3470 col += (*mb_ptr2len)(ptr + col); |
7 | 3471 } |
3472 } | |
3473 else | |
3474 #endif | |
3475 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
|
3476 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
184 | 3477 # if defined(FEAT_BEVAL) |
7 | 3478 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3479 # endif | |
3480 ) | |
3481 ++col; | |
3482 | |
184 | 3483 #if defined(FEAT_BEVAL) |
7 | 3484 /* When starting on a ']' count it, so that we include the '['. */ |
3485 bn = ptr[col] == ']'; | |
3486 #endif | |
3487 | |
3488 /* | |
3489 * 2. Back up to start of identifier/string. | |
3490 */ | |
3491 #ifdef FEAT_MBYTE | |
3492 if (has_mbyte) | |
3493 { | |
3494 /* Remember class of character under cursor. */ | |
184 | 3495 # if defined(FEAT_BEVAL) |
7 | 3496 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
3497 this_class = mb_get_class((char_u *)"a"); | |
3498 else | |
3499 # endif | |
3500 this_class = mb_get_class(ptr + col); | |
835 | 3501 while (col > 0 && this_class != 0) |
7 | 3502 { |
3503 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3504 prev_class = mb_get_class(ptr + prevcol); | |
3505 if (this_class != prev_class | |
3506 && (i == 0 | |
3507 || prev_class == 0 | |
3508 || (find_type & FIND_IDENT)) | |
184 | 3509 # if defined(FEAT_BEVAL) |
7 | 3510 && (!(find_type & FIND_EVAL) |
3511 || prevcol == 0 | |
3512 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3513 &bn, BACKWARD)) | |
3514 # endif | |
3515 ) | |
3516 break; | |
3517 col = prevcol; | |
3518 } | |
3519 | |
3520 /* If we don't want just any old string, or we've found an | |
3521 * identifier, stop searching. */ | |
3522 if (this_class > 2) | |
3523 this_class = 2; | |
3524 if (!(find_type & FIND_STRING) || this_class == 2) | |
3525 break; | |
3526 } | |
3527 else | |
3528 #endif | |
3529 { | |
3530 while (col > 0 | |
3531 && ((i == 0 | |
3532 ? 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
|
3533 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3534 && (!(find_type & FIND_IDENT) |
3535 || !vim_iswordc(ptr[col - 1])))) | |
184 | 3536 #if defined(FEAT_BEVAL) |
7 | 3537 || ((find_type & FIND_EVAL) |
3538 && col > 1 | |
3539 && find_is_eval_item(ptr + col - 1, &col, | |
3540 &bn, BACKWARD)) | |
3541 #endif | |
3542 )) | |
3543 --col; | |
3544 | |
3545 /* If we don't want just any old string, or we've found an | |
3546 * identifier, stop searching. */ | |
3547 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3548 break; | |
3549 } | |
3550 } | |
3551 | |
3552 if (ptr[col] == NUL || (i == 0 && ( | |
3553 #ifdef FEAT_MBYTE | |
3554 has_mbyte ? this_class != 2 : | |
3555 #endif | |
3556 !vim_iswordc(ptr[col])))) | |
3557 { | |
3558 /* | |
3559 * didn't find an identifier or string | |
3560 */ | |
3561 if (find_type & FIND_STRING) | |
3562 EMSG(_("E348: No string under cursor")); | |
3563 else | |
1728 | 3564 EMSG(_(e_noident)); |
7 | 3565 return 0; |
3566 } | |
3567 ptr += col; | |
3568 *string = ptr; | |
3569 | |
3570 /* | |
3571 * 3. Find the end if the identifier/string. | |
3572 */ | |
184 | 3573 #if defined(FEAT_BEVAL) |
7 | 3574 bn = 0; |
3575 startcol -= col; | |
3576 #endif | |
3577 col = 0; | |
3578 #ifdef FEAT_MBYTE | |
3579 if (has_mbyte) | |
3580 { | |
3581 /* Search for point of changing multibyte character class. */ | |
3582 this_class = mb_get_class(ptr); | |
3583 while (ptr[col] != NUL | |
3584 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3585 : mb_get_class(ptr + col) != 0) | |
184 | 3586 # if defined(FEAT_BEVAL) |
7 | 3587 || ((find_type & FIND_EVAL) |
3588 && col <= (int)startcol | |
3589 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3590 # endif | |
3591 )) | |
474 | 3592 col += (*mb_ptr2len)(ptr + col); |
7 | 3593 } |
3594 else | |
3595 #endif | |
3596 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
|
3597 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
184 | 3598 # if defined(FEAT_BEVAL) |
7 | 3599 || ((find_type & FIND_EVAL) |
3600 && col <= (int)startcol | |
3601 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3602 # endif | |
3603 ) | |
3604 { | |
3605 ++col; | |
3606 } | |
3607 | |
3608 return col; | |
3609 } | |
3610 | |
3611 /* | |
3612 * Prepare for redo of a normal command. | |
3613 */ | |
3614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3615 prep_redo_cmd(cmdarg_T *cap) |
7 | 3616 { |
3617 prep_redo(cap->oap->regname, cap->count0, | |
3618 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3619 } | |
3620 | |
3621 /* | |
3622 * Prepare for redo of any command. | |
3623 * Note that only the last argument can be a multi-byte char. | |
3624 */ | |
3625 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3626 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3627 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3628 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3629 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3630 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3631 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3632 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3633 int cmd5) |
7 | 3634 { |
3635 ResetRedobuff(); | |
3636 if (regname != 0) /* yank from specified buffer */ | |
3637 { | |
3638 AppendCharToRedobuff('"'); | |
3639 AppendCharToRedobuff(regname); | |
3640 } | |
3641 if (num) | |
3642 AppendNumberToRedobuff(num); | |
3643 | |
3644 if (cmd1 != NUL) | |
3645 AppendCharToRedobuff(cmd1); | |
3646 if (cmd2 != NUL) | |
3647 AppendCharToRedobuff(cmd2); | |
3648 if (cmd3 != NUL) | |
3649 AppendCharToRedobuff(cmd3); | |
3650 if (cmd4 != NUL) | |
3651 AppendCharToRedobuff(cmd4); | |
3652 if (cmd5 != NUL) | |
3653 AppendCharToRedobuff(cmd5); | |
3654 } | |
3655 | |
3656 /* | |
3657 * check for operator active and clear it | |
3658 * | |
3659 * return TRUE if operator was active | |
3660 */ | |
3661 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3662 checkclearop(oparg_T *oap) |
7 | 3663 { |
3664 if (oap->op_type == OP_NOP) | |
3665 return FALSE; | |
3666 clearopbeep(oap); | |
3667 return TRUE; | |
3668 } | |
3669 | |
3670 /* | |
1131 | 3671 * Check for operator or Visual active. Clear active operator. |
7 | 3672 * |
1131 | 3673 * Return TRUE if operator or Visual was active. |
7 | 3674 */ |
3675 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3676 checkclearopq(oparg_T *oap) |
7 | 3677 { |
5735 | 3678 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3679 return FALSE; |
3680 clearopbeep(oap); | |
3681 return TRUE; | |
3682 } | |
3683 | |
3684 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3685 clearop(oparg_T *oap) |
7 | 3686 { |
3687 oap->op_type = OP_NOP; | |
3688 oap->regname = 0; | |
3689 oap->motion_force = NUL; | |
3690 oap->use_reg_one = FALSE; | |
3691 } | |
3692 | |
3693 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3694 clearopbeep(oparg_T *oap) |
7 | 3695 { |
3696 clearop(oap); | |
3697 beep_flush(); | |
3698 } | |
3699 | |
3700 /* | |
3701 * Remove the shift modifier from a special key. | |
3702 */ | |
3703 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3704 unshift_special(cmdarg_T *cap) |
7 | 3705 { |
3706 switch (cap->cmdchar) | |
3707 { | |
3708 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3709 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3710 case K_S_UP: cap->cmdchar = K_UP; break; | |
3711 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3712 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3713 case K_S_END: cap->cmdchar = K_END; break; | |
3714 } | |
3715 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3716 } | |
3717 | |
6979 | 3718 /* |
3719 * If the mode is currently displayed clear the command line or update the | |
3720 * command displayed. | |
3721 */ | |
3722 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3723 may_clear_cmdline(void) |
6979 | 3724 { |
3725 if (mode_displayed) | |
3726 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3727 #ifdef FEAT_CMDL_INFO | |
3728 else | |
3729 clear_showcmd(); | |
3730 #endif | |
3731 } | |
3732 | |
7 | 3733 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3734 /* | |
3735 * Routines for displaying a partly typed command | |
3736 */ | |
3737 | |
5735 | 3738 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3739 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3740 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3741 static int showcmd_is_clear = TRUE; | |
3742 static int showcmd_visual = FALSE; | |
3743 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3744 static void display_showcmd(void); |
7 | 3745 |
3746 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3747 clear_showcmd(void) |
7 | 3748 { |
3749 if (!p_sc) | |
3750 return; | |
3751 | |
3752 if (VIsual_active && !char_avail()) | |
3753 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3754 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3755 long lines; |
3756 colnr_T leftcol, rightcol; | |
3757 linenr_T top, bot; | |
3758 | |
3759 /* Show the size of the Visual area. */ | |
1866 | 3760 if (cursor_bot) |
7 | 3761 { |
3762 top = VIsual.lnum; | |
3763 bot = curwin->w_cursor.lnum; | |
3764 } | |
3765 else | |
3766 { | |
3767 top = curwin->w_cursor.lnum; | |
3768 bot = VIsual.lnum; | |
3769 } | |
3770 # ifdef FEAT_FOLDING | |
3771 /* Include closed folds as a whole. */ | |
7009 | 3772 (void)hasFolding(top, &top, NULL); |
3773 (void)hasFolding(bot, NULL, &bot); | |
7 | 3774 # endif |
3775 lines = bot - top + 1; | |
3776 | |
3777 if (VIsual_mode == Ctrl_V) | |
3778 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3779 # ifdef FEAT_LINEBREAK |
1866 | 3780 char_u *saved_sbr = p_sbr; |
3781 | |
3782 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3783 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3784 # endif |
7 | 3785 getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3786 # ifdef FEAT_LINEBREAK |
1866 | 3787 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3788 # endif |
7 | 3789 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3790 (long)(rightcol - leftcol + 1)); | |
3791 } | |
3792 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3793 sprintf((char *)showcmd_buf, "%ld", lines); | |
3794 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3795 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3796 char_u *s, *e; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3797 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3798 int bytes = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3799 int chars = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3800 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3801 if (cursor_bot) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3802 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3803 s = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3804 e = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3805 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3806 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3807 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3808 s = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3809 e = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3810 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3811 while ((*p_sel != 'e') ? s <= e : s < e) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3812 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3813 # ifdef FEAT_MBYTE |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3814 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3815 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3816 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3817 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3818 if (l == 0) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3819 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3820 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3821 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3822 break; /* end of line */ |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3823 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3824 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3825 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3826 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3827 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3828 if (bytes == chars) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3829 sprintf((char *)showcmd_buf, "%d", chars); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3830 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3831 sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3832 } |
7 | 3833 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3834 showcmd_visual = TRUE; | |
3835 } | |
3836 else | |
3837 { | |
3838 showcmd_buf[0] = NUL; | |
3839 showcmd_visual = FALSE; | |
3840 | |
3841 /* Don't actually display something if there is nothing to clear. */ | |
3842 if (showcmd_is_clear) | |
3843 return; | |
3844 } | |
3845 | |
3846 display_showcmd(); | |
3847 } | |
3848 | |
3849 /* | |
3850 * Add 'c' to string of shown command chars. | |
3851 * Return TRUE if output has been written (and setcursor() has been called). | |
3852 */ | |
3853 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3854 add_to_showcmd(int c) |
7 | 3855 { |
3856 char_u *p; | |
3857 int old_len; | |
3858 int extra_len; | |
3859 int overflow; | |
3860 #if defined(FEAT_MOUSE) | |
3861 int i; | |
3862 static int ignore[] = | |
3863 { | |
660 | 3864 # ifdef FEAT_GUI |
7 | 3865 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3866 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3867 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3868 K_IGNORE, K_PS, |
7 | 3869 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, |
3870 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, | |
3871 K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3872 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3873 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3874 K_CURSORHOLD, |
7 | 3875 0 |
3876 }; | |
3877 #endif | |
3878 | |
641 | 3879 if (!p_sc || msg_silent != 0) |
7 | 3880 return FALSE; |
3881 | |
3882 if (showcmd_visual) | |
3883 { | |
3884 showcmd_buf[0] = NUL; | |
3885 showcmd_visual = FALSE; | |
3886 } | |
3887 | |
3888 #if defined(FEAT_MOUSE) | |
3889 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3890 if (IS_SPECIAL(c)) | |
3891 for (i = 0; ignore[i] != 0; ++i) | |
3892 if (ignore[i] == c) | |
3893 return FALSE; | |
3894 #endif | |
3895 | |
3896 p = transchar(c); | |
5535 | 3897 if (*p == ' ') |
3898 STRCPY(p, "<20>"); | |
7 | 3899 old_len = (int)STRLEN(showcmd_buf); |
3900 extra_len = (int)STRLEN(p); | |
3901 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3902 if (overflow > 0) | |
1362 | 3903 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3904 old_len - overflow + 1); | |
7 | 3905 STRCAT(showcmd_buf, p); |
3906 | |
3907 if (char_avail()) | |
3908 return FALSE; | |
3909 | |
3910 display_showcmd(); | |
3911 | |
3912 return TRUE; | |
3913 } | |
3914 | |
3915 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3916 add_to_showcmd_c(int c) |
7 | 3917 { |
3918 if (!add_to_showcmd(c)) | |
3919 setcursor(); | |
3920 } | |
3921 | |
3922 /* | |
3923 * Delete 'len' characters from the end of the shown command. | |
3924 */ | |
3925 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3926 del_from_showcmd(int len) |
7 | 3927 { |
3928 int old_len; | |
3929 | |
3930 if (!p_sc) | |
3931 return; | |
3932 | |
3933 old_len = (int)STRLEN(showcmd_buf); | |
3934 if (len > old_len) | |
3935 len = old_len; | |
3936 showcmd_buf[old_len - len] = NUL; | |
3937 | |
3938 if (!char_avail()) | |
3939 display_showcmd(); | |
3940 } | |
3941 | |
3942 /* | |
3943 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3944 * something and there is a partial mapping. | |
3945 */ | |
3946 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3947 push_showcmd(void) |
7 | 3948 { |
3949 if (p_sc) | |
3950 STRCPY(old_showcmd_buf, showcmd_buf); | |
3951 } | |
3952 | |
3953 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3954 pop_showcmd(void) |
7 | 3955 { |
3956 if (!p_sc) | |
3957 return; | |
3958 | |
3959 STRCPY(showcmd_buf, old_showcmd_buf); | |
3960 | |
3961 display_showcmd(); | |
3962 } | |
3963 | |
3964 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3965 display_showcmd(void) |
7 | 3966 { |
3967 int len; | |
3968 | |
3969 cursor_off(); | |
3970 | |
3971 len = (int)STRLEN(showcmd_buf); | |
3972 if (len == 0) | |
3973 showcmd_is_clear = TRUE; | |
3974 else | |
3975 { | |
3976 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3977 showcmd_is_clear = FALSE; | |
3978 } | |
3979 | |
3980 /* | |
1188 | 3981 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3982 * spaces | |
7 | 3983 */ |
3984 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3985 | |
3986 setcursor(); /* put cursor back where it belongs */ | |
3987 } | |
3988 #endif | |
3989 | |
3990 #ifdef FEAT_SCROLLBIND | |
3991 /* | |
3992 * When "check" is FALSE, prepare for commands that scroll the window. | |
3993 * When "check" is TRUE, take care of scroll-binding after the window has | |
3994 * scrolled. Called from normal_cmd() and edit(). | |
3995 */ | |
3996 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3997 do_check_scrollbind(int check) |
7 | 3998 { |
3999 static win_T *old_curwin = NULL; | |
4000 static linenr_T old_topline = 0; | |
4001 #ifdef FEAT_DIFF | |
4002 static int old_topfill = 0; | |
4003 #endif | |
4004 static buf_T *old_buf = NULL; | |
4005 static colnr_T old_leftcol = 0; | |
4006 | |
4007 if (check && curwin->w_p_scb) | |
4008 { | |
4009 /* If a ":syncbind" command was just used, don't scroll, only reset | |
4010 * the values. */ | |
4011 if (did_syncbind) | |
4012 did_syncbind = FALSE; | |
4013 else if (curwin == old_curwin) | |
4014 { | |
4015 /* | |
4016 * Synchronize other windows, as necessary according to | |
4017 * 'scrollbind'. Don't do this after an ":edit" command, except | |
4018 * when 'diff' is set. | |
4019 */ | |
4020 if ((curwin->w_buffer == old_buf | |
4021 #ifdef FEAT_DIFF | |
4022 || curwin->w_p_diff | |
4023 #endif | |
4024 ) | |
4025 && (curwin->w_topline != old_topline | |
4026 #ifdef FEAT_DIFF | |
4027 || curwin->w_topfill != old_topfill | |
4028 #endif | |
4029 || curwin->w_leftcol != old_leftcol)) | |
4030 { | |
4031 check_scrollbind(curwin->w_topline - old_topline, | |
4032 (long)(curwin->w_leftcol - old_leftcol)); | |
4033 } | |
4034 } | |
4035 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4036 { | |
4037 /* | |
4038 * When switching between windows, make sure that the relative | |
4039 * vertical offset is valid for the new window. The relative | |
4040 * offset is invalid whenever another 'scrollbind' window has | |
4041 * scrolled to a point that would force the current window to | |
4042 * scroll past the beginning or end of its buffer. When the | |
4043 * resync is performed, some of the other 'scrollbind' windows may | |
4044 * need to jump so that the current window's relative position is | |
4045 * visible on-screen. | |
4046 */ | |
4047 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4048 } | |
4049 curwin->w_scbind_pos = curwin->w_topline; | |
4050 } | |
4051 | |
4052 old_curwin = curwin; | |
4053 old_topline = curwin->w_topline; | |
4054 #ifdef FEAT_DIFF | |
4055 old_topfill = curwin->w_topfill; | |
4056 #endif | |
4057 old_buf = curwin->w_buffer; | |
4058 old_leftcol = curwin->w_leftcol; | |
4059 } | |
4060 | |
4061 /* | |
4062 * Synchronize any windows that have "scrollbind" set, based on the | |
4063 * number of rows by which the current window has changed | |
4064 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4065 */ | |
4066 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4067 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4068 { |
4069 int want_ver; | |
4070 int want_hor; | |
4071 win_T *old_curwin = curwin; | |
4072 buf_T *old_curbuf = curbuf; | |
4073 int old_VIsual_select = VIsual_select; | |
4074 int old_VIsual_active = VIsual_active; | |
4075 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4076 long topline; | |
4077 long y; | |
4078 | |
4079 /* | |
4080 * check 'scrollopt' string for vertical and horizontal scroll options | |
4081 */ | |
4082 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4083 #ifdef FEAT_DIFF | |
4084 want_ver |= old_curwin->w_p_diff; | |
4085 #endif | |
4086 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4087 | |
4088 /* | |
4089 * loop through the scrollbound windows and scroll accordingly | |
4090 */ | |
4091 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4092 FOR_ALL_WINDOWS(curwin) |
7 | 4093 { |
4094 curbuf = curwin->w_buffer; | |
4095 /* skip original window and windows with 'noscrollbind' */ | |
4096 if (curwin != old_curwin && curwin->w_p_scb) | |
4097 { | |
4098 /* | |
4099 * do the vertical scroll | |
4100 */ | |
4101 if (want_ver) | |
4102 { | |
4103 #ifdef FEAT_DIFF | |
4104 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4105 { | |
4106 diff_set_topline(old_curwin, curwin); | |
4107 } | |
4108 else | |
4109 #endif | |
4110 { | |
4111 curwin->w_scbind_pos += topline_diff; | |
4112 topline = curwin->w_scbind_pos; | |
4113 if (topline > curbuf->b_ml.ml_line_count) | |
4114 topline = curbuf->b_ml.ml_line_count; | |
4115 if (topline < 1) | |
4116 topline = 1; | |
4117 | |
4118 y = topline - curwin->w_topline; | |
4119 if (y > 0) | |
4120 scrollup(y, FALSE); | |
4121 else | |
4122 scrolldown(-y, FALSE); | |
4123 } | |
4124 | |
4125 redraw_later(VALID); | |
4126 cursor_correct(); | |
4127 #ifdef FEAT_WINDOWS | |
4128 curwin->w_redr_status = TRUE; | |
4129 #endif | |
4130 } | |
4131 | |
4132 /* | |
4133 * do the horizontal scroll | |
4134 */ | |
4135 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4136 { | |
4137 curwin->w_leftcol = tgt_leftcol; | |
4138 leftcol_changed(); | |
4139 } | |
4140 } | |
4141 } | |
4142 | |
4143 /* | |
4144 * reset current-window | |
4145 */ | |
4146 VIsual_select = old_VIsual_select; | |
4147 VIsual_active = old_VIsual_active; | |
4148 curwin = old_curwin; | |
4149 curbuf = old_curbuf; | |
4150 } | |
4151 #endif /* #ifdef FEAT_SCROLLBIND */ | |
4152 | |
4153 /* | |
4154 * Command character that's ignored. | |
4155 * 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
|
4156 * xon/xoff. |
7 | 4157 */ |
4158 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4159 nv_ignore(cmdarg_T *cap) |
7 | 4160 { |
226 | 4161 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4162 } |
4163 | |
4164 /* | |
620 | 4165 * Command character that doesn't do anything, but unlike nv_ignore() does |
4166 * start edit(). Used for "startinsert" executed while starting up. | |
4167 */ | |
4168 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4169 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4170 { |
4171 } | |
4172 | |
4173 /* | |
7 | 4174 * Command character doesn't exist. |
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_error(cmdarg_T *cap) |
7 | 4178 { |
4179 clearopbeep(cap->oap); | |
4180 } | |
4181 | |
4182 /* | |
4183 * <Help> and <F1> commands. | |
4184 */ | |
4185 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4186 nv_help(cmdarg_T *cap) |
7 | 4187 { |
4188 if (!checkclearopq(cap->oap)) | |
4189 ex_help(NULL); | |
4190 } | |
4191 | |
4192 /* | |
4193 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4194 */ | |
4195 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4196 nv_addsub(cmdarg_T *cap) |
7 | 4197 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4198 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
|
4199 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4200 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4201 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
|
4202 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
|
4203 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4204 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4205 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4206 nv_operator(cap); |
6868 | 4207 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4208 clearop(cap->oap); |
7 | 4209 } |
4210 | |
4211 /* | |
4212 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4213 */ | |
4214 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4215 nv_page(cmdarg_T *cap) |
7 | 4216 { |
4217 if (!checkclearop(cap->oap)) | |
819 | 4218 { |
4219 #ifdef FEAT_WINDOWS | |
4220 if (mod_mask & MOD_MASK_CTRL) | |
4221 { | |
4222 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4223 if (cap->arg == BACKWARD) | |
4224 goto_tabpage(-(int)cap->count1); | |
4225 else | |
4226 goto_tabpage((int)cap->count0); | |
4227 } | |
4228 else | |
4229 #endif | |
7 | 4230 (void)onepage(cap->arg, cap->count1); |
819 | 4231 } |
7 | 4232 } |
4233 | |
4234 /* | |
4235 * Implementation of "gd" and "gD" command. | |
4236 */ | |
4237 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4238 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4239 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4240 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4241 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4242 { |
4243 int len; | |
503 | 4244 char_u *ptr; |
4245 | |
4246 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
|
4247 || 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
|
4248 == FAIL) |
503 | 4249 clearopbeep(oap); |
4250 #ifdef FEAT_FOLDING | |
4251 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4252 foldOpenCursor(); | |
4253 #endif | |
4254 } | |
4255 | |
4256 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4257 * 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
|
4258 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4259 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4260 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4261 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
|
4262 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4263 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4265 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 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
|
4269 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4270 if (instring != 0) |
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] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4274 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4275 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
|
4276 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4277 instring = line[i]; |
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 |
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 if (incomment) |
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 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4284 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4285 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4286 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4287 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4288 incomment = TRUE; |
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 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4291 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4292 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4293 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4294 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4295 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4296 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4297 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4298 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4299 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4300 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4301 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4302 /* |
523 | 4303 * Search for variable declaration of "ptr[len]". |
4304 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4305 * current file ("gD"). | |
4306 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4307 * Return FAIL when not found. |
4308 */ | |
4309 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4310 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4311 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4312 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4313 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4314 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4315 int flags_arg) /* flags passed to searchit() */ |
503 | 4316 { |
7 | 4317 char_u *pat; |
4318 pos_T old_pos; | |
503 | 4319 pos_T par_pos; |
4320 pos_T found_pos; | |
7 | 4321 int t; |
4322 int save_p_ws; | |
4323 int save_p_scs; | |
503 | 4324 int retval = OK; |
944 | 4325 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4326 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4327 int valid; |
503 | 4328 |
4329 if ((pat = alloc(len + 7)) == NULL) | |
4330 return FAIL; | |
268 | 4331 |
4332 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4333 * and "~" causes trouble. */ | |
4334 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4335 len, ptr); | |
7 | 4336 old_pos = curwin->w_cursor; |
4337 save_p_ws = p_ws; | |
4338 save_p_scs = p_scs; | |
4339 p_ws = FALSE; /* don't wrap around end of file now */ | |
4340 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4341 | |
4342 /* | |
4343 * With "gD" go to line 1. | |
4344 * With "gd" Search back for the start of the current function, then go | |
4345 * back until a blank line. If this fails go to line 1. | |
4346 */ | |
944 | 4347 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4348 { |
4349 setpcmark(); /* Set in findpar() otherwise */ | |
4350 curwin->w_cursor.lnum = 1; | |
539 | 4351 par_pos = curwin->w_cursor; |
7 | 4352 } |
4353 else | |
4354 { | |
539 | 4355 par_pos = curwin->w_cursor; |
7 | 4356 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4357 --curwin->w_cursor.lnum; | |
4358 } | |
4359 curwin->w_cursor.col = 0; | |
4360 | |
4361 /* 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
|
4362 CLEAR_POS(&found_pos); |
503 | 4363 for (;;) |
4364 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4365 valid = FALSE; |
503 | 4366 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
|
4367 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4368 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4369 t = FAIL; /* match after start is failure too */ | |
523 | 4370 |
718 | 4371 if (thisblock && t != FAIL) |
523 | 4372 { |
4373 pos_T *pos; | |
4374 | |
4375 /* Check that the block the match is in doesn't end before the | |
4376 * position where we started the search from. */ | |
4377 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4378 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4379 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4380 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4381 /* 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
|
4382 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4383 curwin->w_cursor = *pos; |
523 | 4384 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4385 } |
523 | 4386 } |
4387 | |
503 | 4388 if (t == FAIL) |
4389 { | |
4390 /* If we previously found a valid position, use it. */ | |
4391 if (found_pos.lnum != 0) | |
4392 { | |
4393 curwin->w_cursor = found_pos; | |
4394 t = OK; | |
4395 } | |
4396 break; | |
4397 } | |
7 | 4398 #ifdef FEAT_COMMENTS |
3562 | 4399 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4400 { |
4401 /* Ignore this line, continue at start of next line. */ | |
4402 ++curwin->w_cursor.lnum; | |
4403 curwin->w_cursor.col = 0; | |
4404 continue; | |
4405 } | |
4406 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4407 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
|
4408 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4409 /* 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
|
4410 * 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
|
4411 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4412 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4413 curwin->w_cursor = found_pos; |
503 | 4414 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4415 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4416 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4417 /* 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
|
4418 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4419 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4420 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4421 { |
4422 /* If we previously found a valid position, use it. */ | |
4423 if (found_pos.lnum != 0) | |
4424 curwin->w_cursor = found_pos; | |
4425 break; | |
4426 } | |
4427 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4428 /* 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
|
4429 * 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
|
4430 * 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
|
4431 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4432 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4433 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4434 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4435 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4436 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4437 /* 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
|
4438 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4439 searchflags &= ~SEARCH_START; |
503 | 4440 } |
4441 | |
4442 if (t == FAIL) | |
4443 { | |
4444 retval = FAIL; | |
7 | 4445 curwin->w_cursor = old_pos; |
4446 } | |
4447 else | |
4448 { | |
4449 curwin->w_set_curswant = TRUE; | |
4450 /* "n" searches forward now */ | |
4451 reset_search_dir(); | |
4452 } | |
4453 | |
4454 vim_free(pat); | |
4455 p_ws = save_p_ws; | |
4456 p_scs = save_p_scs; | |
503 | 4457 |
4458 return retval; | |
7 | 4459 } |
4460 | |
4461 /* | |
4462 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4463 * lines rather than lines in the file. | |
4464 * 'dist' must be positive. | |
4465 * | |
4466 * Return OK if able to move cursor, FAIL otherwise. | |
4467 */ | |
4468 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4469 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4470 { |
4471 int linelen = linetabsize(ml_get_curline()); | |
4472 int retval = OK; | |
4473 int atend = FALSE; | |
4474 int n; | |
4475 int col_off1; /* margin offset for first screen line */ | |
4476 int col_off2; /* margin offset for wrapped screen line */ | |
4477 int width1; /* text width for first screen line */ | |
4478 int width2; /* test width for wrapped screen line */ | |
4479 | |
4480 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4481 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4482 |
4483 col_off1 = curwin_col_off(); | |
4484 col_off2 = col_off1 - curwin_col_off2(); | |
4485 width1 = W_WIDTH(curwin) - col_off1; | |
4486 width2 = W_WIDTH(curwin) - col_off2; | |
6559 | 4487 if (width2 == 0) |
4488 width2 = 1; /* avoid divide by zero */ | |
7 | 4489 |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4490 #ifdef FEAT_WINDOWS |
7 | 4491 if (curwin->w_width != 0) |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4492 #endif |
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4493 { |
7 | 4494 /* |
4495 * Instead of sticking at the last character of the buffer line we | |
4496 * try to stick in the last column of the screen. | |
4497 */ | |
4498 if (curwin->w_curswant == MAXCOL) | |
4499 { | |
4500 atend = TRUE; | |
4501 validate_virtcol(); | |
4502 if (width1 <= 0) | |
4503 curwin->w_curswant = 0; | |
4504 else | |
4505 { | |
4506 curwin->w_curswant = width1 - 1; | |
4507 if (curwin->w_virtcol > curwin->w_curswant) | |
4508 curwin->w_curswant += ((curwin->w_virtcol | |
4509 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4510 } | |
4511 } | |
4512 else | |
4513 { | |
4514 if (linelen > width1) | |
4515 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4516 else | |
4517 n = width1; | |
4518 if (curwin->w_curswant > (colnr_T)n + 1) | |
4519 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4520 * width2; | |
4521 } | |
4522 | |
4523 while (dist--) | |
4524 { | |
4525 if (dir == BACKWARD) | |
4526 { | |
4527 if ((long)curwin->w_curswant >= width2) | |
4528 /* move back within line */ | |
4529 curwin->w_curswant -= width2; | |
4530 else | |
4531 { | |
4532 /* to previous line */ | |
4533 if (curwin->w_cursor.lnum == 1) | |
4534 { | |
4535 retval = FAIL; | |
4536 break; | |
4537 } | |
4538 --curwin->w_cursor.lnum; | |
4539 #ifdef FEAT_FOLDING | |
4540 /* Move to the start of a closed fold. Don't do that when | |
4541 * 'foldopen' contains "all": it will open in a moment. */ | |
4542 if (!(fdo_flags & FDO_ALL)) | |
4543 (void)hasFolding(curwin->w_cursor.lnum, | |
4544 &curwin->w_cursor.lnum, NULL); | |
4545 #endif | |
4546 linelen = linetabsize(ml_get_curline()); | |
4547 if (linelen > width1) | |
4548 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4549 + 1) * width2; | |
4550 } | |
4551 } | |
4552 else /* dir == FORWARD */ | |
4553 { | |
4554 if (linelen > width1) | |
4555 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4556 else | |
4557 n = width1; | |
4558 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4559 /* move forward within line */ | |
4560 curwin->w_curswant += width2; | |
4561 else | |
4562 { | |
4563 /* to next line */ | |
4564 #ifdef FEAT_FOLDING | |
4565 /* Move to the end of a closed fold. */ | |
4566 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4567 &curwin->w_cursor.lnum); | |
4568 #endif | |
4569 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4570 { | |
4571 retval = FAIL; | |
4572 break; | |
4573 } | |
4574 curwin->w_cursor.lnum++; | |
4575 curwin->w_curswant %= width2; | |
2911 | 4576 linelen = linetabsize(ml_get_curline()); |
7 | 4577 } |
4578 } | |
4579 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4580 } |
7 | 4581 |
5600 | 4582 if (virtual_active() && atend) |
4583 coladvance(MAXCOL); | |
4584 else | |
4585 coladvance(curwin->w_curswant); | |
7 | 4586 |
4587 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4588 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4589 { | |
6178 | 4590 colnr_T virtcol; |
4591 | |
7 | 4592 /* |
4593 * Check for landing on a character that got split at the end of the | |
4594 * last line. We want to advance a screenline, not end up in the same | |
4595 * screenline or move two screenlines. | |
4596 */ | |
4597 validate_virtcol(); | |
6178 | 4598 virtcol = curwin->w_virtcol; |
6187 | 4599 # if defined(FEAT_LINEBREAK) |
6178 | 4600 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4601 virtcol -= vim_strsize(p_sbr); | |
6187 | 4602 # endif |
6178 | 4603 |
4604 if (virtcol > curwin->w_curswant | |
7 | 4605 && (curwin->w_curswant < (colnr_T)width1 |
4606 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4607 : ((curwin->w_curswant - width1) % width2 | |
4608 > (colnr_T)width2 / 2))) | |
4609 --curwin->w_cursor.col; | |
4610 } | |
4611 #endif | |
4612 | |
4613 if (atend) | |
4614 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4615 | |
4616 return retval; | |
4617 } | |
4618 | |
4619 #ifdef FEAT_MOUSE | |
4620 /* | |
4621 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4622 * 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
|
4623 * 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
|
4624 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4625 */ |
4626 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4627 nv_mousescroll(cmdarg_T *cap) |
7 | 4628 { |
4162 | 4629 # ifdef FEAT_WINDOWS |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4630 win_T *old_curwin = curwin, *wp; |
7 | 4631 |
4162 | 4632 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4633 { |
4634 int row, col; | |
4635 | |
4636 row = mouse_row; | |
4637 col = mouse_col; | |
4638 | |
4639 /* 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
|
4640 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
|
4641 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
|
4642 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4643 curwin = wp; |
7 | 4644 curbuf = curwin->w_buffer; |
4645 } | |
4646 # endif | |
4647 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4648 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
|
4649 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4650 # 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
|
4651 if (term_use_loop()) |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4652 send_keys_to_term(curbuf->b_term, cap->cmdchar, TRUE); |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4653 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4654 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4655 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
|
4656 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4657 (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
|
4658 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4659 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4660 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4661 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4662 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4663 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4664 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4665 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4666 # ifdef FEAT_GUI |
7 | 4667 else |
4668 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4669 /* 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
|
4670 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4671 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4672 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4673 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4674 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
|
4675 step = W_WIDTH(curwin); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4676 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
|
4677 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4678 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4679 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4680 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4681 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4682 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4683 # endif |
7 | 4684 |
4162 | 4685 # ifdef FEAT_WINDOWS |
7 | 4686 curwin->w_redr_status = TRUE; |
4687 | |
4688 curwin = old_curwin; | |
4689 curbuf = curwin->w_buffer; | |
4690 # endif | |
4691 } | |
4692 | |
4693 /* | |
4694 * Mouse clicks and drags. | |
4695 */ | |
4696 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4697 nv_mouse(cmdarg_T *cap) |
7 | 4698 { |
4699 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4700 } | |
4701 #endif | |
4702 | |
4703 /* | |
4704 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4705 * cap->arg must be TRUE for CTRL-E. | |
4706 */ | |
4707 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4708 nv_scroll_line(cmdarg_T *cap) |
7 | 4709 { |
4710 if (!checkclearop(cap->oap)) | |
4711 scroll_redraw(cap->arg, cap->count1); | |
4712 } | |
4713 | |
4714 /* | |
4715 * Scroll "count" lines up or down, and redraw. | |
4716 */ | |
4717 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4718 scroll_redraw(int up, long count) |
7 | 4719 { |
4720 linenr_T prev_topline = curwin->w_topline; | |
4721 #ifdef FEAT_DIFF | |
4722 int prev_topfill = curwin->w_topfill; | |
4723 #endif | |
4724 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4725 | |
4726 if (up) | |
4727 scrollup(count, TRUE); | |
4728 else | |
4729 scrolldown(count, TRUE); | |
4730 if (p_so) | |
4731 { | |
4732 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4733 * valid, otherwise the screen jumps back at the end of the file. */ | |
4734 cursor_correct(); | |
4735 check_cursor_moved(curwin); | |
4736 curwin->w_valid |= VALID_TOPLINE; | |
4737 | |
4738 /* If moved back to where we were, at least move the cursor, otherwise | |
4739 * we get stuck at one position. Don't move the cursor up if the | |
4740 * first line of the buffer is already on the screen */ | |
4741 while (curwin->w_topline == prev_topline | |
4742 #ifdef FEAT_DIFF | |
4743 && curwin->w_topfill == prev_topfill | |
4744 #endif | |
4745 ) | |
4746 { | |
4747 if (up) | |
4748 { | |
4749 if (curwin->w_cursor.lnum > prev_lnum | |
4750 || cursor_down(1L, FALSE) == FAIL) | |
4751 break; | |
4752 } | |
4753 else | |
4754 { | |
4755 if (curwin->w_cursor.lnum < prev_lnum | |
4756 || prev_topline == 1L | |
4757 || cursor_up(1L, FALSE) == FAIL) | |
4758 break; | |
4759 } | |
4760 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4761 * end of the file. */ | |
4762 check_cursor_moved(curwin); | |
4763 curwin->w_valid |= VALID_TOPLINE; | |
4764 } | |
4765 } | |
4766 if (curwin->w_cursor.lnum != prev_lnum) | |
4767 coladvance(curwin->w_curswant); | |
4768 redraw_later(VALID); | |
4769 } | |
4770 | |
4771 /* | |
4772 * Commands that start with "z". | |
4773 */ | |
4774 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4775 nv_zet(cmdarg_T *cap) |
7 | 4776 { |
4777 long n; | |
4778 colnr_T col; | |
4779 int nchar = cap->nchar; | |
4780 #ifdef FEAT_FOLDING | |
4781 long old_fdl = curwin->w_p_fdl; | |
4782 int old_fen = curwin->w_p_fen; | |
4783 #endif | |
737 | 4784 #ifdef FEAT_SPELL |
710 | 4785 int undo = FALSE; |
4786 #endif | |
7 | 4787 |
4788 if (VIM_ISDIGIT(nchar)) | |
4789 { | |
4790 /* | |
4791 * "z123{nchar}": edit the count before obtaining {nchar} | |
4792 */ | |
4793 if (checkclearop(cap->oap)) | |
4794 return; | |
4795 n = nchar - '0'; | |
4796 for (;;) | |
4797 { | |
4798 #ifdef USE_ON_FLY_SCROLL | |
4799 dont_scroll = TRUE; /* disallow scrolling here */ | |
4800 #endif | |
4801 ++no_mapping; | |
4802 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4803 nchar = plain_vgetc(); |
7 | 4804 LANGMAP_ADJUST(nchar, TRUE); |
4805 --no_mapping; | |
4806 --allow_keys; | |
4807 #ifdef FEAT_CMDL_INFO | |
4808 (void)add_to_showcmd(nchar); | |
4809 #endif | |
4810 if (nchar == K_DEL || nchar == K_KDEL) | |
4811 n /= 10; | |
4812 else if (VIM_ISDIGIT(nchar)) | |
4813 n = n * 10 + (nchar - '0'); | |
4814 else if (nchar == CAR) | |
4815 { | |
4816 #ifdef FEAT_GUI | |
4817 need_mouse_correct = TRUE; | |
4818 #endif | |
4819 win_setheight((int)n); | |
4820 break; | |
4821 } | |
4822 else if (nchar == 'l' | |
4823 || nchar == 'h' | |
4824 || nchar == K_LEFT | |
229 | 4825 || nchar == K_RIGHT) |
7 | 4826 { |
4827 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4828 goto dozet; | |
4829 } | |
4830 else | |
4831 { | |
4832 clearopbeep(cap->oap); | |
4833 break; | |
4834 } | |
4835 } | |
4836 cap->oap->op_type = OP_NOP; | |
4837 return; | |
4838 } | |
4839 | |
4840 dozet: | |
4841 if ( | |
4842 #ifdef FEAT_FOLDING | |
4843 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4844 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4845 * commands. */ | |
4846 cap->nchar != 'f' && cap->nchar != 'F' | |
4847 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4848 && cap->nchar != 'j' && cap->nchar != 'k' | |
4849 && | |
4850 #endif | |
4851 checkclearop(cap->oap)) | |
4852 return; | |
4853 | |
4854 /* | |
4855 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4856 * If line number given, set cursor. | |
4857 */ | |
4858 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4859 && cap->count0 | |
4860 && cap->count0 != curwin->w_cursor.lnum) | |
4861 { | |
4862 setpcmark(); | |
4863 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4864 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4865 else | |
4866 curwin->w_cursor.lnum = cap->count0; | |
22 | 4867 check_cursor_col(); |
7 | 4868 } |
4869 | |
4870 switch (nchar) | |
4871 { | |
4872 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4873 case '+': | |
4874 if (cap->count0 == 0) | |
4875 { | |
4876 /* No count given: put cursor at the line below screen */ | |
4877 validate_botline(); /* make sure w_botline is valid */ | |
4878 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4879 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4880 else | |
4881 curwin->w_cursor.lnum = curwin->w_botline; | |
4882 } | |
4883 /* FALLTHROUGH */ | |
4884 case NL: | |
4885 case CAR: | |
4886 case K_KENTER: | |
4887 beginline(BL_WHITE | BL_FIX); | |
4888 /* FALLTHROUGH */ | |
4889 | |
4890 case 't': scroll_cursor_top(0, TRUE); | |
4891 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4892 set_fraction(curwin); |
7 | 4893 break; |
4894 | |
4895 /* "z." and "zz": put cursor in middle of screen */ | |
4896 case '.': beginline(BL_WHITE | BL_FIX); | |
4897 /* FALLTHROUGH */ | |
4898 | |
4899 case 'z': scroll_cursor_halfway(TRUE); | |
4900 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4901 set_fraction(curwin); |
7 | 4902 break; |
4903 | |
4904 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4905 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4906 * when <count> is at bottom of window, and puts that one at | |
4907 * bottom of window. */ | |
4908 if (cap->count0 != 0) | |
4909 { | |
4910 scroll_cursor_bot(0, TRUE); | |
4911 curwin->w_cursor.lnum = curwin->w_topline; | |
4912 } | |
4913 else if (curwin->w_topline == 1) | |
4914 curwin->w_cursor.lnum = 1; | |
4915 else | |
4916 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4917 /* FALLTHROUGH */ | |
4918 case '-': | |
4919 beginline(BL_WHITE | BL_FIX); | |
4920 /* FALLTHROUGH */ | |
4921 | |
4922 case 'b': scroll_cursor_bot(0, TRUE); | |
4923 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4924 set_fraction(curwin); |
7 | 4925 break; |
4926 | |
4927 /* "zH" - scroll screen right half-page */ | |
4928 case 'H': | |
4929 cap->count1 *= W_WIDTH(curwin) / 2; | |
4930 /* FALLTHROUGH */ | |
4931 | |
4932 /* "zh" - scroll screen to the right */ | |
4933 case 'h': | |
4934 case K_LEFT: | |
4935 if (!curwin->w_p_wrap) | |
4936 { | |
4937 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4938 curwin->w_leftcol = 0; | |
4939 else | |
4940 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4941 leftcol_changed(); | |
4942 } | |
4943 break; | |
4944 | |
4945 /* "zL" - scroll screen left half-page */ | |
4946 case 'L': cap->count1 *= W_WIDTH(curwin) / 2; | |
4947 /* FALLTHROUGH */ | |
4948 | |
4949 /* "zl" - scroll screen to the left */ | |
4950 case 'l': | |
4951 case K_RIGHT: | |
4952 if (!curwin->w_p_wrap) | |
4953 { | |
4954 /* scroll the window left */ | |
4955 curwin->w_leftcol += (colnr_T)cap->count1; | |
4956 leftcol_changed(); | |
4957 } | |
4958 break; | |
4959 | |
4960 /* "zs" - scroll screen, cursor at the start */ | |
4961 case 's': if (!curwin->w_p_wrap) | |
4962 { | |
4963 #ifdef FEAT_FOLDING | |
4964 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4965 col = 0; /* like the cursor is in col 0 */ | |
4966 else | |
4967 #endif | |
4968 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4969 if ((long)col > p_siso) | |
4970 col -= p_siso; | |
4971 else | |
4972 col = 0; | |
4973 if (curwin->w_leftcol != col) | |
4974 { | |
4975 curwin->w_leftcol = col; | |
4976 redraw_later(NOT_VALID); | |
4977 } | |
4978 } | |
4979 break; | |
4980 | |
4981 /* "ze" - scroll screen, cursor at the end */ | |
4982 case 'e': if (!curwin->w_p_wrap) | |
4983 { | |
4984 #ifdef FEAT_FOLDING | |
4985 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4986 col = 0; /* like the cursor is in col 0 */ | |
4987 else | |
4988 #endif | |
4989 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
4990 n = W_WIDTH(curwin) - curwin_col_off(); | |
4991 if ((long)col + p_siso < n) | |
4992 col = 0; | |
4993 else | |
4994 col = col + p_siso - n + 1; | |
4995 if (curwin->w_leftcol != col) | |
4996 { | |
4997 curwin->w_leftcol = col; | |
4998 redraw_later(NOT_VALID); | |
4999 } | |
5000 } | |
5001 break; | |
5002 | |
5003 #ifdef FEAT_FOLDING | |
5004 /* "zF": create fold command */ | |
5005 /* "zf": create fold operator */ | |
5006 case 'F': | |
5007 case 'f': if (foldManualAllowed(TRUE)) | |
5008 { | |
5009 cap->nchar = 'f'; | |
5010 nv_operator(cap); | |
5011 curwin->w_p_fen = TRUE; | |
5012 | |
5013 /* "zF" is like "zfzf" */ | |
5014 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
5015 { | |
5016 nv_operator(cap); | |
5017 finish_op = TRUE; | |
5018 } | |
5019 } | |
5020 else | |
5021 clearopbeep(cap->oap); | |
5022 break; | |
5023 | |
5024 /* "zd": delete fold at cursor */ | |
5025 /* "zD": delete fold at cursor recursively */ | |
5026 case 'd': | |
5027 case 'D': if (foldManualAllowed(FALSE)) | |
5028 { | |
5029 if (VIsual_active) | |
5030 nv_operator(cap); | |
5031 else | |
5032 deleteFold(curwin->w_cursor.lnum, | |
5033 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5034 } | |
5035 break; | |
5036 | |
4352 | 5037 /* "zE": erase all folds */ |
7 | 5038 case 'E': if (foldmethodIsManual(curwin)) |
5039 { | |
5040 clearFolding(curwin); | |
5041 changed_window_setting(); | |
5042 } | |
5043 else if (foldmethodIsMarker(curwin)) | |
5044 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5045 TRUE, FALSE); | |
5046 else | |
5047 EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); | |
5048 break; | |
5049 | |
5050 /* "zn": fold none: reset 'foldenable' */ | |
5051 case 'n': curwin->w_p_fen = FALSE; | |
5052 break; | |
5053 | |
5054 /* "zN": fold Normal: set 'foldenable' */ | |
5055 case 'N': curwin->w_p_fen = TRUE; | |
5056 break; | |
5057 | |
5058 /* "zi": invert folding: toggle 'foldenable' */ | |
5059 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5060 break; | |
5061 | |
5062 /* "za": open closed fold or close open fold at cursor */ | |
5063 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5064 openFold(curwin->w_cursor.lnum, cap->count1); | |
5065 else | |
5066 { | |
5067 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5068 curwin->w_p_fen = TRUE; | |
5069 } | |
5070 break; | |
5071 | |
5072 /* "zA": open fold at cursor recursively */ | |
5073 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5074 openFoldRecurse(curwin->w_cursor.lnum); | |
5075 else | |
5076 { | |
5077 closeFoldRecurse(curwin->w_cursor.lnum); | |
5078 curwin->w_p_fen = TRUE; | |
5079 } | |
5080 break; | |
5081 | |
5082 /* "zo": open fold at cursor or Visual area */ | |
5083 case 'o': if (VIsual_active) | |
5084 nv_operator(cap); | |
5085 else | |
5086 openFold(curwin->w_cursor.lnum, cap->count1); | |
5087 break; | |
5088 | |
5089 /* "zO": open fold recursively */ | |
5090 case 'O': if (VIsual_active) | |
5091 nv_operator(cap); | |
5092 else | |
5093 openFoldRecurse(curwin->w_cursor.lnum); | |
5094 break; | |
5095 | |
5096 /* "zc": close fold at cursor or Visual area */ | |
5097 case 'c': if (VIsual_active) | |
5098 nv_operator(cap); | |
5099 else | |
5100 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5101 curwin->w_p_fen = TRUE; | |
5102 break; | |
5103 | |
5104 /* "zC": close fold recursively */ | |
5105 case 'C': if (VIsual_active) | |
5106 nv_operator(cap); | |
5107 else | |
5108 closeFoldRecurse(curwin->w_cursor.lnum); | |
5109 curwin->w_p_fen = TRUE; | |
5110 break; | |
5111 | |
5112 /* "zv": open folds at the cursor */ | |
5113 case 'v': foldOpenCursor(); | |
5114 break; | |
5115 | |
5116 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5117 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5118 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5119 newFoldLevel(); /* update right now */ |
7 | 5120 foldOpenCursor(); |
5121 break; | |
5122 | |
5123 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5124 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5125 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5126 old_fdl = -1; /* force an update */ |
7 | 5127 break; |
5128 | |
5129 /* "zm": fold more */ | |
5130 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5131 { |
5132 curwin->w_p_fdl -= cap->count1; | |
5133 if (curwin->w_p_fdl < 0) | |
5134 curwin->w_p_fdl = 0; | |
5135 } | |
7 | 5136 old_fdl = -1; /* force an update */ |
5137 curwin->w_p_fen = TRUE; | |
5138 break; | |
5139 | |
5140 /* "zM": close all folds */ | |
5141 case 'M': curwin->w_p_fdl = 0; | |
5142 old_fdl = -1; /* force an update */ | |
5143 curwin->w_p_fen = TRUE; | |
5144 break; | |
5145 | |
5146 /* "zr": reduce folding */ | |
6725 | 5147 case 'r': curwin->w_p_fdl += cap->count1; |
5148 { | |
5149 int d = getDeepestNesting(); | |
5150 | |
5151 if (curwin->w_p_fdl >= d) | |
5152 curwin->w_p_fdl = d; | |
5153 } | |
7 | 5154 break; |
5155 | |
5156 /* "zR": open all folds */ | |
5157 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5158 old_fdl = -1; /* force an update */ | |
5159 break; | |
5160 | |
5161 case 'j': /* "zj" move to next fold downwards */ | |
5162 case 'k': /* "zk" move to next fold upwards */ | |
5163 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5164 cap->count1) == FAIL) | |
5165 clearopbeep(cap->oap); | |
5166 break; | |
5167 | |
5168 #endif /* FEAT_FOLDING */ | |
5169 | |
737 | 5170 #ifdef FEAT_SPELL |
710 | 5171 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5172 ++no_mapping; | |
5173 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5174 nchar = plain_vgetc(); |
710 | 5175 LANGMAP_ADJUST(nchar, TRUE); |
5176 --no_mapping; | |
5177 --allow_keys; | |
5178 #ifdef FEAT_CMDL_INFO | |
5179 (void)add_to_showcmd(nchar); | |
5180 #endif | |
5181 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5182 { | |
5183 clearopbeep(cap->oap); | |
5184 break; | |
5185 } | |
5186 undo = TRUE; | |
5187 /*FALLTHROUGH*/ | |
5188 | |
310 | 5189 case 'g': /* "zg": add good word to word list */ |
5190 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5191 case 'G': /* "zG": add good word to temp word list */ |
5192 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5193 { |
5194 char_u *ptr = NULL; | |
5195 int len; | |
5196 | |
5197 if (checkclearop(cap->oap)) | |
5198 break; | |
5199 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5200 == FAIL) | |
5201 return; | |
501 | 5202 if (ptr == NULL) |
5203 { | |
5204 pos_T pos = curwin->w_cursor; | |
5205 | |
5374 | 5206 /* Find bad word under the cursor. When 'spell' is |
5207 * off this fails and find_ident_under_cursor() is | |
5208 * used below. */ | |
5209 emsg_off++; | |
534 | 5210 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5211 emsg_off--; |
501 | 5212 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5213 ptr = ml_get_pos(&curwin->w_cursor); | |
5214 curwin->w_cursor = pos; | |
5215 } | |
5216 | |
310 | 5217 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5218 FIND_IDENT)) == 0) | |
5219 return; | |
381 | 5220 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5221 (nchar == 'G' || nchar == 'W') |
5222 ? 0 : (int)cap->count1, | |
5223 undo); | |
310 | 5224 } |
316 | 5225 break; |
323 | 5226 |
584 | 5227 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5228 if (!checkclearop(cap->oap)) |
485 | 5229 spell_suggest((int)cap->count0); |
323 | 5230 break; |
310 | 5231 #endif |
5232 | |
7 | 5233 default: clearopbeep(cap->oap); |
5234 } | |
5235 | |
5236 #ifdef FEAT_FOLDING | |
5237 /* Redraw when 'foldenable' changed */ | |
5238 if (old_fen != curwin->w_p_fen) | |
5239 { | |
5240 # ifdef FEAT_DIFF | |
5241 win_T *wp; | |
5242 | |
5243 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5244 { | |
5245 /* Adjust 'foldenable' in diff-synced windows. */ | |
5246 FOR_ALL_WINDOWS(wp) | |
5247 { | |
5248 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5249 { | |
5250 wp->w_p_fen = curwin->w_p_fen; | |
5251 changed_window_setting_win(wp); | |
5252 } | |
5253 } | |
5254 } | |
5255 # endif | |
5256 changed_window_setting(); | |
5257 } | |
5258 | |
5259 /* Redraw when 'foldlevel' changed. */ | |
5260 if (old_fdl != curwin->w_p_fdl) | |
5261 newFoldLevel(); | |
5262 #endif | |
5263 } | |
5264 | |
5265 #ifdef FEAT_GUI | |
5266 /* | |
5267 * Vertical scrollbar movement. | |
5268 */ | |
5269 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5270 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5271 { |
5272 if (cap->oap->op_type != OP_NOP) | |
5273 clearopbeep(cap->oap); | |
5274 | |
5275 /* Even if an operator was pending, we still want to scroll */ | |
5276 gui_do_scroll(); | |
5277 } | |
5278 | |
5279 /* | |
5280 * Horizontal scrollbar movement. | |
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_hor_scrollbar(cmdarg_T *cap) |
7 | 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 scroll */ | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
5289 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5290 } |
5291 #endif | |
5292 | |
690 | 5293 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5294 /* |
5295 * Click in GUI tab. | |
5296 */ | |
5297 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5298 nv_tabline(cmdarg_T *cap) |
685 | 5299 { |
5300 if (cap->oap->op_type != OP_NOP) | |
5301 clearopbeep(cap->oap); | |
5302 | |
5303 /* Even if an operator was pending, we still want to jump tabs. */ | |
5304 goto_tabpage(current_tab); | |
5305 } | |
686 | 5306 |
5307 /* | |
5308 * Selected item in tab line menu. | |
5309 */ | |
5310 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5311 nv_tabmenu(cmdarg_T *cap) |
686 | 5312 { |
5313 if (cap->oap->op_type != OP_NOP) | |
5314 clearopbeep(cap->oap); | |
5315 | |
5316 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5317 handle_tabmenu(); |
5318 } | |
5319 | |
5320 /* | |
5321 * Handle selecting an item of the GUI tab line menu. | |
5322 * Used in Normal and Insert mode. | |
5323 */ | |
5324 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5325 handle_tabmenu(void) |
690 | 5326 { |
686 | 5327 switch (current_tabmenu) |
5328 { | |
5329 case TABLINE_MENU_CLOSE: | |
5330 if (current_tab == 0) | |
5331 do_cmdline_cmd((char_u *)"tabclose"); | |
5332 else | |
5333 { | |
5334 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5335 current_tab); | |
5336 do_cmdline_cmd(IObuff); | |
5337 } | |
5338 break; | |
5339 | |
5340 case TABLINE_MENU_NEW: | |
6631 | 5341 if (current_tab == 0) |
5342 do_cmdline_cmd((char_u *)"$tabnew"); | |
5343 else | |
5344 { | |
5345 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5346 current_tab - 1); | |
5347 do_cmdline_cmd(IObuff); | |
5348 } | |
686 | 5349 break; |
5350 | |
5351 case TABLINE_MENU_OPEN: | |
6631 | 5352 if (current_tab == 0) |
5353 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5354 else | |
5355 { | |
5356 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5357 current_tab - 1); | |
5358 do_cmdline_cmd(IObuff); | |
5359 } | |
686 | 5360 break; |
5361 } | |
5362 } | |
685 | 5363 #endif |
5364 | |
7 | 5365 /* |
5366 * "Q" 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_exmode(cmdarg_T *cap) |
7 | 5370 { |
5371 /* | |
5372 * Ignore 'Q' in Visual mode, just give a beep. | |
5373 */ | |
5374 if (VIsual_active) | |
6949 | 5375 vim_beep(BO_EX); |
5735 | 5376 else if (!checkclearop(cap->oap)) |
7 | 5377 do_exmode(FALSE); |
5378 } | |
5379 | |
5380 /* | |
5381 * Handle a ":" command. | |
5382 */ | |
5383 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5384 nv_colon(cmdarg_T *cap) |
7 | 5385 { |
5386 int old_p_im; | |
4256 | 5387 int cmd_result; |
7 | 5388 |
5389 if (VIsual_active) | |
5390 nv_operator(cap); | |
5391 else | |
5392 { | |
5393 if (cap->oap->op_type != OP_NOP) | |
5394 { | |
5395 /* Using ":" as a movement is characterwise exclusive. */ | |
5396 cap->oap->motion_type = MCHAR; | |
5397 cap->oap->inclusive = FALSE; | |
5398 } | |
5399 else if (cap->count0) | |
5400 { | |
5401 /* translate "count:" into ":.,.+(count - 1)" */ | |
5402 stuffcharReadbuff('.'); | |
5403 if (cap->count0 > 1) | |
5404 { | |
5405 stuffReadbuff((char_u *)",.+"); | |
5406 stuffnumReadbuff((long)cap->count0 - 1L); | |
5407 } | |
5408 } | |
5409 | |
5410 /* When typing, don't type below an old message */ | |
5411 if (KeyTyped) | |
5412 compute_cmdrow(); | |
5413 | |
5414 old_p_im = p_im; | |
5415 | |
5416 /* get a command line and execute it */ | |
4256 | 5417 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5418 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5419 | |
5420 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5421 if (p_im != old_p_im) | |
5422 { | |
5423 if (p_im) | |
5424 restart_edit = 'i'; | |
5425 else | |
5426 restart_edit = 0; | |
5427 } | |
5428 | |
4256 | 5429 if (cmd_result == FAIL) |
5430 /* The Ex command failed, do not execute the operator. */ | |
5431 clearop(cap->oap); | |
5432 else if (cap->oap->op_type != OP_NOP | |
7 | 5433 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5434 || cap->oap->start.col > | |
4256 | 5435 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5436 || did_emsg | |
5437 )) | |
5438 /* The start of the operator has become invalid by the Ex command. | |
5439 */ | |
7 | 5440 clearopbeep(cap->oap); |
5441 } | |
5442 } | |
5443 | |
5444 /* | |
5445 * Handle CTRL-G command. | |
5446 */ | |
5447 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5448 nv_ctrlg(cmdarg_T *cap) |
7 | 5449 { |
5450 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5451 { | |
5452 VIsual_select = !VIsual_select; | |
5453 showmode(); | |
5454 } | |
5735 | 5455 else if (!checkclearop(cap->oap)) |
7 | 5456 /* print full name if count given or :cd used */ |
5457 fileinfo((int)cap->count0, FALSE, TRUE); | |
5458 } | |
5459 | |
5460 /* | |
5461 * Handle CTRL-H <Backspace> command. | |
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_ctrlh(cmdarg_T *cap) |
7 | 5465 { |
5466 if (VIsual_active && VIsual_select) | |
5467 { | |
5468 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5469 v_visop(cap); | |
5470 } | |
5471 else | |
5472 nv_left(cap); | |
5473 } | |
5474 | |
5475 /* | |
5476 * CTRL-L: clear screen and redraw. | |
5477 */ | |
5478 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5479 nv_clear(cmdarg_T *cap) |
7 | 5480 { |
5481 if (!checkclearop(cap->oap)) | |
5482 { | |
5483 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5484 /* | |
5485 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5486 * window resizing, so we cheat and make the user detect it | |
5487 * manually with CTRL-L instead | |
5488 */ | |
5489 ui_get_shellsize(); | |
5490 #endif | |
5491 #ifdef FEAT_SYN_HL | |
5492 /* 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
|
5493 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
|
5494 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5495 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5496 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5497 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5498 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
|
5499 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
|
5500 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5501 # endif |
7 | 5502 #endif |
5503 redraw_later(CLEAR); | |
5504 } | |
5505 } | |
5506 | |
5507 /* | |
5508 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5509 * Otherwise: Go to older pcmark. | |
5510 */ | |
5511 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5512 nv_ctrlo(cmdarg_T *cap) |
7 | 5513 { |
5514 if (VIsual_active && VIsual_select) | |
5515 { | |
5516 VIsual_select = FALSE; | |
5517 showmode(); | |
5518 restart_VIsual_select = 2; /* restart Select mode later */ | |
5519 } | |
5520 else | |
5521 { | |
5522 cap->count1 = -cap->count1; | |
5523 nv_pcmark(cap); | |
5524 } | |
5525 } | |
5526 | |
5527 /* | |
5528 * CTRL-^ command, short for ":e #" | |
5529 */ | |
5530 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5531 nv_hat(cmdarg_T *cap) |
7 | 5532 { |
5533 if (!checkclearopq(cap->oap)) | |
5534 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5535 GETF_SETMARK|GETF_ALT, FALSE); | |
5536 } | |
5537 | |
5538 /* | |
5539 * "Z" commands. | |
5540 */ | |
5541 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5542 nv_Zet(cmdarg_T *cap) |
7 | 5543 { |
5544 if (!checkclearopq(cap->oap)) | |
5545 { | |
5546 switch (cap->nchar) | |
5547 { | |
5548 /* "ZZ": equivalent to ":x". */ | |
5549 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5550 break; | |
5551 | |
5552 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5553 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5554 break; | |
5555 | |
5556 default: clearopbeep(cap->oap); | |
5557 } | |
5558 } | |
5559 } | |
5560 | |
5561 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5562 /* | |
5563 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5564 */ | |
5565 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5566 do_nv_ident(int c1, int c2) |
7 | 5567 { |
5568 oparg_T oa; | |
5569 cmdarg_T ca; | |
5570 | |
5571 clear_oparg(&oa); | |
5572 vim_memset(&ca, 0, sizeof(ca)); | |
5573 ca.oap = &oa; | |
5574 ca.cmdchar = c1; | |
5575 ca.nchar = c2; | |
5576 nv_ident(&ca); | |
5577 } | |
5578 #endif | |
5579 | |
5580 /* | |
5581 * Handle the commands that use the word under the cursor. | |
5582 * [g] CTRL-] :ta to current identifier | |
5583 * [g] 'K' run program for current identifier | |
5584 * [g] '*' / to current identifier or string | |
5585 * [g] '#' ? to current identifier or string | |
5586 * g ']' :tselect for current identifier | |
5587 */ | |
5588 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5589 nv_ident(cmdarg_T *cap) |
7 | 5590 { |
5591 char_u *ptr = NULL; | |
5592 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5593 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5594 char_u *newbuf; |
7 | 5595 char_u *p; |
5596 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
|
5597 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5598 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5599 int n = 0; /* init for GCC */ |
5600 int cmdchar; | |
5601 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5602 int tag_cmd = FALSE; |
7 | 5603 char_u *aux_ptr; |
5604 int isman; | |
5605 int isman_s; | |
5606 | |
5607 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5608 { | |
5609 cmdchar = cap->nchar; | |
5610 g_cmd = TRUE; | |
5611 } | |
5612 else | |
5613 { | |
5614 cmdchar = cap->cmdchar; | |
5615 g_cmd = FALSE; | |
5616 } | |
5617 | |
5618 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5619 cmdchar = '#'; | |
5620 | |
5621 /* | |
5622 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5623 */ | |
5624 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5625 { | |
5626 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5627 return; | |
5628 if (checkclearopq(cap->oap)) | |
5629 return; | |
5630 } | |
5631 | |
5632 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5633 (cmdchar == '*' || cmdchar == '#') | |
5634 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5635 { | |
5636 clearop(cap->oap); | |
5637 return; | |
5638 } | |
5639 | |
5640 /* Allocate buffer to put the command in. Inserting backslashes can | |
5641 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5642 * and some numbers. */ | |
5643 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5644 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5645 || STRCMP(kp, ":help") == 0); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5646 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5647 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
|
5648 buf = alloc(buflen); |
7 | 5649 if (buf == NULL) |
5650 return; | |
5651 buf[0] = NUL; | |
5652 | |
5653 switch (cmdchar) | |
5654 { | |
5655 case '*': | |
5656 case '#': | |
5657 /* | |
5658 * Put cursor at start of word, makes search skip the word | |
5659 * under the cursor. | |
5660 * Call setpcmark() first, so "*``" puts the cursor back where | |
5661 * it was. | |
5662 */ | |
5663 setpcmark(); | |
5664 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5665 | |
5666 if (!g_cmd && vim_iswordp(ptr)) | |
5667 STRCPY(buf, "\\<"); | |
5668 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5669 break; | |
5670 | |
5671 case 'K': | |
5672 if (kp_help) | |
5673 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5674 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5675 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5676 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5677 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
|
5678 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5679 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5680 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5681 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5682 } |
7 | 5683 else |
5684 { | |
1712 | 5685 /* An external command will probably use an argument starting |
5686 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5687 while (*ptr == '-' && n > 0) |
5688 { | |
1712 | 5689 ++ptr; |
1728 | 5690 --n; |
5691 } | |
5692 if (n == 0) | |
5693 { | |
5694 EMSG(_(e_noident)); /* found dashes only */ | |
5695 vim_free(buf); | |
5696 return; | |
5697 } | |
1712 | 5698 |
7 | 5699 /* When a count is given, turn it into a range. Is this |
5700 * really what we want? */ | |
5701 isman = (STRCMP(kp, "man") == 0); | |
5702 isman_s = (STRCMP(kp, "man -s") == 0); | |
5703 if (cap->count0 != 0 && !(isman || isman_s)) | |
5704 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5705 | |
5706 STRCAT(buf, "! "); | |
5707 if (cap->count0 == 0 && isman_s) | |
5708 STRCAT(buf, "man"); | |
5709 else | |
5710 STRCAT(buf, kp); | |
5711 STRCAT(buf, " "); | |
5712 if (cap->count0 != 0 && (isman || isman_s)) | |
5713 { | |
5714 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5715 STRCAT(buf, " "); | |
5716 } | |
5717 } | |
5718 break; | |
5719 | |
5720 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5721 tag_cmd = TRUE; |
7 | 5722 #ifdef FEAT_CSCOPE |
5723 if (p_cst) | |
5724 STRCPY(buf, "cstag "); | |
5725 else | |
5726 #endif | |
5727 STRCPY(buf, "ts "); | |
5728 break; | |
5729 | |
5730 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5731 tag_cmd = TRUE; |
7 | 5732 if (curbuf->b_help) |
5733 STRCPY(buf, "he! "); | |
5734 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5735 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5736 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5737 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5738 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5739 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5740 } |
7 | 5741 } |
5742 | |
5743 /* | |
5744 * Now grab the chars in the identifier | |
5745 */ | |
1712 | 5746 if (cmdchar == 'K' && !kp_help) |
5747 { | |
1728 | 5748 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5749 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5750 /* 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
|
5751 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5752 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5753 /* 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
|
5754 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5755 vim_free(ptr); |
1712 | 5756 if (p == NULL) |
5757 { | |
5758 vim_free(buf); | |
5759 return; | |
5760 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5761 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
|
5762 if (newbuf == NULL) |
1712 | 5763 { |
5764 vim_free(buf); | |
5765 vim_free(p); | |
5766 return; | |
5767 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5768 buf = newbuf; |
1712 | 5769 STRCAT(buf, p); |
5770 vim_free(p); | |
5771 } | |
7 | 5772 else |
1712 | 5773 { |
5774 if (cmdchar == '*') | |
5775 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5776 else if (cmdchar == '#') | |
5777 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5778 else if (tag_cmd) |
2603 | 5779 { |
5780 if (curbuf->b_help) | |
5781 /* ":help" handles unescaped argument */ | |
5782 aux_ptr = (char_u *)""; | |
5783 else | |
5784 aux_ptr = (char_u *)"\\|\"\n["; | |
5785 } | |
1712 | 5786 else |
5787 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5788 | |
5789 p = buf + STRLEN(buf); | |
5790 while (n-- > 0) | |
5791 { | |
5792 /* put a backslash before \ and some others */ | |
5793 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5794 *p++ = '\\'; | |
7 | 5795 #ifdef FEAT_MBYTE |
1712 | 5796 /* When current byte is a part of multibyte character, copy all |
5797 * bytes of that character. */ | |
5798 if (has_mbyte) | |
5799 { | |
5800 int i; | |
5801 int len = (*mb_ptr2len)(ptr) - 1; | |
5802 | |
5803 for (i = 0; i < len && n >= 1; ++i, --n) | |
5804 *p++ = *ptr++; | |
5805 } | |
5806 #endif | |
5807 *p++ = *ptr++; | |
5808 } | |
5809 *p = NUL; | |
5810 } | |
7 | 5811 |
5812 /* | |
5813 * Execute the command. | |
5814 */ | |
5815 if (cmdchar == '*' || cmdchar == '#') | |
5816 { | |
5817 if (!g_cmd && ( | |
5818 #ifdef FEAT_MBYTE | |
5819 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5820 #endif | |
5821 vim_iswordc(ptr[-1]))) | |
5822 STRCAT(buf, "\\>"); | |
5823 #ifdef FEAT_CMDHIST | |
5824 /* put pattern in search history */ | |
2024 | 5825 init_history(); |
7 | 5826 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5827 #endif | |
6620 | 5828 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5829 } |
5830 else | |
5831 do_cmdline_cmd(buf); | |
5832 | |
5833 vim_free(buf); | |
5834 } | |
5835 | |
5836 /* | |
5837 * Get visually selected text, within one line only. | |
5838 * Returns FAIL if more than one line selected. | |
5839 */ | |
344 | 5840 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5841 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5842 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5843 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
|
5844 int *lenp) /* return: length of selected text */ |
7 | 5845 { |
5846 if (VIsual_mode != 'V') | |
5847 unadjust_for_sel(); | |
5848 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5849 { | |
344 | 5850 if (cap != NULL) |
5851 clearopbeep(cap->oap); | |
7 | 5852 return FAIL; |
5853 } | |
5854 if (VIsual_mode == 'V') | |
5855 { | |
5856 *pp = ml_get_curline(); | |
5857 *lenp = (int)STRLEN(*pp); | |
5858 } | |
5859 else | |
5860 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5861 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5862 { |
5863 *pp = ml_get_pos(&curwin->w_cursor); | |
5864 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5865 } | |
5866 else | |
5867 { | |
5868 *pp = ml_get_pos(&VIsual); | |
5869 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5870 } | |
5871 #ifdef FEAT_MBYTE | |
5872 if (has_mbyte) | |
5873 /* Correct the length to include the whole last character. */ | |
474 | 5874 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5875 #endif |
5876 } | |
5877 reset_VIsual_and_resel(); | |
5878 return OK; | |
5879 } | |
5880 | |
5881 /* | |
5882 * CTRL-T: backwards in tag stack | |
5883 */ | |
5884 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5885 nv_tagpop(cmdarg_T *cap) |
7 | 5886 { |
5887 if (!checkclearopq(cap->oap)) | |
5888 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5889 } | |
5890 | |
5891 /* | |
5892 * Handle scrolling command 'H', 'L' and 'M'. | |
5893 */ | |
5894 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5895 nv_scroll(cmdarg_T *cap) |
7 | 5896 { |
5897 int used = 0; | |
5898 long n; | |
5899 #ifdef FEAT_FOLDING | |
5900 linenr_T lnum; | |
5901 #endif | |
5902 int half; | |
5903 | |
5904 cap->oap->motion_type = MLINE; | |
5905 setpcmark(); | |
5906 | |
5907 if (cap->cmdchar == 'L') | |
5908 { | |
5909 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5910 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5911 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5912 curwin->w_cursor.lnum = 1; | |
5913 else | |
9 | 5914 { |
5915 #ifdef FEAT_FOLDING | |
5916 if (hasAnyFolding(curwin)) | |
5917 { | |
5918 /* Count a fold for one screen line. */ | |
5919 for (n = cap->count1 - 1; n > 0 | |
5920 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5921 { | |
5922 (void)hasFolding(curwin->w_cursor.lnum, | |
5923 &curwin->w_cursor.lnum, NULL); | |
5924 --curwin->w_cursor.lnum; | |
5925 } | |
5926 } | |
5927 else | |
5928 #endif | |
5929 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5930 } | |
7 | 5931 } |
5932 else | |
5933 { | |
5934 if (cap->cmdchar == 'M') | |
5935 { | |
5936 #ifdef FEAT_DIFF | |
5937 /* Don't count filler lines above the window. */ | |
5938 used -= diff_check_fill(curwin, curwin->w_topline) | |
5939 - curwin->w_topfill; | |
5940 #endif | |
5941 validate_botline(); /* make sure w_empty_rows is valid */ | |
5942 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5943 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5944 { | |
5945 #ifdef FEAT_DIFF | |
5946 /* Count half he number of filler lines to be "below this | |
5947 * line" and half to be "above the next line". */ | |
5948 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5949 + n) / 2 >= half) | |
5950 { | |
5951 --n; | |
5952 break; | |
5953 } | |
5954 #endif | |
5955 used += plines(curwin->w_topline + n); | |
5956 if (used >= half) | |
5957 break; | |
5958 #ifdef FEAT_FOLDING | |
5959 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5960 n = lnum - curwin->w_topline; | |
5961 #endif | |
5962 } | |
5963 if (n > 0 && used > curwin->w_height) | |
5964 --n; | |
5965 } | |
9 | 5966 else /* (cap->cmdchar == 'H') */ |
5967 { | |
7 | 5968 n = cap->count1 - 1; |
9 | 5969 #ifdef FEAT_FOLDING |
5970 if (hasAnyFolding(curwin)) | |
5971 { | |
5972 /* Count a fold for one screen line. */ | |
5973 lnum = curwin->w_topline; | |
5974 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5975 { | |
7009 | 5976 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5977 ++lnum; |
5978 } | |
5979 n = lnum - curwin->w_topline; | |
5980 } | |
5981 #endif | |
5982 } | |
7 | 5983 curwin->w_cursor.lnum = curwin->w_topline + n; |
5984 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5985 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5986 } | |
5987 | |
5988 cursor_correct(); /* correct for 'so' */ | |
5989 beginline(BL_SOL | BL_FIX); | |
5990 } | |
5991 | |
5992 /* | |
5993 * Cursor right commands. | |
5994 */ | |
5995 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5996 nv_right(cmdarg_T *cap) |
7 | 5997 { |
5998 long n; | |
5735 | 5999 int past_line; |
7 | 6000 |
180 | 6001 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6002 { | |
6003 /* <C-Right> and <S-Right> move a word or WORD right */ | |
6004 if (mod_mask & MOD_MASK_CTRL) | |
6005 cap->arg = TRUE; | |
6006 nv_wordcmd(cap); | |
6007 return; | |
6008 } | |
6009 | |
7 | 6010 cap->oap->motion_type = MCHAR; |
6011 cap->oap->inclusive = FALSE; | |
5735 | 6012 past_line = (VIsual_active && *p_sel != 'o'); |
6013 | |
6014 #ifdef FEAT_VIRTUALEDIT | |
7 | 6015 /* |
5735 | 6016 * In virtual edit mode, there's no such thing as "past_line", as lines |
6017 * are (theoretically) infinitely long. | |
7 | 6018 */ |
6019 if (virtual_active()) | |
5735 | 6020 past_line = 0; |
7 | 6021 #endif |
6022 | |
6023 for (n = cap->count1; n > 0; --n) | |
6024 { | |
5735 | 6025 if ((!past_line && oneright() == FAIL) |
6026 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6027 ) |
7 | 6028 { |
6029 /* | |
714 | 6030 * <Space> wraps to next line if 'whichwrap' has 's'. |
6031 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6032 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6033 */ |
6034 if ( ((cap->cmdchar == ' ' | |
6035 && vim_strchr(p_ww, 's') != NULL) | |
6036 || (cap->cmdchar == 'l' | |
6037 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6038 || (cap->cmdchar == K_RIGHT |
7 | 6039 && vim_strchr(p_ww, '>') != NULL)) |
6040 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6041 { | |
6042 /* When deleting we also count the NL as a character. | |
6043 * Set cap->oap->inclusive when last char in the line is | |
6044 * included, move to next line after that */ | |
714 | 6045 if ( cap->oap->op_type != OP_NOP |
7 | 6046 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6047 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6048 cap->oap->inclusive = TRUE; |
6049 else | |
6050 { | |
6051 ++curwin->w_cursor.lnum; | |
6052 curwin->w_cursor.col = 0; | |
6053 #ifdef FEAT_VIRTUALEDIT | |
6054 curwin->w_cursor.coladd = 0; | |
6055 #endif | |
6056 curwin->w_set_curswant = TRUE; | |
6057 cap->oap->inclusive = FALSE; | |
6058 } | |
6059 continue; | |
6060 } | |
6061 if (cap->oap->op_type == OP_NOP) | |
6062 { | |
6063 /* Only beep and flush if not moved at all */ | |
6064 if (n == cap->count1) | |
6065 beep_flush(); | |
6066 } | |
6067 else | |
6068 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6069 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6070 cap->oap->inclusive = TRUE; |
6071 } | |
6072 break; | |
6073 } | |
5735 | 6074 else if (past_line) |
7 | 6075 { |
6076 curwin->w_set_curswant = TRUE; | |
5735 | 6077 #ifdef FEAT_VIRTUALEDIT |
7 | 6078 if (virtual_active()) |
6079 oneright(); | |
6080 else | |
5735 | 6081 #endif |
6082 { | |
6083 #ifdef FEAT_MBYTE | |
7 | 6084 if (has_mbyte) |
6085 curwin->w_cursor.col += | |
474 | 6086 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6087 else |
5735 | 6088 #endif |
7 | 6089 ++curwin->w_cursor.col; |
6090 } | |
6091 } | |
6092 } | |
6093 #ifdef FEAT_FOLDING | |
6094 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6095 && cap->oap->op_type == OP_NOP) | |
6096 foldOpenCursor(); | |
6097 #endif | |
6098 } | |
6099 | |
6100 /* | |
6101 * Cursor left commands. | |
6102 * | |
6103 * Returns TRUE when operator end should not be adjusted. | |
6104 */ | |
6105 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6106 nv_left(cmdarg_T *cap) |
7 | 6107 { |
6108 long n; | |
6109 | |
180 | 6110 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6111 { | |
6112 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6113 if (mod_mask & MOD_MASK_CTRL) | |
6114 cap->arg = 1; | |
6115 nv_bck_word(cap); | |
6116 return; | |
6117 } | |
6118 | |
7 | 6119 cap->oap->motion_type = MCHAR; |
6120 cap->oap->inclusive = FALSE; | |
6121 for (n = cap->count1; n > 0; --n) | |
6122 { | |
6123 if (oneleft() == FAIL) | |
6124 { | |
6125 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6126 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6127 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6128 */ | |
6129 if ( (((cap->cmdchar == K_BS | |
6130 || cap->cmdchar == Ctrl_H) | |
6131 && vim_strchr(p_ww, 'b') != NULL) | |
6132 || (cap->cmdchar == 'h' | |
6133 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6134 || (cap->cmdchar == K_LEFT |
7 | 6135 && vim_strchr(p_ww, '<') != NULL)) |
6136 && curwin->w_cursor.lnum > 1) | |
6137 { | |
6138 --(curwin->w_cursor.lnum); | |
6139 coladvance((colnr_T)MAXCOL); | |
6140 curwin->w_set_curswant = TRUE; | |
6141 | |
6142 /* When the NL before the first char has to be deleted we | |
6143 * put the cursor on the NUL after the previous line. | |
6144 * This is a very special case, be careful! | |
1469 | 6145 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6146 if ( (cap->oap->op_type == OP_DELETE |
6147 || 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
|
6148 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6149 { |
5682 | 6150 char_u *cp = ml_get_cursor(); |
6151 | |
6152 if (*cp != NUL) | |
6153 { | |
6154 #ifdef FEAT_MBYTE | |
6155 if (has_mbyte) | |
6156 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6157 else | |
6158 #endif | |
6159 ++curwin->w_cursor.col; | |
6160 } | |
7 | 6161 cap->retval |= CA_NO_ADJ_OP_END; |
6162 } | |
6163 continue; | |
6164 } | |
6165 /* Only beep and flush if not moved at all */ | |
6166 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6167 beep_flush(); | |
6168 break; | |
6169 } | |
6170 } | |
6171 #ifdef FEAT_FOLDING | |
6172 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6173 && cap->oap->op_type == OP_NOP) | |
6174 foldOpenCursor(); | |
6175 #endif | |
6176 } | |
6177 | |
6178 /* | |
6179 * Cursor up commands. | |
6180 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6181 */ | |
6182 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6183 nv_up(cmdarg_T *cap) |
7 | 6184 { |
180 | 6185 if (mod_mask & MOD_MASK_SHIFT) |
6186 { | |
6187 /* <S-Up> is page up */ | |
6188 cap->arg = BACKWARD; | |
6189 nv_page(cap); | |
6190 } | |
6191 else | |
6192 { | |
6193 cap->oap->motion_type = MLINE; | |
6194 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6195 clearopbeep(cap->oap); | |
6196 else if (cap->arg) | |
6197 beginline(BL_WHITE | BL_FIX); | |
6198 } | |
7 | 6199 } |
6200 | |
6201 /* | |
6202 * Cursor down commands. | |
6203 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6204 */ | |
6205 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6206 nv_down(cmdarg_T *cap) |
7 | 6207 { |
180 | 6208 if (mod_mask & MOD_MASK_SHIFT) |
6209 { | |
6210 /* <S-Down> is page down */ | |
6211 cap->arg = FORWARD; | |
6212 nv_page(cap); | |
6213 } | |
6214 else | |
7 | 6215 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
6216 /* In a quickfix window a <CR> jumps to the error under the cursor. */ | |
170 | 6217 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
|
6218 { |
643 | 6219 if (curwin->w_llist_ref == NULL) |
6220 do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ | |
6221 else | |
6222 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
|
6223 } |
7 | 6224 else |
6225 #endif | |
6226 { | |
6227 #ifdef FEAT_CMDWIN | |
6228 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6229 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6230 cmdwin_result = CAR; |
6231 else | |
6232 #endif | |
6233 { | |
6234 cap->oap->motion_type = MLINE; | |
6235 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6236 clearopbeep(cap->oap); | |
6237 else if (cap->arg) | |
6238 beginline(BL_WHITE | BL_FIX); | |
6239 } | |
6240 } | |
6241 } | |
6242 | |
6243 #ifdef FEAT_SEARCHPATH | |
6244 /* | |
6245 * Grab the file name under the cursor and edit it. | |
6246 */ | |
6247 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6248 nv_gotofile(cmdarg_T *cap) |
7 | 6249 { |
6250 char_u *ptr; | |
681 | 6251 linenr_T lnum = -1; |
7 | 6252 |
633 | 6253 if (text_locked()) |
7 | 6254 { |
6255 clearopbeep(cap->oap); | |
633 | 6256 text_locked_msg(); |
7 | 6257 return; |
6258 } | |
819 | 6259 #ifdef FEAT_AUTOCMD |
6260 if (curbuf_locked()) | |
6261 { | |
6262 clearop(cap->oap); | |
6263 return; | |
6264 } | |
6265 #endif | |
7 | 6266 |
681 | 6267 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6268 |
6269 if (ptr != NULL) | |
6270 { | |
6271 /* 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
|
6272 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6273 (void)autowrite(curbuf, FALSE); |
7 | 6274 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
|
6275 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
|
6276 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
|
6277 && cap->nchar == 'F' && lnum >= 0) |
681 | 6278 { |
6279 curwin->w_cursor.lnum = lnum; | |
6280 check_cursor_lnum(); | |
6281 beginline(BL_SOL | BL_FIX); | |
6282 } | |
7 | 6283 vim_free(ptr); |
6284 } | |
6285 else | |
6286 clearop(cap->oap); | |
6287 } | |
6288 #endif | |
6289 | |
6290 /* | |
6291 * <End> command: to end of current line or last line. | |
6292 */ | |
6293 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6294 nv_end(cmdarg_T *cap) |
7 | 6295 { |
180 | 6296 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6297 { | |
6298 cap->arg = TRUE; | |
7 | 6299 nv_goto(cap); |
6300 cap->count1 = 1; /* to end of current line */ | |
6301 } | |
6302 nv_dollar(cap); | |
6303 } | |
6304 | |
6305 /* | |
6306 * Handle the "$" command. | |
6307 */ | |
6308 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6309 nv_dollar(cmdarg_T *cap) |
7 | 6310 { |
6311 cap->oap->motion_type = MCHAR; | |
6312 cap->oap->inclusive = TRUE; | |
6313 #ifdef FEAT_VIRTUALEDIT | |
6314 /* In virtual mode when off the edge of a line and an operator | |
6315 * is pending (whew!) keep the cursor where it is. | |
6316 * Otherwise, send it to the end of the line. */ | |
6317 if (!virtual_active() || gchar_cursor() != NUL | |
6318 || cap->oap->op_type == OP_NOP) | |
6319 #endif | |
6320 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6321 if (cursor_down((long)(cap->count1 - 1), | |
6322 cap->oap->op_type == OP_NOP) == FAIL) | |
6323 clearopbeep(cap->oap); | |
6324 #ifdef FEAT_FOLDING | |
6325 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6326 foldOpenCursor(); | |
6327 #endif | |
6328 } | |
6329 | |
6330 /* | |
6331 * Implementation of '?' and '/' commands. | |
6332 * If cap->arg is TRUE don't set PC mark. | |
6333 */ | |
6334 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6335 nv_search(cmdarg_T *cap) |
7 | 6336 { |
6337 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6338 pos_T save_cursor = curwin->w_cursor; |
7 | 6339 |
6340 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6341 { | |
6342 /* Translate "g??" to "g?g?" */ | |
6343 cap->cmdchar = 'g'; | |
6344 cap->nchar = '?'; | |
6345 nv_operator(cap); | |
6346 return; | |
6347 } | |
6348 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6349 /* 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
|
6350 * start position. */ |
7 | 6351 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6352 | |
6353 if (cap->searchbuf == NULL) | |
6354 { | |
6355 clearop(oap); | |
6356 return; | |
6357 } | |
6358 | |
6620 | 6359 (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
|
6360 (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
|
6361 ? 0 : SEARCH_MARK); |
7 | 6362 } |
6363 | |
6364 /* | |
6365 * Handle "N" and "n" commands. | |
6366 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6367 */ | |
6368 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6369 nv_next(cmdarg_T *cap) |
7 | 6370 { |
6620 | 6371 pos_T old = curwin->w_cursor; |
6372 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6373 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6374 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6375 { |
6376 /* Avoid getting stuck on the current cursor position, which can | |
6377 * happen when an offset is given and the cursor is on the last char | |
6378 * in the buffer: Repeat with count + 1. */ | |
6379 cap->count1 += 1; | |
6380 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6381 cap->count1 -= 1; | |
6382 } | |
7 | 6383 } |
6384 | |
6385 /* | |
6386 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6387 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6388 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6389 */ | |
6390 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6391 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6392 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6393 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6394 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6395 int opt) /* extra flags for do_search() */ |
7 | 6396 { |
6397 int i; | |
6398 | |
6399 cap->oap->motion_type = MCHAR; | |
6400 cap->oap->inclusive = FALSE; | |
6401 cap->oap->use_reg_one = TRUE; | |
6402 curwin->w_set_curswant = TRUE; | |
6403 | |
6404 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
|
6405 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6406 if (i == 0) |
6407 clearop(cap->oap); | |
6408 else | |
6409 { | |
6410 if (i == 2) | |
6411 cap->oap->motion_type = MLINE; | |
6412 #ifdef FEAT_VIRTUALEDIT | |
6413 curwin->w_cursor.coladd = 0; | |
6414 #endif | |
6415 #ifdef FEAT_FOLDING | |
6416 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6417 foldOpenCursor(); | |
6418 #endif | |
6419 } | |
6420 | |
6421 /* "/$" will put the cursor after the end of the line, may need to | |
6422 * correct that here */ | |
6423 check_cursor(); | |
6620 | 6424 return i; |
7 | 6425 } |
6426 | |
6427 /* | |
6428 * Character search commands. | |
6429 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6430 * ',' and FALSE for ';'. | |
6431 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6432 */ | |
6433 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6434 nv_csearch(cmdarg_T *cap) |
7 | 6435 { |
6436 int t_cmd; | |
6437 | |
6438 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6439 t_cmd = TRUE; | |
6440 else | |
6441 t_cmd = FALSE; | |
6442 | |
6443 cap->oap->motion_type = MCHAR; | |
6444 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6445 clearopbeep(cap->oap); | |
6446 else | |
6447 { | |
6448 curwin->w_set_curswant = TRUE; | |
6449 #ifdef FEAT_VIRTUALEDIT | |
6450 /* Include a Tab for "tx" and for "dfx". */ | |
6451 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6452 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6453 { | |
6454 colnr_T scol, ecol; | |
6455 | |
6456 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6457 curwin->w_cursor.coladd = ecol - scol; | |
6458 } | |
6459 else | |
6460 curwin->w_cursor.coladd = 0; | |
6461 #endif | |
6462 adjust_for_sel(cap); | |
6463 #ifdef FEAT_FOLDING | |
6464 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6465 foldOpenCursor(); | |
6466 #endif | |
6467 } | |
6468 } | |
6469 | |
6470 /* | |
6471 * "[" and "]" commands. | |
6472 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6473 */ | |
6474 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6475 nv_brackets(cmdarg_T *cap) |
7 | 6476 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6477 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6478 pos_T prev_pos; |
6479 pos_T *pos = NULL; /* init for GCC */ | |
6480 pos_T old_pos; /* cursor position before command */ | |
6481 int flag; | |
6482 long n; | |
6483 int findc; | |
6484 int c; | |
6485 | |
6486 cap->oap->motion_type = MCHAR; | |
6487 cap->oap->inclusive = FALSE; | |
6488 old_pos = curwin->w_cursor; | |
6489 #ifdef FEAT_VIRTUALEDIT | |
6490 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6491 #endif | |
6492 | |
6493 #ifdef FEAT_SEARCHPATH | |
6494 /* | |
6495 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6496 */ | |
6497 if (cap->nchar == 'f') | |
6498 nv_gotofile(cap); | |
6499 else | |
6500 #endif | |
6501 | |
6502 #ifdef FEAT_FIND_ID | |
6503 /* | |
1188 | 6504 * Find the occurrence(s) of the identifier or define under cursor |
6505 * in current and included files or jump to the first occurrence. | |
7 | 6506 * |
6507 * search list jump | |
6508 * fwd bwd fwd bwd fwd bwd | |
6509 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6510 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6511 */ | |
6512 if (vim_strchr((char_u *) | |
6513 #ifdef EBCDIC | |
6514 "iI\005dD\067", | |
6515 #else | |
6516 "iI\011dD\004", | |
6517 #endif | |
6518 cap->nchar) != NULL) | |
6519 { | |
6520 char_u *ptr; | |
6521 int len; | |
6522 | |
6523 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6524 clearop(cap->oap); | |
6525 else | |
6526 { | |
6527 find_pattern_in_path(ptr, 0, len, TRUE, | |
6528 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6529 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6530 cap->count1, | |
6531 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6532 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6533 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6534 (linenr_T)MAXLNUM); | |
6535 curwin->w_set_curswant = TRUE; | |
6536 } | |
6537 } | |
6538 else | |
6539 #endif | |
6540 | |
6541 /* | |
6542 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6543 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6544 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6545 * "[m" or "]m" search for prev/next start of (Java) method. | |
6546 * "[M" or "]M" search for prev/next end of (Java) method. | |
6547 */ | |
6548 if ( (cap->cmdchar == '[' | |
6549 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6550 || (cap->cmdchar == ']' | |
6551 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6552 { | |
6553 if (cap->nchar == '*') | |
6554 cap->nchar = '/'; | |
6555 prev_pos.lnum = 0; | |
6556 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6557 { | |
6558 if (cap->cmdchar == '[') | |
6559 findc = '{'; | |
6560 else | |
6561 findc = '}'; | |
6562 n = 9999; | |
6563 } | |
6564 else | |
6565 { | |
6566 findc = cap->nchar; | |
6567 n = cap->count1; | |
6568 } | |
6569 for ( ; n > 0; --n) | |
6570 { | |
6571 if ((pos = findmatchlimit(cap->oap, findc, | |
6572 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6573 { | |
6574 if (new_pos.lnum == 0) /* nothing found */ | |
6575 { | |
6576 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6577 clearopbeep(cap->oap); | |
6578 } | |
6579 else | |
6580 pos = &new_pos; /* use last one found */ | |
6581 break; | |
6582 } | |
6583 prev_pos = new_pos; | |
6584 curwin->w_cursor = *pos; | |
6585 new_pos = *pos; | |
6586 } | |
6587 curwin->w_cursor = old_pos; | |
6588 | |
6589 /* | |
6590 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6591 * brought us to the match for "[m" and "]M" when inside a method. | |
6592 * Try finding the '{' or '}' we want to be at. | |
6593 * Also repeat for the given count. | |
6594 */ | |
6595 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6596 { | |
6597 /* norm is TRUE for "]M" and "[m" */ | |
6598 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6599 | |
6600 n = cap->count1; | |
6601 /* found a match: we were inside a method */ | |
6602 if (prev_pos.lnum != 0) | |
6603 { | |
6604 pos = &prev_pos; | |
6605 curwin->w_cursor = prev_pos; | |
6606 if (norm) | |
6607 --n; | |
6608 } | |
6609 else | |
6610 pos = NULL; | |
6611 while (n > 0) | |
6612 { | |
6613 for (;;) | |
6614 { | |
6615 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6616 { | |
6617 /* if not found anything, that's an error */ | |
6618 if (pos == NULL) | |
6619 clearopbeep(cap->oap); | |
6620 n = 0; | |
6621 break; | |
6622 } | |
6623 c = gchar_cursor(); | |
6624 if (c == '{' || c == '}') | |
6625 { | |
6626 /* Must have found end/start of class: use it. | |
6627 * Or found the place to be at. */ | |
6628 if ((c == findc && norm) || (n == 1 && !norm)) | |
6629 { | |
6630 new_pos = curwin->w_cursor; | |
6631 pos = &new_pos; | |
6632 n = 0; | |
6633 } | |
6634 /* if no match found at all, we started outside of the | |
6635 * class and we're inside now. Just go on. */ | |
6636 else if (new_pos.lnum == 0) | |
6637 { | |
6638 new_pos = curwin->w_cursor; | |
6639 pos = &new_pos; | |
6640 } | |
6641 /* found start/end of other method: go to match */ | |
6642 else if ((pos = findmatchlimit(cap->oap, findc, | |
6643 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6644 0)) == NULL) | |
6645 n = 0; | |
6646 else | |
6647 curwin->w_cursor = *pos; | |
6648 break; | |
6649 } | |
6650 } | |
6651 --n; | |
6652 } | |
6653 curwin->w_cursor = old_pos; | |
6654 if (pos == NULL && new_pos.lnum != 0) | |
6655 clearopbeep(cap->oap); | |
6656 } | |
6657 if (pos != NULL) | |
6658 { | |
6659 setpcmark(); | |
6660 curwin->w_cursor = *pos; | |
6661 curwin->w_set_curswant = TRUE; | |
6662 #ifdef FEAT_FOLDING | |
6663 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6664 && cap->oap->op_type == OP_NOP) | |
6665 foldOpenCursor(); | |
6666 #endif | |
6667 } | |
6668 } | |
6669 | |
6670 /* | |
6671 * "[[", "[]", "]]" and "][": move to start or end of function | |
6672 */ | |
6673 else if (cap->nchar == '[' || cap->nchar == ']') | |
6674 { | |
6675 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6676 flag = '{'; | |
6677 else | |
6678 flag = '}'; /* "][" or "[]" */ | |
6679 | |
6680 curwin->w_set_curswant = TRUE; | |
6681 /* | |
6682 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6683 * we also stop at '}'. | |
6684 */ | |
503 | 6685 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6686 (cap->oap->op_type != OP_NOP |
6687 && cap->arg == FORWARD && flag == '{'))) | |
6688 clearopbeep(cap->oap); | |
6689 else | |
6690 { | |
6691 if (cap->oap->op_type == OP_NOP) | |
6692 beginline(BL_WHITE | BL_FIX); | |
6693 #ifdef FEAT_FOLDING | |
6694 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6695 foldOpenCursor(); | |
6696 #endif | |
6697 } | |
6698 } | |
6699 | |
6700 /* | |
6701 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6702 */ | |
6703 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6704 { | |
1312 | 6705 if (!checkclearop(cap->oap)) |
7 | 6706 { |
5708 | 6707 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6708 ? FORWARD : BACKWARD; | |
6709 int regname = cap->oap->regname; | |
6710 int was_visual = VIsual_active; | |
6711 int line_count = curbuf->b_ml.ml_line_count; | |
6712 pos_T start, end; | |
6713 | |
6714 if (VIsual_active) | |
6715 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6716 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6717 ? 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
|
6718 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6719 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6720 } | |
6721 # ifdef FEAT_CLIPBOARD | |
6722 adjust_clip_reg(®name); | |
6723 # endif | |
7 | 6724 prep_redo_cmd(cap); |
5708 | 6725 |
6726 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6727 if (was_visual) | |
6728 { | |
6729 VIsual = start; | |
6730 curwin->w_cursor = end; | |
6731 if (dir == BACKWARD) | |
6732 { | |
6733 /* adjust lines */ | |
6734 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6735 curwin->w_cursor.lnum += | |
6736 curbuf->b_ml.ml_line_count - line_count; | |
6737 } | |
6738 | |
6739 VIsual_active = TRUE; | |
6740 if (VIsual_mode == 'V') | |
6741 { | |
6742 /* delete visually selected lines */ | |
6743 cap->cmdchar = 'd'; | |
6744 cap->nchar = NUL; | |
6745 cap->oap->regname = regname; | |
6746 nv_operator(cap); | |
6747 do_pending_operator(cap, 0, FALSE); | |
6748 } | |
6749 if (VIsual_active) | |
6750 { | |
6751 end_visual_mode(); | |
6752 redraw_later(SOME_VALID); | |
6753 } | |
6754 } | |
7 | 6755 } |
6756 } | |
6757 | |
6758 /* | |
6759 * "['", "[`", "]'" and "]`": jump to next mark | |
6760 */ | |
6761 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6762 { | |
6763 pos = &curwin->w_cursor; | |
6764 for (n = cap->count1; n > 0; --n) | |
6765 { | |
6766 prev_pos = *pos; | |
6767 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6768 cap->nchar == '\''); | |
6769 if (pos == NULL) | |
6770 break; | |
6771 } | |
6772 if (pos == NULL) | |
6773 pos = &prev_pos; | |
6774 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6775 } | |
6776 | |
6777 #ifdef FEAT_MOUSE | |
6778 /* | |
6779 * [ or ] followed by a middle mouse click: put selected text with | |
6780 * indent adjustment. Any other button just does as usual. | |
6781 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6782 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6783 { |
6784 (void)do_mouse(cap->oap, cap->nchar, | |
6785 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6786 cap->count1, PUT_FIXINDENT); | |
6787 } | |
6788 #endif /* FEAT_MOUSE */ | |
6789 | |
6790 #ifdef FEAT_FOLDING | |
6791 /* | |
6792 * "[z" and "]z": move to start or end of open fold. | |
6793 */ | |
6794 else if (cap->nchar == 'z') | |
6795 { | |
6796 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6797 cap->count1) == FAIL) | |
6798 clearopbeep(cap->oap); | |
6799 } | |
6800 #endif | |
6801 | |
6802 #ifdef FEAT_DIFF | |
6803 /* | |
6804 * "[c" and "]c": move to next or previous diff-change. | |
6805 */ | |
6806 else if (cap->nchar == 'c') | |
6807 { | |
6808 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6809 cap->count1) == FAIL) | |
6810 clearopbeep(cap->oap); | |
6811 } | |
6812 #endif | |
6813 | |
737 | 6814 #ifdef FEAT_SPELL |
236 | 6815 /* |
6816 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6817 */ | |
6818 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6819 { | |
249 | 6820 setpcmark(); |
6821 for (n = 0; n < cap->count1; ++n) | |
498 | 6822 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6823 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6824 { |
6825 clearopbeep(cap->oap); | |
6826 break; | |
6827 } | |
819 | 6828 # ifdef FEAT_FOLDING |
6829 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6830 foldOpenCursor(); | |
6831 # endif | |
236 | 6832 } |
6833 #endif | |
6834 | |
7 | 6835 /* Not a valid cap->nchar. */ |
6836 else | |
6837 clearopbeep(cap->oap); | |
6838 } | |
6839 | |
6840 /* | |
6841 * Handle Normal mode "%" command. | |
6842 */ | |
6843 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6844 nv_percent(cmdarg_T *cap) |
7 | 6845 { |
6846 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
|
6847 #if defined(FEAT_FOLDING) |
7 | 6848 linenr_T lnum = curwin->w_cursor.lnum; |
6849 #endif | |
6850 | |
6851 cap->oap->inclusive = TRUE; | |
6852 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6853 { | |
6854 if (cap->count0 > 100) | |
6855 clearopbeep(cap->oap); | |
6856 else | |
6857 { | |
6858 cap->oap->motion_type = MLINE; | |
6859 setpcmark(); | |
6860 /* Round up, so CTRL-G will give same value. Watch out for a | |
6861 * large line count, the line number must not go negative! */ | |
6862 if (curbuf->b_ml.ml_line_count > 1000000) | |
6863 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6864 / 100L * cap->count0; | |
6865 else | |
6866 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6867 cap->count0 + 99L) / 100L; | |
6868 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6869 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6870 beginline(BL_SOL | BL_FIX); | |
6871 } | |
6872 } | |
6873 else /* "%" : go to matching paren */ | |
6874 { | |
6875 cap->oap->motion_type = MCHAR; | |
6876 cap->oap->use_reg_one = TRUE; | |
6877 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6878 clearopbeep(cap->oap); | |
6879 else | |
6880 { | |
6881 setpcmark(); | |
6882 curwin->w_cursor = *pos; | |
6883 curwin->w_set_curswant = TRUE; | |
6884 #ifdef FEAT_VIRTUALEDIT | |
6885 curwin->w_cursor.coladd = 0; | |
6886 #endif | |
6887 adjust_for_sel(cap); | |
6888 } | |
6889 } | |
6890 #ifdef FEAT_FOLDING | |
6891 if (cap->oap->op_type == OP_NOP | |
6892 && lnum != curwin->w_cursor.lnum | |
6893 && (fdo_flags & FDO_PERCENT) | |
6894 && KeyTyped) | |
6895 foldOpenCursor(); | |
6896 #endif | |
6897 } | |
6898 | |
6899 /* | |
6900 * Handle "(" and ")" commands. | |
6901 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6902 */ | |
6903 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6904 nv_brace(cmdarg_T *cap) |
7 | 6905 { |
6906 cap->oap->motion_type = MCHAR; | |
6907 cap->oap->use_reg_one = TRUE; | |
620 | 6908 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6909 cap->oap->inclusive = FALSE; | |
7 | 6910 curwin->w_set_curswant = TRUE; |
6911 | |
6912 if (findsent(cap->arg, cap->count1) == FAIL) | |
6913 clearopbeep(cap->oap); | |
6914 else | |
6915 { | |
1505 | 6916 /* Don't leave the cursor on the NUL past end of line. */ |
6917 adjust_cursor(cap->oap); | |
7 | 6918 #ifdef FEAT_VIRTUALEDIT |
6919 curwin->w_cursor.coladd = 0; | |
6920 #endif | |
6921 #ifdef FEAT_FOLDING | |
6922 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6923 foldOpenCursor(); | |
6924 #endif | |
6925 } | |
6926 } | |
6927 | |
6928 /* | |
6929 * "m" command: Mark a position. | |
6930 */ | |
6931 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6932 nv_mark(cmdarg_T *cap) |
7 | 6933 { |
6934 if (!checkclearop(cap->oap)) | |
6935 { | |
6936 if (setmark(cap->nchar) == FAIL) | |
6937 clearopbeep(cap->oap); | |
6938 } | |
6939 } | |
6940 | |
6941 /* | |
6942 * "{" and "}" commands. | |
6943 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6944 */ | |
6945 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6946 nv_findpar(cmdarg_T *cap) |
7 | 6947 { |
6948 cap->oap->motion_type = MCHAR; | |
6949 cap->oap->inclusive = FALSE; | |
6950 cap->oap->use_reg_one = TRUE; | |
6951 curwin->w_set_curswant = TRUE; | |
503 | 6952 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6953 clearopbeep(cap->oap); |
6954 else | |
6955 { | |
6956 #ifdef FEAT_VIRTUALEDIT | |
6957 curwin->w_cursor.coladd = 0; | |
6958 #endif | |
6959 #ifdef FEAT_FOLDING | |
6960 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6961 foldOpenCursor(); | |
6962 #endif | |
6963 } | |
6964 } | |
6965 | |
6966 /* | |
6967 * "u" command: Undo or make lower case. | |
6968 */ | |
6969 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6970 nv_undo(cmdarg_T *cap) |
7 | 6971 { |
5735 | 6972 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6973 { |
6974 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6975 cap->cmdchar = 'g'; | |
6976 cap->nchar = 'u'; | |
6977 nv_operator(cap); | |
6978 } | |
6979 else | |
6980 nv_kundo(cap); | |
6981 } | |
6982 | |
6983 /* | |
6984 * <Undo> command. | |
6985 */ | |
6986 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6987 nv_kundo(cmdarg_T *cap) |
7 | 6988 { |
6989 if (!checkclearopq(cap->oap)) | |
6990 { | |
6991 u_undo((int)cap->count1); | |
6992 curwin->w_set_curswant = TRUE; | |
6993 } | |
6994 } | |
6995 | |
6996 /* | |
6997 * Handle the "r" command. | |
6998 */ | |
6999 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7000 nv_replace(cmdarg_T *cap) |
7 | 7001 { |
7002 char_u *ptr; | |
7003 int had_ctrl_v; | |
7004 long n; | |
7005 | |
7006 if (checkclearop(cap->oap)) | |
7007 return; | |
7008 | |
7009 /* get another character */ | |
7010 if (cap->nchar == Ctrl_V) | |
7011 { | |
7012 had_ctrl_v = Ctrl_V; | |
7013 cap->nchar = get_literal(); | |
7014 /* Don't redo a multibyte character with CTRL-V. */ | |
7015 if (cap->nchar > DEL) | |
7016 had_ctrl_v = NUL; | |
7017 } | |
7018 else | |
7019 had_ctrl_v = NUL; | |
7020 | |
1343 | 7021 /* Abort if the character is a special key. */ |
7022 if (IS_SPECIAL(cap->nchar)) | |
7023 { | |
7024 clearopbeep(cap->oap); | |
7025 return; | |
7026 } | |
7027 | |
7 | 7028 /* Visual mode "r" */ |
7029 if (VIsual_active) | |
7030 { | |
1797 | 7031 if (got_int) |
7032 reset_VIsual(); | |
5428 | 7033 if (had_ctrl_v) |
7034 { | |
7035 if (cap->nchar == '\r') | |
7036 cap->nchar = -1; | |
7037 else if (cap->nchar == '\n') | |
7038 cap->nchar = -2; | |
7039 } | |
7 | 7040 nv_operator(cap); |
7041 return; | |
7042 } | |
7043 | |
7044 #ifdef FEAT_VIRTUALEDIT | |
7045 /* Break tabs, etc. */ | |
7046 if (virtual_active()) | |
7047 { | |
7048 if (u_save_cursor() == FAIL) | |
7049 return; | |
7050 if (gchar_cursor() == NUL) | |
7051 { | |
7052 /* Add extra space and put the cursor on the first one. */ | |
7053 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7054 curwin->w_cursor.col -= cap->count1; | |
7055 } | |
7056 else if (gchar_cursor() == TAB) | |
7057 coladvance_force(getviscol()); | |
7058 } | |
7059 #endif | |
7060 | |
1343 | 7061 /* Abort if not enough characters to replace. */ |
7 | 7062 ptr = ml_get_cursor(); |
1343 | 7063 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7064 #ifdef FEAT_MBYTE |
7065 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7066 #endif | |
7067 ) | |
7068 { | |
7069 clearopbeep(cap->oap); | |
7070 return; | |
7071 } | |
7072 | |
7073 /* | |
7074 * Replacing with a TAB is done by edit() when it is complicated because | |
7075 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7076 * Other characters are done below to avoid problems with things like | |
7077 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7078 */ | |
7079 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7080 { | |
7081 stuffnumReadbuff(cap->count1); | |
7082 stuffcharReadbuff('R'); | |
7083 stuffcharReadbuff('\t'); | |
7084 stuffcharReadbuff(ESC); | |
7085 return; | |
7086 } | |
7087 | |
7088 /* save line for undo */ | |
7089 if (u_save_cursor() == FAIL) | |
7090 return; | |
7091 | |
7092 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7093 { | |
7094 /* | |
7095 * Replace character(s) by a single newline. | |
7096 * Strange vi behaviour: Only one newline is inserted. | |
7097 * Delete the characters here. | |
7098 * Insert the newline with an insert command, takes care of | |
7099 * autoindent. The insert command depends on being on the last | |
7100 * character of a line or not. | |
7101 */ | |
7102 #ifdef FEAT_MBYTE | |
7103 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7104 #else | |
608 | 7105 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7106 #endif |
7107 stuffcharReadbuff('\r'); | |
7108 stuffcharReadbuff(ESC); | |
7109 | |
7110 /* Give 'r' to edit(), to get the redo command right. */ | |
7111 invoke_edit(cap, TRUE, 'r', FALSE); | |
7112 } | |
7113 else | |
7114 { | |
7115 prep_redo(cap->oap->regname, cap->count1, | |
7116 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7117 | |
7118 curbuf->b_op_start = curwin->w_cursor; | |
7119 #ifdef FEAT_MBYTE | |
7120 if (has_mbyte) | |
7121 { | |
7122 int old_State = State; | |
7123 | |
7124 if (cap->ncharC1 != 0) | |
7125 AppendCharToRedobuff(cap->ncharC1); | |
7126 if (cap->ncharC2 != 0) | |
7127 AppendCharToRedobuff(cap->ncharC2); | |
7128 | |
7129 /* This is slow, but it handles replacing a single-byte with a | |
7130 * multi-byte and the other way around. Also handles adding | |
7131 * composing characters for utf-8. */ | |
7132 for (n = cap->count1; n > 0; --n) | |
7133 { | |
7134 State = REPLACE; | |
3501 | 7135 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7136 { | |
7137 int c = ins_copychar(curwin->w_cursor.lnum | |
7138 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7139 if (c != NUL) | |
7140 ins_char(c); | |
7141 else | |
7142 /* will be decremented further down */ | |
7143 ++curwin->w_cursor.col; | |
7144 } | |
7145 else | |
7146 ins_char(cap->nchar); | |
7 | 7147 State = old_State; |
7148 if (cap->ncharC1 != 0) | |
7149 ins_char(cap->ncharC1); | |
7150 if (cap->ncharC2 != 0) | |
7151 ins_char(cap->ncharC2); | |
7152 } | |
7153 } | |
7154 else | |
7155 #endif | |
7156 { | |
7157 /* | |
7158 * Replace the characters within one line. | |
7159 */ | |
7160 for (n = cap->count1; n > 0; --n) | |
7161 { | |
7162 /* | |
7163 * Get ptr again, because u_save and/or showmatch() will have | |
7164 * released the line. At the same time we let know that the | |
7165 * line will be changed. | |
7166 */ | |
7167 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7168 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7169 { | |
7170 int c = ins_copychar(curwin->w_cursor.lnum | |
7171 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7172 if (c != NUL) | |
7173 ptr[curwin->w_cursor.col] = c; | |
7174 } | |
7175 else | |
7176 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7177 if (p_sm && msg_silent == 0) |
7178 showmatch(cap->nchar); | |
7179 ++curwin->w_cursor.col; | |
7180 } | |
7181 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7182 if (netbeans_active()) |
7 | 7183 { |
2210 | 7184 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7185 |
33 | 7186 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7187 (long)cap->count1); |
7 | 7188 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7189 &ptr[start], (int)cap->count1); |
7 | 7190 } |
7191 #endif | |
7192 | |
7193 /* mark the buffer as changed and prepare for displaying */ | |
7194 changed_bytes(curwin->w_cursor.lnum, | |
7195 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7196 } | |
7197 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7198 #ifdef FEAT_MBYTE | |
7199 /* if the character on the left of the current cursor is a multi-byte | |
7200 * character, move two characters left */ | |
7201 if (has_mbyte) | |
7202 mb_adjust_cursor(); | |
7203 #endif | |
7204 curbuf->b_op_end = curwin->w_cursor; | |
7205 curwin->w_set_curswant = TRUE; | |
7206 set_last_insert(cap->nchar); | |
7207 } | |
7208 } | |
7209 | |
7210 /* | |
7211 * 'o': Exchange start and end of Visual area. | |
7212 * 'O': same, but in block mode exchange left and right corners. | |
7213 */ | |
7214 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7215 v_swap_corners(int cmdchar) |
7 | 7216 { |
7217 pos_T old_cursor; | |
7218 colnr_T left, right; | |
7219 | |
7220 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7221 { | |
7222 old_cursor = curwin->w_cursor; | |
7223 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7224 curwin->w_cursor.lnum = VIsual.lnum; | |
7225 coladvance(left); | |
7226 VIsual = curwin->w_cursor; | |
7227 | |
7228 curwin->w_cursor.lnum = old_cursor.lnum; | |
7229 curwin->w_curswant = right; | |
7230 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7231 * right one column */ | |
7232 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7233 ++curwin->w_curswant; | |
7234 coladvance(curwin->w_curswant); | |
7235 if (curwin->w_cursor.col == old_cursor.col | |
7236 #ifdef FEAT_VIRTUALEDIT | |
7237 && (!virtual_active() | |
7238 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7239 #endif | |
7240 ) | |
7241 { | |
7242 curwin->w_cursor.lnum = VIsual.lnum; | |
7243 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7244 ++right; | |
7245 coladvance(right); | |
7246 VIsual = curwin->w_cursor; | |
7247 | |
7248 curwin->w_cursor.lnum = old_cursor.lnum; | |
7249 coladvance(left); | |
7250 curwin->w_curswant = left; | |
7251 } | |
7252 } | |
7253 else | |
7254 { | |
7255 old_cursor = curwin->w_cursor; | |
7256 curwin->w_cursor = VIsual; | |
7257 VIsual = old_cursor; | |
7258 curwin->w_set_curswant = TRUE; | |
7259 } | |
7260 } | |
7261 | |
7262 /* | |
7263 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7264 */ | |
7265 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7266 nv_Replace(cmdarg_T *cap) |
7 | 7267 { |
7268 if (VIsual_active) /* "R" is replace lines */ | |
7269 { | |
7270 cap->cmdchar = 'c'; | |
7271 cap->nchar = NUL; | |
4213 | 7272 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7273 VIsual_mode = 'V'; |
7274 nv_operator(cap); | |
7275 } | |
5735 | 7276 else if (!checkclearopq(cap->oap)) |
7 | 7277 { |
7278 if (!curbuf->b_p_ma) | |
7279 EMSG(_(e_modifiable)); | |
7280 else | |
7281 { | |
7282 #ifdef FEAT_VIRTUALEDIT | |
7283 if (virtual_active()) | |
7284 coladvance(getviscol()); | |
7285 #endif | |
7286 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7287 } | |
7288 } | |
7289 } | |
7290 | |
7291 #ifdef FEAT_VREPLACE | |
7292 /* | |
7293 * "gr". | |
7294 */ | |
7295 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7296 nv_vreplace(cmdarg_T *cap) |
7 | 7297 { |
7298 if (VIsual_active) | |
7299 { | |
7300 cap->cmdchar = 'r'; | |
7301 cap->nchar = cap->extra_char; | |
7302 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7303 } | |
5735 | 7304 else if (!checkclearopq(cap->oap)) |
7 | 7305 { |
7306 if (!curbuf->b_p_ma) | |
7307 EMSG(_(e_modifiable)); | |
7308 else | |
7309 { | |
7310 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7311 cap->extra_char = get_literal(); | |
7312 stuffcharReadbuff(cap->extra_char); | |
7313 stuffcharReadbuff(ESC); | |
7314 # ifdef FEAT_VIRTUALEDIT | |
7315 if (virtual_active()) | |
7316 coladvance(getviscol()); | |
7317 # endif | |
7318 invoke_edit(cap, TRUE, 'v', FALSE); | |
7319 } | |
7320 } | |
7321 } | |
7322 #endif | |
7323 | |
7324 /* | |
7325 * Swap case for "~" command, when it does not work like an operator. | |
7326 */ | |
7327 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7328 n_swapchar(cmdarg_T *cap) |
7 | 7329 { |
7330 long n; | |
7331 pos_T startpos; | |
7332 int did_change = 0; | |
7333 #ifdef FEAT_NETBEANS_INTG | |
7334 pos_T pos; | |
7335 char_u *ptr; | |
7336 int count; | |
7337 #endif | |
7338 | |
7339 if (checkclearopq(cap->oap)) | |
7340 return; | |
7341 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7342 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7343 { |
7344 clearopbeep(cap->oap); | |
7345 return; | |
7346 } | |
7347 | |
7348 prep_redo_cmd(cap); | |
7349 | |
7350 if (u_save_cursor() == FAIL) | |
7351 return; | |
7352 | |
7353 startpos = curwin->w_cursor; | |
7354 #ifdef FEAT_NETBEANS_INTG | |
7355 pos = startpos; | |
7356 #endif | |
7357 for (n = cap->count1; n > 0; --n) | |
7358 { | |
7359 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7360 inc_cursor(); | |
7361 if (gchar_cursor() == NUL) | |
7362 { | |
7363 if (vim_strchr(p_ww, '~') != NULL | |
7364 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7365 { | |
7366 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7367 if (netbeans_active()) |
7 | 7368 { |
7369 if (did_change) | |
7370 { | |
7371 ptr = ml_get(pos.lnum); | |
835 | 7372 count = (int)STRLEN(ptr) - pos.col; |
33 | 7373 netbeans_removed(curbuf, pos.lnum, pos.col, |
7374 (long)count); | |
7 | 7375 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7376 &ptr[pos.col], count); |
7 | 7377 } |
7378 pos.col = 0; | |
7379 pos.lnum++; | |
7380 } | |
7381 #endif | |
7382 ++curwin->w_cursor.lnum; | |
7383 curwin->w_cursor.col = 0; | |
7384 if (n > 1) | |
7385 { | |
7386 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7387 break; | |
7388 u_clearline(); | |
7389 } | |
7390 } | |
7391 else | |
7392 break; | |
7393 } | |
7394 } | |
7395 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7396 if (did_change && netbeans_active()) |
7 | 7397 { |
7398 ptr = ml_get(pos.lnum); | |
7399 count = curwin->w_cursor.col - pos.col; | |
33 | 7400 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7401 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7402 } |
7403 #endif | |
7404 | |
7405 | |
7406 check_cursor(); | |
7407 curwin->w_set_curswant = TRUE; | |
7408 if (did_change) | |
7409 { | |
7410 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7411 0L); | |
7412 curbuf->b_op_start = startpos; | |
7413 curbuf->b_op_end = curwin->w_cursor; | |
7414 if (curbuf->b_op_end.col > 0) | |
7415 --curbuf->b_op_end.col; | |
7416 } | |
7417 } | |
7418 | |
7419 /* | |
7420 * Move cursor to mark. | |
7421 */ | |
7422 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7423 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7424 { |
7425 if (check_mark(pos) == FAIL) | |
7426 clearop(cap->oap); | |
7427 else | |
7428 { | |
7429 if (cap->cmdchar == '\'' | |
7430 || cap->cmdchar == '`' | |
7431 || cap->cmdchar == '[' | |
7432 || cap->cmdchar == ']') | |
7433 setpcmark(); | |
7434 curwin->w_cursor = *pos; | |
7435 if (flag) | |
7436 beginline(BL_WHITE | BL_FIX); | |
7437 else | |
7438 check_cursor(); | |
7439 } | |
7440 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7441 if (cap->cmdchar == '`') | |
7442 cap->oap->use_reg_one = TRUE; | |
7443 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7444 curwin->w_set_curswant = TRUE; | |
7445 } | |
7446 | |
7447 /* | |
7448 * Handle commands that are operators in Visual mode. | |
7449 */ | |
7450 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7451 v_visop(cmdarg_T *cap) |
7 | 7452 { |
7453 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7454 | |
7455 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7456 * the end of the line, and "C" replaces till EOL */ |
7 | 7457 if (isupper(cap->cmdchar)) |
7458 { | |
7459 if (VIsual_mode != Ctrl_V) | |
4213 | 7460 { |
7461 VIsual_mode_orig = VIsual_mode; | |
7 | 7462 VIsual_mode = 'V'; |
4213 | 7463 } |
7 | 7464 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7465 curwin->w_curswant = MAXCOL; | |
7466 } | |
7467 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7468 nv_operator(cap); | |
7469 } | |
7470 | |
7471 /* | |
7472 * "s" and "S" commands. | |
7473 */ | |
7474 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7475 nv_subst(cmdarg_T *cap) |
7 | 7476 { |
7477 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ | |
7478 { | |
7479 if (cap->cmdchar == 'S') | |
4213 | 7480 { |
7481 VIsual_mode_orig = VIsual_mode; | |
7 | 7482 VIsual_mode = 'V'; |
4213 | 7483 } |
7 | 7484 cap->cmdchar = 'c'; |
7485 nv_operator(cap); | |
7486 } | |
7487 else | |
7488 nv_optrans(cap); | |
7489 } | |
7490 | |
7491 /* | |
7492 * Abbreviated commands. | |
7493 */ | |
7494 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7495 nv_abbrev(cmdarg_T *cap) |
7 | 7496 { |
7497 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7498 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7499 | |
7500 /* in Visual mode these commands are operators */ | |
7501 if (VIsual_active) | |
7502 v_visop(cap); | |
7503 else | |
7504 nv_optrans(cap); | |
7505 } | |
7506 | |
7507 /* | |
7508 * Translate a command into another command. | |
7509 */ | |
7510 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7511 nv_optrans(cmdarg_T *cap) |
7 | 7512 { |
7513 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7514 (char_u *)"d$", (char_u *)"c$", | |
7515 (char_u *)"cl", (char_u *)"cc", | |
7516 (char_u *)"yy", (char_u *)":s\r"}; | |
7517 static char_u *str = (char_u *)"xXDCsSY&"; | |
7518 | |
7519 if (!checkclearopq(cap->oap)) | |
7520 { | |
164 | 7521 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7522 * either, because "2." should also not use the count. */ | |
7523 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7524 { | |
7525 cap->oap->start = curwin->w_cursor; | |
7526 cap->oap->op_type = OP_DELETE; | |
1490 | 7527 #ifdef FEAT_EVAL |
7528 set_op_var(OP_DELETE); | |
7529 #endif | |
164 | 7530 cap->count1 = 1; |
7531 nv_dollar(cap); | |
7532 finish_op = TRUE; | |
7533 ResetRedobuff(); | |
7534 AppendCharToRedobuff('D'); | |
7535 } | |
7536 else | |
7537 { | |
7538 if (cap->count0) | |
7539 stuffnumReadbuff(cap->count0); | |
7540 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7541 } | |
7 | 7542 } |
7543 cap->opcount = 0; | |
7544 } | |
7545 | |
7546 /* | |
7547 * "'" and "`" commands. Also for "g'" and "g`". | |
7548 * cap->arg is TRUE for "'" and "g'". | |
7549 */ | |
7550 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7551 nv_gomark(cmdarg_T *cap) |
7 | 7552 { |
7553 pos_T *pos; | |
7554 int c; | |
7555 #ifdef FEAT_FOLDING | |
4017 | 7556 pos_T old_cursor = curwin->w_cursor; |
7 | 7557 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7558 #endif | |
7559 | |
7560 if (cap->cmdchar == 'g') | |
7561 c = cap->extra_char; | |
7562 else | |
7563 c = cap->nchar; | |
7564 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7565 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7566 { | |
7567 if (cap->arg) | |
7568 { | |
7569 check_cursor_lnum(); | |
7570 beginline(BL_WHITE | BL_FIX); | |
7571 } | |
7572 else | |
7573 check_cursor(); | |
7574 } | |
7575 else | |
7576 nv_cursormark(cap, cap->arg, pos); | |
7577 | |
7578 #ifdef FEAT_VIRTUALEDIT | |
7579 /* May need to clear the coladd that a mark includes. */ | |
7580 if (!virtual_active()) | |
7581 curwin->w_cursor.coladd = 0; | |
7582 #endif | |
7583 #ifdef FEAT_FOLDING | |
7584 if (cap->oap->op_type == OP_NOP | |
4057 | 7585 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7586 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7587 && (fdo_flags & FDO_MARK) |
7588 && old_KeyTyped) | |
7589 foldOpenCursor(); | |
7590 #endif | |
7591 } | |
7592 | |
7593 /* | |
7594 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7595 */ | |
7596 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7597 nv_pcmark(cmdarg_T *cap) |
7 | 7598 { |
7599 #ifdef FEAT_JUMPLIST | |
7600 pos_T *pos; | |
7601 # ifdef FEAT_FOLDING | |
7602 linenr_T lnum = curwin->w_cursor.lnum; | |
7603 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7604 # endif | |
7605 | |
7606 if (!checkclearopq(cap->oap)) | |
7607 { | |
7608 if (cap->cmdchar == 'g') | |
7609 pos = movechangelist((int)cap->count1); | |
7610 else | |
7611 pos = movemark((int)cap->count1); | |
7612 if (pos == (pos_T *)-1) /* jump to other file */ | |
7613 { | |
7614 curwin->w_set_curswant = TRUE; | |
7615 check_cursor(); | |
7616 } | |
7617 else if (pos != NULL) /* can jump */ | |
7618 nv_cursormark(cap, FALSE, pos); | |
7619 else if (cap->cmdchar == 'g') | |
7620 { | |
7621 if (curbuf->b_changelistlen == 0) | |
7622 EMSG(_("E664: changelist is empty")); | |
7623 else if (cap->count1 < 0) | |
7624 EMSG(_("E662: At start of changelist")); | |
7625 else | |
7626 EMSG(_("E663: At end of changelist")); | |
7627 } | |
7628 else | |
7629 clearopbeep(cap->oap); | |
7630 # ifdef FEAT_FOLDING | |
7631 if (cap->oap->op_type == OP_NOP | |
7632 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7633 && (fdo_flags & FDO_MARK) | |
7634 && old_KeyTyped) | |
7635 foldOpenCursor(); | |
7636 # endif | |
7637 } | |
7638 #else | |
7639 clearopbeep(cap->oap); | |
7640 #endif | |
7641 } | |
7642 | |
7643 /* | |
7644 * Handle '"' command. | |
7645 */ | |
7646 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7647 nv_regname(cmdarg_T *cap) |
7 | 7648 { |
7649 if (checkclearop(cap->oap)) | |
7650 return; | |
7651 #ifdef FEAT_EVAL | |
7652 if (cap->nchar == '=') | |
7653 cap->nchar = get_expr_register(); | |
7654 #endif | |
7655 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7656 { | |
7657 cap->oap->regname = cap->nchar; | |
7658 cap->opcount = cap->count0; /* remember count before '"' */ | |
7659 #ifdef FEAT_EVAL | |
7660 set_reg_var(cap->oap->regname); | |
7661 #endif | |
7662 } | |
7663 else | |
7664 clearopbeep(cap->oap); | |
7665 } | |
7666 | |
7667 /* | |
7668 * Handle "v", "V" and "CTRL-V" commands. | |
7669 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7670 * is TRUE. | |
167 | 7671 * Handle CTRL-Q just like CTRL-V. |
7 | 7672 */ |
7673 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7674 nv_visual(cmdarg_T *cap) |
7 | 7675 { |
167 | 7676 if (cap->cmdchar == Ctrl_Q) |
7677 cap->cmdchar = Ctrl_V; | |
7678 | |
7 | 7679 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7680 * characterwise, linewise, or blockwise. */ | |
7681 if (cap->oap->op_type != OP_NOP) | |
7682 { | |
7683 cap->oap->motion_force = cap->cmdchar; | |
7684 finish_op = FALSE; /* operator doesn't finish now but later */ | |
7685 return; | |
7686 } | |
7687 | |
7688 VIsual_select = cap->arg; | |
7689 if (VIsual_active) /* change Visual mode */ | |
7690 { | |
7691 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7692 end_visual_mode(); | |
7693 else /* toggle char/block mode */ | |
7694 { /* or char/line mode */ | |
7695 VIsual_mode = cap->cmdchar; | |
7696 showmode(); | |
7697 } | |
7698 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7699 } | |
7700 else /* start Visual mode */ | |
7701 { | |
7702 check_visual_highlight(); | |
3537 | 7703 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7704 { | |
7705 /* use previously selected part */ | |
7 | 7706 VIsual = curwin->w_cursor; |
7707 | |
7708 VIsual_active = TRUE; | |
7709 VIsual_reselect = TRUE; | |
7710 if (!cap->arg) | |
7711 /* start Select mode when 'selectmode' contains "cmd" */ | |
7712 may_start_select('c'); | |
7713 #ifdef FEAT_MOUSE | |
7714 setmouse(); | |
7715 #endif | |
641 | 7716 if (p_smd && msg_silent == 0) |
7 | 7717 redraw_cmdline = TRUE; /* show visual mode later */ |
7718 /* | |
7719 * For V and ^V, we multiply the number of lines even if there | |
7720 * was only one -- webb | |
7721 */ | |
7722 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7723 { | |
7724 curwin->w_cursor.lnum += | |
7725 resel_VIsual_line_count * cap->count0 - 1; | |
7726 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7727 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7728 } | |
7729 VIsual_mode = resel_VIsual_mode; | |
7730 if (VIsual_mode == 'v') | |
7731 { | |
7732 if (resel_VIsual_line_count <= 1) | |
3125 | 7733 { |
7734 validate_virtcol(); | |
7735 curwin->w_curswant = curwin->w_virtcol | |
7736 + resel_VIsual_vcol * cap->count0 - 1; | |
7737 } | |
7 | 7738 else |
3125 | 7739 curwin->w_curswant = resel_VIsual_vcol; |
7740 coladvance(curwin->w_curswant); | |
7 | 7741 } |
3125 | 7742 if (resel_VIsual_vcol == MAXCOL) |
7 | 7743 { |
7744 curwin->w_curswant = MAXCOL; | |
7745 coladvance((colnr_T)MAXCOL); | |
7746 } | |
7747 else if (VIsual_mode == Ctrl_V) | |
7748 { | |
7749 validate_virtcol(); | |
7750 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7751 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7752 coladvance(curwin->w_curswant); |
7753 } | |
7754 else | |
7755 curwin->w_set_curswant = TRUE; | |
7756 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7757 } | |
7758 else | |
7759 { | |
7760 if (!cap->arg) | |
7761 /* start Select mode when 'selectmode' contains "cmd" */ | |
7762 may_start_select('c'); | |
7763 n_start_visual_mode(cap->cmdchar); | |
3537 | 7764 if (VIsual_mode != 'V' && *p_sel == 'e') |
7765 ++cap->count1; /* include one more char */ | |
7766 if (cap->count0 > 0 && --cap->count1 > 0) | |
7767 { | |
7768 /* With a count select that many characters or lines. */ | |
7769 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7770 nv_right(cap); | |
7771 else if (VIsual_mode == 'V') | |
7772 nv_down(cap); | |
7773 } | |
7 | 7774 } |
7775 } | |
7776 } | |
7777 | |
7778 /* | |
7779 * Start selection for Shift-movement keys. | |
7780 */ | |
7781 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7782 start_selection(void) |
7 | 7783 { |
7784 /* if 'selectmode' contains "key", start Select mode */ | |
7785 may_start_select('k'); | |
7786 n_start_visual_mode('v'); | |
7787 } | |
7788 | |
7789 /* | |
7790 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7791 */ | |
7792 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7793 may_start_select(int c) |
7 | 7794 { |
7795 VIsual_select = (stuff_empty() && typebuf_typed() | |
7796 && (vim_strchr(p_slm, c) != NULL)); | |
7797 } | |
7798 | |
7799 /* | |
7800 * Start Visual mode "c". | |
7801 * Should set VIsual_select before calling this. | |
7802 */ | |
7803 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7804 n_start_visual_mode(int c) |
7 | 7805 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7806 #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
|
7807 /* 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
|
7808 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
|
7809 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7810 |
7 | 7811 VIsual_mode = c; |
7812 VIsual_active = TRUE; | |
7813 VIsual_reselect = TRUE; | |
7814 #ifdef FEAT_VIRTUALEDIT | |
7815 /* Corner case: the 0 position in a tab may change when going into | |
7816 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7817 */ | |
7818 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7819 { |
7820 validate_virtcol(); | |
7 | 7821 coladvance(curwin->w_virtcol); |
3742 | 7822 } |
7 | 7823 #endif |
7824 VIsual = curwin->w_cursor; | |
7825 | |
7826 #ifdef FEAT_FOLDING | |
7827 foldAdjustVisual(); | |
7828 #endif | |
7829 | |
7830 #ifdef FEAT_MOUSE | |
7831 setmouse(); | |
7832 #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
|
7833 #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
|
7834 /* 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
|
7835 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
|
7836 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7837 |
641 | 7838 if (p_smd && msg_silent == 0) |
7 | 7839 redraw_cmdline = TRUE; /* show visual mode later */ |
7840 #ifdef FEAT_CLIPBOARD | |
7841 /* Make sure the clipboard gets updated. Needed because start and | |
7842 * end may still be the same, and the selection needs to be owned */ | |
7843 clip_star.vmode = NUL; | |
7844 #endif | |
7845 | |
7846 /* Only need to redraw this line, unless still need to redraw an old | |
7847 * Visual area (when 'lazyredraw' is set). */ | |
7848 if (curwin->w_redr_type < INVERTED) | |
7849 { | |
7850 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7851 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7852 } | |
7853 } | |
7854 | |
7855 | |
7856 /* | |
7857 * CTRL-W: Window commands | |
7858 */ | |
7859 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7860 nv_window(cmdarg_T *cap) |
7 | 7861 { |
7862 #ifdef FEAT_WINDOWS | |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7863 if (cap->nchar == ':') |
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7864 /* "CTRL-W :" is the same as typing ":"; useful in a terminal window */ |
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); |
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7866 else if (!checkclearop(cap->oap)) |
7 | 7867 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7868 #else | |
7869 (void)checkclearop(cap->oap); | |
7870 #endif | |
7871 } | |
7872 | |
7873 /* | |
7874 * CTRL-Z: Suspend | |
7875 */ | |
7876 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7877 nv_suspend(cmdarg_T *cap) |
7 | 7878 { |
7879 clearop(cap->oap); | |
7880 if (VIsual_active) | |
7881 end_visual_mode(); /* stop Visual mode */ | |
7882 do_cmdline_cmd((char_u *)"st"); | |
7883 } | |
7884 | |
7885 /* | |
7886 * Commands starting with "g". | |
7887 */ | |
7888 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7889 nv_g_cmd(cmdarg_T *cap) |
7 | 7890 { |
7891 oparg_T *oap = cap->oap; | |
7892 pos_T tpos; | |
7893 int i; | |
7894 int flag = FALSE; | |
7895 | |
7896 switch (cap->nchar) | |
7897 { | |
6868 | 7898 case Ctrl_A: |
7899 case Ctrl_X: | |
7 | 7900 #ifdef MEM_PROFILE |
7901 /* | |
7902 * "g^A": dump log of used memory. | |
7903 */ | |
6868 | 7904 if (!VIsual_active && cap->nchar == Ctrl_A) |
7905 vim_mem_profile_dump(); | |
7906 else | |
7907 #endif | |
7908 /* | |
7909 * "g^A/g^X": sequentially increment visually selected region | |
7910 */ | |
7911 if (VIsual_active) | |
7912 { | |
7913 cap->arg = TRUE; | |
7914 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7915 cap->nchar = NUL; |
6868 | 7916 nv_addsub(cap); |
7917 } | |
7918 else | |
7919 clearopbeep(oap); | |
7 | 7920 break; |
7921 | |
7922 #ifdef FEAT_VREPLACE | |
7923 /* | |
7924 * "gR": Enter virtual replace mode. | |
7925 */ | |
7926 case 'R': | |
7927 cap->arg = TRUE; | |
7928 nv_Replace(cap); | |
7929 break; | |
7930 | |
7931 case 'r': | |
7932 nv_vreplace(cap); | |
7933 break; | |
7934 #endif | |
7935 | |
7936 case '&': | |
7937 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7938 break; | |
7939 | |
7940 /* | |
7941 * "gv": Reselect the previous Visual area. If Visual already active, | |
7942 * exchange previous and current Visual area. | |
7943 */ | |
7944 case 'v': | |
7945 if (checkclearop(oap)) | |
7946 break; | |
7947 | |
690 | 7948 if ( curbuf->b_visual.vi_start.lnum == 0 |
7949 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7950 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7951 beep_flush(); |
7952 else | |
7953 { | |
7954 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7955 if (VIsual_active) | |
7956 { | |
7957 i = VIsual_mode; | |
690 | 7958 VIsual_mode = curbuf->b_visual.vi_mode; |
7959 curbuf->b_visual.vi_mode = i; | |
7 | 7960 # ifdef FEAT_EVAL |
7961 curbuf->b_visual_mode_eval = i; | |
7962 # endif | |
7963 i = curwin->w_curswant; | |
690 | 7964 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7965 curbuf->b_visual.vi_curswant = i; | |
7966 | |
7967 tpos = curbuf->b_visual.vi_end; | |
7968 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7969 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7970 curbuf->b_visual.vi_start = VIsual; | |
7 | 7971 } |
7972 else | |
7973 { | |
690 | 7974 VIsual_mode = curbuf->b_visual.vi_mode; |
7975 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7976 tpos = curbuf->b_visual.vi_end; | |
7977 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7978 } |
7979 | |
7980 VIsual_active = TRUE; | |
7981 VIsual_reselect = TRUE; | |
7982 | |
7983 /* Set Visual to the start and w_cursor to the end of the Visual | |
7984 * area. Make sure they are on an existing character. */ | |
7985 check_cursor(); | |
7986 VIsual = curwin->w_cursor; | |
7987 curwin->w_cursor = tpos; | |
7988 check_cursor(); | |
7989 update_topline(); | |
7990 /* | |
7991 * When called from normal "g" command: start Select mode when | |
7992 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
7993 * start Select mode. | |
7994 */ | |
7995 if (cap->arg) | |
7996 VIsual_select = TRUE; | |
7997 else | |
7998 may_start_select('c'); | |
7999 #ifdef FEAT_MOUSE | |
8000 setmouse(); | |
8001 #endif | |
8002 #ifdef FEAT_CLIPBOARD | |
8003 /* Make sure the clipboard gets updated. Needed because start and | |
8004 * end are still the same, and the selection needs to be owned */ | |
8005 clip_star.vmode = NUL; | |
8006 #endif | |
8007 redraw_curbuf_later(INVERTED); | |
8008 showmode(); | |
8009 } | |
8010 break; | |
8011 /* | |
8012 * "gV": Don't reselect the previous Visual area after a Select mode | |
8013 * mapping of menu. | |
8014 */ | |
8015 case 'V': | |
8016 VIsual_reselect = FALSE; | |
8017 break; | |
8018 | |
8019 /* | |
8020 * "gh": start Select mode. | |
8021 * "gH": start Select line mode. | |
8022 * "g^H": start Select block mode. | |
8023 */ | |
8024 case K_BS: | |
8025 cap->nchar = Ctrl_H; | |
8026 /* FALLTHROUGH */ | |
8027 case 'h': | |
8028 case 'H': | |
8029 case Ctrl_H: | |
8030 # ifdef EBCDIC | |
8031 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8032 if (cap->nchar == Ctrl_H) | |
8033 cap->cmdchar = Ctrl_V; | |
8034 else | |
8035 # endif | |
8036 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8037 cap->arg = TRUE; | |
8038 nv_visual(cap); | |
8039 break; | |
3701 | 8040 |
8041 /* "gn", "gN" visually select next/previous search match | |
8042 * "gn" selects next match | |
8043 * "gN" selects previous match | |
8044 */ | |
8045 case 'N': | |
8046 case 'n': | |
8047 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8048 clearopbeep(oap); |
3701 | 8049 break; |
7 | 8050 |
8051 /* | |
8052 * "gj" and "gk" two new funny movement keys -- up and down | |
8053 * movement based on *screen* line rather than *file* line. | |
8054 */ | |
8055 case 'j': | |
8056 case K_DOWN: | |
8057 /* with 'nowrap' it works just like the normal "j" command; also when | |
8058 * in a closed fold */ | |
8059 if (!curwin->w_p_wrap | |
8060 #ifdef FEAT_FOLDING | |
8061 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8062 #endif | |
8063 ) | |
8064 { | |
8065 oap->motion_type = MLINE; | |
8066 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8067 } | |
8068 else | |
8069 i = nv_screengo(oap, FORWARD, cap->count1); | |
8070 if (i == FAIL) | |
8071 clearopbeep(oap); | |
8072 break; | |
8073 | |
8074 case 'k': | |
8075 case K_UP: | |
8076 /* with 'nowrap' it works just like the normal "k" command; also when | |
8077 * in a closed fold */ | |
8078 if (!curwin->w_p_wrap | |
8079 #ifdef FEAT_FOLDING | |
8080 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8081 #endif | |
8082 ) | |
8083 { | |
8084 oap->motion_type = MLINE; | |
8085 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8086 } | |
8087 else | |
8088 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8089 if (i == FAIL) | |
8090 clearopbeep(oap); | |
8091 break; | |
8092 | |
8093 /* | |
8094 * "gJ": join two lines without inserting a space. | |
8095 */ | |
8096 case 'J': | |
8097 nv_join(cap); | |
8098 break; | |
8099 | |
8100 /* | |
8101 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8102 * "gm": middle of "g0" and "g$". | |
8103 */ | |
8104 case '^': | |
8105 flag = TRUE; | |
8106 /* FALLTHROUGH */ | |
8107 | |
8108 case '0': | |
8109 case 'm': | |
8110 case K_HOME: | |
8111 case K_KHOME: | |
8112 oap->motion_type = MCHAR; | |
8113 oap->inclusive = FALSE; | |
8114 if (curwin->w_p_wrap | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
8115 #ifdef FEAT_WINDOWS |
7 | 8116 && curwin->w_width != 0 |
8117 #endif | |
8118 ) | |
8119 { | |
8120 int width1 = W_WIDTH(curwin) - curwin_col_off(); | |
8121 int width2 = width1 + curwin_col_off2(); | |
8122 | |
8123 validate_virtcol(); | |
8124 i = 0; | |
8125 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8126 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8127 } | |
8128 else | |
8129 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8130 /* 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
|
8131 * '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
|
8132 * to the left. */ |
7 | 8133 if (cap->nchar == 'm') |
8134 i += (W_WIDTH(curwin) - curwin_col_off() | |
8135 + ((curwin->w_p_wrap && i > 0) | |
8136 ? curwin_col_off2() : 0)) / 2; | |
8137 coladvance((colnr_T)i); | |
8138 if (flag) | |
8139 { | |
8140 do | |
8141 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8142 while (VIM_ISWHITE(i) && oneright() == OK); |
7 | 8143 } |
8144 curwin->w_set_curswant = TRUE; | |
8145 break; | |
8146 | |
8147 case '_': | |
8148 /* "g_": to the last non-blank character in the line or <count> lines | |
8149 * downward. */ | |
8150 cap->oap->motion_type = MCHAR; | |
8151 cap->oap->inclusive = TRUE; | |
8152 curwin->w_curswant = MAXCOL; | |
8153 if (cursor_down((long)(cap->count1 - 1), | |
8154 cap->oap->op_type == OP_NOP) == FAIL) | |
8155 clearopbeep(cap->oap); | |
8156 else | |
8157 { | |
8158 char_u *ptr = ml_get_curline(); | |
8159 | |
8160 /* In Visual mode we may end up after the line. */ | |
8161 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8162 --curwin->w_cursor.col; | |
8163 | |
8164 /* Decrease the cursor column until it's on a non-blank. */ | |
8165 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
|
8166 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8167 --curwin->w_cursor.col; |
8168 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8169 adjust_for_sel(cap); |
7 | 8170 } |
8171 break; | |
8172 | |
8173 case '$': | |
8174 case K_END: | |
8175 case K_KEND: | |
8176 { | |
8177 int col_off = curwin_col_off(); | |
8178 | |
8179 oap->motion_type = MCHAR; | |
8180 oap->inclusive = TRUE; | |
8181 if (curwin->w_p_wrap | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
8182 #ifdef FEAT_WINDOWS |
7 | 8183 && curwin->w_width != 0 |
8184 #endif | |
8185 ) | |
8186 { | |
8187 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8188 if (cap->count1 == 1) | |
8189 { | |
8190 int width1 = W_WIDTH(curwin) - col_off; | |
8191 int width2 = width1 + curwin_col_off2(); | |
8192 | |
8193 validate_virtcol(); | |
8194 i = width1 - 1; | |
8195 if (curwin->w_virtcol >= (colnr_T)width1) | |
8196 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8197 * width2; | |
8198 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8199 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8200 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8201 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8202 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8203 curwin->w_set_curswant = FALSE; |
7 | 8204 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8205 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8206 { | |
8207 /* | |
8208 * Check for landing on a character that got split at | |
8209 * the end of the line. We do not want to advance to | |
8210 * the next screen line. | |
8211 */ | |
8212 if (curwin->w_virtcol > (colnr_T)i) | |
8213 --curwin->w_cursor.col; | |
8214 } | |
8215 #endif | |
8216 } | |
8217 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8218 clearopbeep(oap); | |
8219 } | |
8220 else | |
8221 { | |
8222 i = curwin->w_leftcol + W_WIDTH(curwin) - col_off - 1; | |
8223 coladvance((colnr_T)i); | |
40 | 8224 |
8225 /* Make sure we stick in this column. */ | |
8226 validate_virtcol(); | |
8227 curwin->w_curswant = curwin->w_virtcol; | |
8228 curwin->w_set_curswant = FALSE; | |
7 | 8229 } |
8230 } | |
8231 break; | |
8232 | |
8233 /* | |
8234 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8235 */ | |
8236 case '*': | |
8237 case '#': | |
8238 #if POUND != '#' | |
8239 case POUND: /* pound sign (sometimes equal to '#') */ | |
8240 #endif | |
8241 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8242 case ']': /* :tselect for current identifier */ | |
8243 nv_ident(cap); | |
8244 break; | |
8245 | |
8246 /* | |
8247 * ge and gE: go back to end of word | |
8248 */ | |
8249 case 'e': | |
8250 case 'E': | |
8251 oap->motion_type = MCHAR; | |
8252 curwin->w_set_curswant = TRUE; | |
8253 oap->inclusive = TRUE; | |
8254 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8255 clearopbeep(oap); | |
8256 break; | |
8257 | |
8258 /* | |
8259 * "g CTRL-G": display info about cursor position | |
8260 */ | |
8261 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8262 cursor_pos_info(NULL); |
7 | 8263 break; |
8264 | |
8265 /* | |
8266 * "gi": start Insert at the last position. | |
8267 */ | |
8268 case 'i': | |
8269 if (curbuf->b_last_insert.lnum != 0) | |
8270 { | |
8271 curwin->w_cursor = curbuf->b_last_insert; | |
8272 check_cursor_lnum(); | |
8273 i = (int)STRLEN(ml_get_curline()); | |
8274 if (curwin->w_cursor.col > (colnr_T)i) | |
8275 { | |
8276 #ifdef FEAT_VIRTUALEDIT | |
8277 if (virtual_active()) | |
8278 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8279 #endif | |
8280 curwin->w_cursor.col = i; | |
8281 } | |
8282 } | |
8283 cap->cmdchar = 'i'; | |
8284 nv_edit(cap); | |
8285 break; | |
8286 | |
8287 /* | |
8288 * "gI": Start insert in column 1. | |
8289 */ | |
8290 case 'I': | |
8291 beginline(0); | |
8292 if (!checkclearopq(oap)) | |
8293 invoke_edit(cap, FALSE, 'g', FALSE); | |
8294 break; | |
8295 | |
8296 #ifdef FEAT_SEARCHPATH | |
8297 /* | |
8298 * "gf": goto file, edit file under cursor | |
8299 * "]f" and "[f": can also be used. | |
8300 */ | |
8301 case 'f': | |
681 | 8302 case 'F': |
7 | 8303 nv_gotofile(cap); |
8304 break; | |
8305 #endif | |
8306 | |
8307 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8308 case '\'': | |
8309 cap->arg = TRUE; | |
8310 /*FALLTHROUGH*/ | |
8311 case '`': | |
8312 nv_gomark(cap); | |
8313 break; | |
8314 | |
8315 /* | |
8316 * "gs": Goto sleep. | |
8317 */ | |
8318 case 's': | |
8319 do_sleep(cap->count1 * 1000L); | |
8320 break; | |
8321 | |
8322 /* | |
8323 * "ga": Display the ascii value of the character under the | |
8324 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8325 */ | |
8326 case 'a': | |
8327 do_ascii(NULL); | |
8328 break; | |
8329 | |
8330 #ifdef FEAT_MBYTE | |
8331 /* | |
8332 * "g8": Display the bytes used for the UTF-8 character under the | |
8333 * cursor. It is displayed in hex. | |
775 | 8334 * "8g8" finds illegal byte sequence. |
7 | 8335 */ |
8336 case '8': | |
775 | 8337 if (cap->count0 == 8) |
8338 utf_find_illegal(); | |
8339 else | |
8340 show_utf8(); | |
7 | 8341 break; |
8342 #endif | |
8343 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8344 /* "g<": show scrollback text */ |
447 | 8345 case '<': |
8346 show_sb_text(); | |
8347 break; | |
8348 | |
7 | 8349 /* |
8350 * "gg": Goto the first line in file. With a count it goes to | |
8351 * that line number like for "G". -- webb | |
8352 */ | |
8353 case 'g': | |
8354 cap->arg = FALSE; | |
8355 nv_goto(cap); | |
8356 break; | |
8357 | |
8358 /* | |
8359 * Two-character operators: | |
8360 * "gq" Format text | |
8361 * "gw" Format text and keep cursor position | |
8362 * "g~" Toggle the case of the text. | |
8363 * "gu" Change text to lower case. | |
8364 * "gU" Change text to upper case. | |
8365 * "g?" rot13 encoding | |
602 | 8366 * "g@" call 'operatorfunc' |
7 | 8367 */ |
8368 case 'q': | |
8369 case 'w': | |
8370 oap->cursor_start = curwin->w_cursor; | |
8371 /*FALLTHROUGH*/ | |
8372 case '~': | |
8373 case 'u': | |
8374 case 'U': | |
8375 case '?': | |
602 | 8376 case '@': |
7 | 8377 nv_operator(cap); |
8378 break; | |
8379 | |
8380 /* | |
1188 | 8381 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8382 * current function |
8383 * "gD": idem, but in the current file. | |
8384 */ | |
8385 case 'd': | |
8386 case 'D': | |
523 | 8387 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8388 break; |
8389 | |
8390 #ifdef FEAT_MOUSE | |
8391 /* | |
8392 * g<*Mouse> : <C-*mouse> | |
8393 */ | |
8394 case K_MIDDLEMOUSE: | |
8395 case K_MIDDLEDRAG: | |
8396 case K_MIDDLERELEASE: | |
8397 case K_LEFTMOUSE: | |
8398 case K_LEFTDRAG: | |
8399 case K_LEFTRELEASE: | |
8400 case K_RIGHTMOUSE: | |
8401 case K_RIGHTDRAG: | |
8402 case K_RIGHTRELEASE: | |
8403 case K_X1MOUSE: | |
8404 case K_X1DRAG: | |
8405 case K_X1RELEASE: | |
8406 case K_X2MOUSE: | |
8407 case K_X2DRAG: | |
8408 case K_X2RELEASE: | |
8409 mod_mask = MOD_MASK_CTRL; | |
8410 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8411 break; | |
8412 #endif | |
8413 | |
8414 case K_IGNORE: | |
8415 break; | |
8416 | |
8417 /* | |
8418 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8419 */ | |
8420 case 'p': | |
8421 case 'P': | |
8422 nv_put(cap); | |
8423 break; | |
8424 | |
8425 #ifdef FEAT_BYTEOFF | |
8426 /* "go": goto byte count from start of buffer */ | |
8427 case 'o': | |
8428 goto_byte(cap->count0); | |
8429 break; | |
8430 #endif | |
8431 | |
8432 /* "gQ": improved Ex mode */ | |
8433 case 'Q': | |
633 | 8434 if (text_locked()) |
7 | 8435 { |
8436 clearopbeep(cap->oap); | |
633 | 8437 text_locked_msg(); |
7 | 8438 break; |
8439 } | |
631 | 8440 |
7 | 8441 if (!checkclearopq(oap)) |
8442 do_exmode(TRUE); | |
8443 break; | |
8444 | |
8445 #ifdef FEAT_JUMPLIST | |
8446 case ',': | |
8447 nv_pcmark(cap); | |
8448 break; | |
8449 | |
8450 case ';': | |
8451 cap->count1 = -cap->count1; | |
8452 nv_pcmark(cap); | |
8453 break; | |
8454 #endif | |
8455 | |
667 | 8456 #ifdef FEAT_WINDOWS |
8457 case 't': | |
3630 | 8458 if (!checkclearop(oap)) |
8459 goto_tabpage((int)cap->count0); | |
667 | 8460 break; |
682 | 8461 case 'T': |
3630 | 8462 if (!checkclearop(oap)) |
8463 goto_tabpage(-(int)cap->count1); | |
682 | 8464 break; |
667 | 8465 #endif |
8466 | |
750 | 8467 case '+': |
8468 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8469 if (!checkclearopq(oap)) | |
771 | 8470 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
|
8471 FALSE, FALSE, FALSE); |
750 | 8472 break; |
8473 | |
7 | 8474 default: |
8475 clearopbeep(oap); | |
8476 break; | |
8477 } | |
8478 } | |
8479 | |
8480 /* | |
8481 * Handle "o" and "O" commands. | |
8482 */ | |
8483 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8484 n_opencmd(cmdarg_T *cap) |
7 | 8485 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8486 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8487 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8488 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8489 |
7 | 8490 if (!checkclearopq(cap->oap)) |
8491 { | |
8492 #ifdef FEAT_FOLDING | |
8493 if (cap->cmdchar == 'O') | |
8494 /* Open above the first line of a folded sequence of lines */ | |
8495 (void)hasFolding(curwin->w_cursor.lnum, | |
8496 &curwin->w_cursor.lnum, NULL); | |
8497 else | |
8498 /* Open below the last line of a folded sequence of lines */ | |
8499 (void)hasFolding(curwin->w_cursor.lnum, | |
8500 NULL, &curwin->w_cursor.lnum); | |
8501 #endif | |
8502 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8503 (cap->cmdchar == 'O' ? 1 : 0)), | |
8504 (linenr_T)(curwin->w_cursor.lnum + | |
8505 (cap->cmdchar == 'o' ? 1 : 0)) | |
8506 ) == OK | |
8507 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8508 #ifdef FEAT_COMMENTS | |
8509 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8510 #endif | |
8511 0, 0)) | |
8512 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8513 #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
|
8514 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
|
8515 update_single_line(curwin, oldline); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8516 #endif |
164 | 8517 /* When '#' is in 'cpoptions' ignore the count. */ |
8518 if (vim_strchr(p_cpo, CPO_HASH) != NULL) | |
8519 cap->count1 = 1; | |
6834 | 8520 #ifdef FEAT_SYN_HL |
6821 | 8521 if (curwin->w_p_cul) |
8522 /* force redraw of cursorline */ | |
8523 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8524 #endif |
7 | 8525 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8526 } | |
8527 } | |
8528 } | |
8529 | |
8530 /* | |
8531 * "." command: redo last change. | |
8532 */ | |
8533 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8534 nv_dot(cmdarg_T *cap) |
7 | 8535 { |
8536 if (!checkclearopq(cap->oap)) | |
8537 { | |
8538 /* | |
8539 * If "restart_edit" is TRUE, the last but one command is repeated | |
8540 * instead of the last command (inserting text). This is used for | |
8541 * CTRL-O <.> in insert mode. | |
8542 */ | |
8543 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8544 clearopbeep(cap->oap); | |
8545 } | |
8546 } | |
8547 | |
8548 /* | |
8549 * CTRL-R: undo undo | |
8550 */ | |
8551 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8552 nv_redo(cmdarg_T *cap) |
7 | 8553 { |
8554 if (!checkclearopq(cap->oap)) | |
8555 { | |
8556 u_redo((int)cap->count1); | |
8557 curwin->w_set_curswant = TRUE; | |
8558 } | |
8559 } | |
8560 | |
8561 /* | |
8562 * Handle "U" command. | |
8563 */ | |
8564 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8565 nv_Undo(cmdarg_T *cap) |
7 | 8566 { |
8567 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8568 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8569 { |
8570 /* translate "gUU" to "gUgU" */ | |
8571 cap->cmdchar = 'g'; | |
8572 cap->nchar = 'U'; | |
8573 nv_operator(cap); | |
8574 } | |
8575 else if (!checkclearopq(cap->oap)) | |
8576 { | |
8577 u_undoline(); | |
8578 curwin->w_set_curswant = TRUE; | |
8579 } | |
8580 } | |
8581 | |
8582 /* | |
8583 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8584 * single character. | |
8585 */ | |
8586 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8587 nv_tilde(cmdarg_T *cap) |
7 | 8588 { |
5735 | 8589 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
7 | 8590 n_swapchar(cap); |
8591 else | |
8592 nv_operator(cap); | |
8593 } | |
8594 | |
8595 /* | |
8596 * Handle an operator command. | |
8597 * The actual work is done by do_pending_operator(). | |
8598 */ | |
8599 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8600 nv_operator(cmdarg_T *cap) |
7 | 8601 { |
8602 int op_type; | |
8603 | |
8604 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
8605 | |
8606 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8607 nv_lineop(cap); | |
8608 else if (!checkclearop(cap->oap)) | |
8609 { | |
8610 cap->oap->start = curwin->w_cursor; | |
8611 cap->oap->op_type = op_type; | |
1490 | 8612 #ifdef FEAT_EVAL |
8613 set_op_var(op_type); | |
8614 #endif | |
8615 } | |
8616 } | |
8617 | |
8618 #ifdef FEAT_EVAL | |
8619 /* | |
8620 * Set v:operator to the characters for "optype". | |
8621 */ | |
8622 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8623 set_op_var(int optype) |
1490 | 8624 { |
8625 char_u opchars[3]; | |
8626 | |
8627 if (optype == OP_NOP) | |
8628 set_vim_var_string(VV_OP, NULL, 0); | |
8629 else | |
8630 { | |
8631 opchars[0] = get_op_char(optype); | |
8632 opchars[1] = get_extra_op_char(optype); | |
8633 opchars[2] = NUL; | |
8634 set_vim_var_string(VV_OP, opchars, -1); | |
8635 } | |
8636 } | |
8637 #endif | |
7 | 8638 |
8639 /* | |
8640 * Handle linewise operator "dd", "yy", etc. | |
8641 * | |
8642 * "_" is is a strange motion command that helps make operators more logical. | |
8643 * It is actually implemented, but not documented in the real Vi. This motion | |
8644 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8645 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8646 * "d3_" works to delete 3 lines. | |
8647 */ | |
8648 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8649 nv_lineop(cmdarg_T *cap) |
7 | 8650 { |
8651 cap->oap->motion_type = MLINE; | |
8652 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8653 clearopbeep(cap->oap); | |
4011 | 8654 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8655 && cap->oap->motion_force != 'v' | |
8656 && cap->oap->motion_force != Ctrl_V) | |
7 | 8657 || cap->oap->op_type == OP_LSHIFT |
8658 || cap->oap->op_type == OP_RSHIFT) | |
8659 beginline(BL_SOL | BL_FIX); | |
8660 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8661 beginline(BL_WHITE | BL_FIX); | |
8662 } | |
8663 | |
8664 /* | |
8665 * <Home> command. | |
8666 */ | |
8667 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8668 nv_home(cmdarg_T *cap) |
7 | 8669 { |
180 | 8670 /* CTRL-HOME is like "gg" */ |
8671 if (mod_mask & MOD_MASK_CTRL) | |
8672 nv_goto(cap); | |
8673 else | |
8674 { | |
8675 cap->count0 = 1; | |
8676 nv_pipe(cap); | |
8677 } | |
229 | 8678 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8679 one-character line). */ | |
7 | 8680 } |
8681 | |
8682 /* | |
8683 * "|" command. | |
8684 */ | |
8685 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8686 nv_pipe(cmdarg_T *cap) |
7 | 8687 { |
8688 cap->oap->motion_type = MCHAR; | |
8689 cap->oap->inclusive = FALSE; | |
8690 beginline(0); | |
8691 if (cap->count0 > 0) | |
8692 { | |
8693 coladvance((colnr_T)(cap->count0 - 1)); | |
8694 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8695 } | |
8696 else | |
8697 curwin->w_curswant = 0; | |
8698 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8699 * we ended; differs if line is too short */ |
7 | 8700 curwin->w_set_curswant = FALSE; |
8701 } | |
8702 | |
8703 /* | |
8704 * Handle back-word command "b" and "B". | |
8705 * cap->arg is 1 for "B" | |
8706 */ | |
8707 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8708 nv_bck_word(cmdarg_T *cap) |
7 | 8709 { |
8710 cap->oap->motion_type = MCHAR; | |
8711 cap->oap->inclusive = FALSE; | |
8712 curwin->w_set_curswant = TRUE; | |
8713 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8714 clearopbeep(cap->oap); | |
8715 #ifdef FEAT_FOLDING | |
8716 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8717 foldOpenCursor(); | |
8718 #endif | |
8719 } | |
8720 | |
8721 /* | |
8722 * Handle word motion commands "e", "E", "w" and "W". | |
8723 * cap->arg is TRUE for "E" and "W". | |
8724 */ | |
8725 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8726 nv_wordcmd(cmdarg_T *cap) |
7 | 8727 { |
8728 int n; | |
8729 int word_end; | |
8730 int flag = FALSE; | |
1573 | 8731 pos_T startpos = curwin->w_cursor; |
7 | 8732 |
8733 /* | |
8734 * Set inclusive for the "E" and "e" command. | |
8735 */ | |
8736 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8737 word_end = TRUE; | |
8738 else | |
8739 word_end = FALSE; | |
8740 cap->oap->inclusive = word_end; | |
8741 | |
8742 /* | |
8743 * "cw" and "cW" are a special case. | |
8744 */ | |
8745 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8746 { | |
8747 n = gchar_cursor(); | |
8748 if (n != NUL) /* not an empty line */ | |
8749 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8750 if (VIM_ISWHITE(n)) |
7 | 8751 { |
8752 /* | |
8753 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8754 * changes one character, not all blanks until the start of | |
8755 * the next word. Only do this when the 'w' flag is included | |
8756 * in 'cpoptions'. | |
8757 */ | |
8758 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8759 { | |
8760 cap->oap->inclusive = TRUE; | |
8761 cap->oap->motion_type = MCHAR; | |
8762 return; | |
8763 } | |
8764 } | |
8765 else | |
8766 { | |
8767 /* | |
8768 * This is a little strange. To match what the real Vi does, | |
8769 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8770 * that we are not on a space or a TAB. This seems impolite | |
8771 * at first, but it's really more what we mean when we say | |
8772 * 'cw'. | |
8773 * Another strangeness: When standing on the end of a word | |
4352 | 8774 * "ce" will change until the end of the next word, but "cw" |
7 | 8775 * will change only one character! This is done by setting |
8776 * flag. | |
8777 */ | |
8778 cap->oap->inclusive = TRUE; | |
8779 word_end = TRUE; | |
8780 flag = TRUE; | |
8781 } | |
8782 } | |
8783 } | |
8784 | |
8785 cap->oap->motion_type = MCHAR; | |
8786 curwin->w_set_curswant = TRUE; | |
8787 if (word_end) | |
8788 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8789 else | |
8790 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8791 | |
1573 | 8792 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8793 * 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
|
8794 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8795 adjust_cursor(cap->oap); |
7 | 8796 |
8797 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8798 clearopbeep(cap->oap); | |
8799 else | |
8800 { | |
8801 adjust_for_sel(cap); | |
8802 #ifdef FEAT_FOLDING | |
8803 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8804 foldOpenCursor(); | |
8805 #endif | |
8806 } | |
8807 } | |
8808 | |
8809 /* | |
1505 | 8810 * Used after a movement command: If the cursor ends up on the NUL after the |
8811 * end of the line, may move it back to the last character and make the motion | |
8812 * inclusive. | |
8813 */ | |
8814 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8815 adjust_cursor(oparg_T *oap) |
1505 | 8816 { |
8817 /* The cursor cannot remain on the NUL when: | |
8818 * - the column is > 0 | |
8819 * - not in Visual mode or 'selection' is "o" | |
8820 * - 'virtualedit' is not "all" and not "onemore". | |
8821 */ | |
8822 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8823 && (!VIsual_active || *p_sel == 'o') | |
8824 #ifdef FEAT_VIRTUALEDIT | |
8825 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8826 #endif | |
8827 ) | |
8828 { | |
8829 --curwin->w_cursor.col; | |
8830 #ifdef FEAT_MBYTE | |
8831 /* prevent cursor from moving on the trail byte */ | |
8832 if (has_mbyte) | |
8833 mb_adjust_cursor(); | |
8834 #endif | |
8835 oap->inclusive = TRUE; | |
8836 } | |
8837 } | |
8838 | |
8839 /* | |
7 | 8840 * "0" and "^" commands. |
8841 * cap->arg is the argument for beginline(). | |
8842 */ | |
8843 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8844 nv_beginline(cmdarg_T *cap) |
7 | 8845 { |
8846 cap->oap->motion_type = MCHAR; | |
8847 cap->oap->inclusive = FALSE; | |
8848 beginline(cap->arg); | |
8849 #ifdef FEAT_FOLDING | |
8850 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8851 foldOpenCursor(); | |
8852 #endif | |
557 | 8853 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8854 one-character line). */ | |
7 | 8855 } |
8856 | |
8857 /* | |
8858 * In exclusive Visual mode, may include the last character. | |
8859 */ | |
8860 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8861 adjust_for_sel(cmdarg_T *cap) |
7 | 8862 { |
8863 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
|
8864 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8865 { |
5735 | 8866 #ifdef FEAT_MBYTE |
7 | 8867 if (has_mbyte) |
8868 inc_cursor(); | |
8869 else | |
5735 | 8870 #endif |
7 | 8871 ++curwin->w_cursor.col; |
8872 cap->oap->inclusive = FALSE; | |
8873 } | |
8874 } | |
8875 | |
8876 /* | |
8877 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8878 * Should check VIsual_mode before calling this. | |
8879 * Returns TRUE when backed up to the previous line. | |
8880 */ | |
8881 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8882 unadjust_for_sel(void) |
7 | 8883 { |
8884 pos_T *pp; | |
8885 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8886 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
|
8887 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8888 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8889 pp = &curwin->w_cursor; |
8890 else | |
8891 pp = &VIsual; | |
8892 #ifdef FEAT_VIRTUALEDIT | |
8893 if (pp->coladd > 0) | |
8894 --pp->coladd; | |
8895 else | |
8896 #endif | |
8897 if (pp->col > 0) | |
8898 { | |
8899 --pp->col; | |
8900 #ifdef FEAT_MBYTE | |
2933 | 8901 mb_adjustpos(curbuf, pp); |
7 | 8902 #endif |
8903 } | |
8904 else if (pp->lnum > 1) | |
8905 { | |
8906 --pp->lnum; | |
8907 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8908 return TRUE; | |
8909 } | |
8910 } | |
8911 return FALSE; | |
8912 } | |
8913 | |
8914 /* | |
8915 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8916 */ | |
8917 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8918 nv_select(cmdarg_T *cap) |
7 | 8919 { |
8920 if (VIsual_active) | |
8921 VIsual_select = TRUE; | |
8922 else if (VIsual_reselect) | |
8923 { | |
8924 cap->nchar = 'v'; /* fake "gv" command */ | |
8925 cap->arg = TRUE; | |
8926 nv_g_cmd(cap); | |
8927 } | |
8928 } | |
8929 | |
8930 | |
8931 /* | |
8932 * "G", "gg", CTRL-END, CTRL-HOME. | |
8933 * cap->arg is TRUE for "G". | |
8934 */ | |
8935 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8936 nv_goto(cmdarg_T *cap) |
7 | 8937 { |
8938 linenr_T lnum; | |
8939 | |
8940 if (cap->arg) | |
8941 lnum = curbuf->b_ml.ml_line_count; | |
8942 else | |
8943 lnum = 1L; | |
8944 cap->oap->motion_type = MLINE; | |
8945 setpcmark(); | |
8946 | |
8947 /* When a count is given, use it instead of the default lnum */ | |
8948 if (cap->count0 != 0) | |
8949 lnum = cap->count0; | |
8950 if (lnum < 1L) | |
8951 lnum = 1L; | |
8952 else if (lnum > curbuf->b_ml.ml_line_count) | |
8953 lnum = curbuf->b_ml.ml_line_count; | |
8954 curwin->w_cursor.lnum = lnum; | |
8955 beginline(BL_SOL | BL_FIX); | |
8956 #ifdef FEAT_FOLDING | |
8957 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8958 foldOpenCursor(); | |
8959 #endif | |
8960 } | |
8961 | |
8962 /* | |
8963 * CTRL-\ in Normal mode. | |
8964 */ | |
8965 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8966 nv_normal(cmdarg_T *cap) |
7 | 8967 { |
8968 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8969 { | |
8970 clearop(cap->oap); | |
643 | 8971 if (restart_edit != 0 && mode_displayed) |
7 | 8972 clear_cmdline = TRUE; /* unshow mode later */ |
8973 restart_edit = 0; | |
8974 #ifdef FEAT_CMDWIN | |
8975 if (cmdwin_type != 0) | |
8976 cmdwin_result = Ctrl_C; | |
8977 #endif | |
8978 if (VIsual_active) | |
8979 { | |
8980 end_visual_mode(); /* stop Visual */ | |
8981 redraw_curbuf_later(INVERTED); | |
8982 } | |
8983 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8984 if (cap->nchar == Ctrl_G && p_im) | |
8985 restart_edit = 'a'; | |
8986 } | |
8987 else | |
8988 clearopbeep(cap->oap); | |
8989 } | |
8990 | |
8991 /* | |
8992 * ESC in Normal mode: beep, but don't flush buffers. | |
8993 * Don't even beep if we are canceling a command. | |
8994 */ | |
8995 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8996 nv_esc(cmdarg_T *cap) |
7 | 8997 { |
8998 int no_reason; | |
8999 | |
9000 no_reason = (cap->oap->op_type == OP_NOP | |
9001 && cap->opcount == 0 | |
9002 && cap->count0 == 0 | |
9003 && cap->oap->regname == 0 | |
9004 && !p_im); | |
9005 | |
9006 if (cap->arg) /* TRUE for CTRL-C */ | |
9007 { | |
9008 if (restart_edit == 0 | |
9009 #ifdef FEAT_CMDWIN | |
9010 && cmdwin_type == 0 | |
9011 #endif | |
9012 && !VIsual_active | |
9013 && 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
|
9014 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9015 |
9016 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9017 * set again below when halfway a mapping. */ | |
9018 if (!p_im) | |
9019 restart_edit = 0; | |
9020 #ifdef FEAT_CMDWIN | |
9021 if (cmdwin_type != 0) | |
9022 { | |
9023 cmdwin_result = K_IGNORE; | |
9024 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9025 return; | |
9026 } | |
9027 #endif | |
9028 } | |
9029 | |
9030 if (VIsual_active) | |
9031 { | |
9032 end_visual_mode(); /* stop Visual */ | |
9033 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9034 curwin->w_set_curswant = TRUE; | |
9035 redraw_curbuf_later(INVERTED); | |
9036 } | |
5735 | 9037 else if (no_reason) |
6949 | 9038 vim_beep(BO_ESC); |
7 | 9039 clearop(cap->oap); |
9040 | |
9041 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9042 * 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
|
9043 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9044 restart_edit = 'a'; |
9045 } | |
9046 | |
9047 /* | |
9048 * 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
|
9049 * Also handle K_PS, start bracketed paste. |
7 | 9050 */ |
9051 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9052 nv_edit(cmdarg_T *cap) |
7 | 9053 { |
9054 /* <Insert> is equal to "i" */ | |
9055 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9056 cap->cmdchar = 'i'; | |
9057 | |
9058 /* in Visual mode "A" and "I" are an operator */ | |
9059 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) | |
9060 v_visop(cap); | |
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; |
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9151 /*FALLTHROUGH*/ |
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 #ifdef FEAT_AUTOCMD | |
9581 /* | |
9582 * Trigger CursorHold event. | |
9583 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9584 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9585 */ | |
9586 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9587 nv_cursorhold(cmdarg_T *cap) |
203 | 9588 { |
9589 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9590 did_cursorhold = TRUE; | |
226 | 9591 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9592 } | |
9593 #endif | |
6866 | 9594 |
9595 /* | |
7001 | 9596 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9597 */ |
9598 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9599 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9600 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9601 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9602 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9603 { |
9604 colnr_T start, end; | |
9605 | |
7001 | 9606 if (VIsual_mode != Ctrl_V |
9607 || (!initial && oap->end.col < W_WIDTH(curwin))) | |
6866 | 9608 return; |
9609 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9610 oap->block_mode = TRUE; |
6866 | 9611 |
9612 #ifdef FEAT_MBYTE | |
9613 /* prevent from moving onto a trail byte */ | |
9614 if (has_mbyte) | |
9615 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9616 #endif | |
9617 | |
9618 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9619 |
9620 if (!redo_VIsual_busy) | |
9621 { | |
9622 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9623 | |
9624 if (start < oap->start_vcol) | |
9625 oap->start_vcol = start; | |
9626 if (end > oap->end_vcol) | |
9627 { | |
9628 if (initial && *p_sel == 'e' && start >= 1 | |
9629 && start - 1 >= oap->end_vcol) | |
9630 oap->end_vcol = start - 1; | |
9631 else | |
9632 oap->end_vcol = end; | |
9633 } | |
9634 } | |
9635 | |
6866 | 9636 /* if '$' was used, get oap->end_vcol from longest line */ |
9637 if (curwin->w_curswant == MAXCOL) | |
9638 { | |
9639 curwin->w_cursor.col = MAXCOL; | |
9640 oap->end_vcol = 0; | |
9641 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9642 curwin->w_cursor.lnum <= oap->end.lnum; | |
9643 ++curwin->w_cursor.lnum) | |
9644 { | |
9645 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9646 if (end > oap->end_vcol) | |
9647 oap->end_vcol = end; | |
9648 } | |
9649 } | |
9650 else if (redo_VIsual_busy) | |
9651 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9652 /* | |
9653 * Correct oap->end.col and oap->start.col to be the | |
9654 * upper-left and lower-right corner of the block area. | |
9655 * | |
9656 * (Actually, this does convert column positions into character | |
9657 * positions) | |
9658 */ | |
9659 curwin->w_cursor.lnum = oap->end.lnum; | |
9660 coladvance(oap->end_vcol); | |
9661 oap->end = curwin->w_cursor; | |
9662 | |
9663 curwin->w_cursor = oap->start; | |
9664 coladvance(oap->start_vcol); | |
9665 oap->start = curwin->w_cursor; | |
9666 } |