Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 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 | #ifdef FEAT_VISUAL |
| 18 | /* |
| 19 | * The Visual area is remembered for reselection. |
| 20 | */ |
| 21 | static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
| 22 | static linenr_T resel_VIsual_line_count; /* number of lines */ |
| 23 | static colnr_T resel_VIsual_col; /* nr of cols or end col */ |
| 24 | |
| 25 | static int restart_VIsual_select = 0; |
| 26 | #endif |
| 27 | |
| 28 | static int |
| 29 | # ifdef __BORLANDC__ |
| 30 | _RTLENTRYF |
| 31 | # endif |
| 32 | nv_compare __ARGS((const void *s1, const void *s2)); |
| 33 | static int find_command __ARGS((int cmdchar)); |
| 34 | static void op_colon __ARGS((oparg_T *oap)); |
| 35 | #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL) |
| 36 | static void find_start_of_word __ARGS((pos_T *)); |
| 37 | static void find_end_of_word __ARGS((pos_T *)); |
| 38 | static int get_mouse_class __ARGS((char_u *p)); |
| 39 | #endif |
| 40 | static void prep_redo_cmd __ARGS((cmdarg_T *cap)); |
| 41 | static void prep_redo __ARGS((int regname, long, int, int, int, int, int)); |
| 42 | static int checkclearop __ARGS((oparg_T *oap)); |
| 43 | static int checkclearopq __ARGS((oparg_T *oap)); |
| 44 | static void clearop __ARGS((oparg_T *oap)); |
| 45 | static void clearopbeep __ARGS((oparg_T *oap)); |
| 46 | #ifdef FEAT_VISUAL |
| 47 | static void unshift_special __ARGS((cmdarg_T *cap)); |
| 48 | #endif |
| 49 | #ifdef FEAT_CMDL_INFO |
| 50 | static void del_from_showcmd __ARGS((int)); |
| 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * nv_*(): functions called to handle Normal and Visual mode commands. |
| 55 | * n_*(): functions called to handle Normal mode commands. |
| 56 | * v_*(): functions called to handle Visual mode commands. |
| 57 | */ |
| 58 | static void nv_ignore __ARGS((cmdarg_T *cap)); |
| 59 | static void nv_error __ARGS((cmdarg_T *cap)); |
| 60 | static void nv_help __ARGS((cmdarg_T *cap)); |
| 61 | static void nv_addsub __ARGS((cmdarg_T *cap)); |
| 62 | static void nv_page __ARGS((cmdarg_T *cap)); |
| 63 | static void nv_gd __ARGS((oparg_T *oap, int nchar)); |
| 64 | static int nv_screengo __ARGS((oparg_T *oap, int dir, long dist)); |
| 65 | #ifdef FEAT_MOUSE |
| 66 | static void nv_mousescroll __ARGS((cmdarg_T *cap)); |
| 67 | static void nv_mouse __ARGS((cmdarg_T *cap)); |
| 68 | #endif |
| 69 | static void nv_scroll_line __ARGS((cmdarg_T *cap)); |
| 70 | static void nv_zet __ARGS((cmdarg_T *cap)); |
| 71 | #ifdef FEAT_GUI |
| 72 | static void nv_ver_scrollbar __ARGS((cmdarg_T *cap)); |
| 73 | static void nv_hor_scrollbar __ARGS((cmdarg_T *cap)); |
| 74 | #endif |
| 75 | static void nv_exmode __ARGS((cmdarg_T *cap)); |
| 76 | static void nv_colon __ARGS((cmdarg_T *cap)); |
| 77 | static void nv_ctrlg __ARGS((cmdarg_T *cap)); |
| 78 | static void nv_ctrlh __ARGS((cmdarg_T *cap)); |
| 79 | static void nv_clear __ARGS((cmdarg_T *cap)); |
| 80 | static void nv_ctrlo __ARGS((cmdarg_T *cap)); |
| 81 | static void nv_hat __ARGS((cmdarg_T *cap)); |
| 82 | static void nv_Zet __ARGS((cmdarg_T *cap)); |
| 83 | static void nv_ident __ARGS((cmdarg_T *cap)); |
| 84 | #ifdef FEAT_VISUAL |
| 85 | static int get_visual_text __ARGS((cmdarg_T *cap, char_u **pp, int *lenp)); |
| 86 | #endif |
| 87 | static void nv_tagpop __ARGS((cmdarg_T *cap)); |
| 88 | static void nv_scroll __ARGS((cmdarg_T *cap)); |
| 89 | static void nv_right __ARGS((cmdarg_T *cap)); |
| 90 | static void nv_left __ARGS((cmdarg_T *cap)); |
| 91 | static void nv_up __ARGS((cmdarg_T *cap)); |
| 92 | static void nv_down __ARGS((cmdarg_T *cap)); |
| 93 | #ifdef FEAT_SEARCHPATH |
| 94 | static void nv_gotofile __ARGS((cmdarg_T *cap)); |
| 95 | #endif |
| 96 | static void nv_end __ARGS((cmdarg_T *cap)); |
| 97 | static void nv_dollar __ARGS((cmdarg_T *cap)); |
| 98 | static void nv_search __ARGS((cmdarg_T *cap)); |
| 99 | static void nv_next __ARGS((cmdarg_T *cap)); |
| 100 | static void normal_search __ARGS((cmdarg_T *cap, int dir, char_u *pat, int opt)); |
| 101 | static void nv_csearch __ARGS((cmdarg_T *cap)); |
| 102 | static void nv_brackets __ARGS((cmdarg_T *cap)); |
| 103 | static void nv_percent __ARGS((cmdarg_T *cap)); |
| 104 | static void nv_brace __ARGS((cmdarg_T *cap)); |
| 105 | static void nv_mark __ARGS((cmdarg_T *cap)); |
| 106 | static void nv_findpar __ARGS((cmdarg_T *cap)); |
| 107 | static void nv_undo __ARGS((cmdarg_T *cap)); |
| 108 | static void nv_kundo __ARGS((cmdarg_T *cap)); |
| 109 | static void nv_Replace __ARGS((cmdarg_T *cap)); |
| 110 | #ifdef FEAT_VREPLACE |
| 111 | static void nv_vreplace __ARGS((cmdarg_T *cap)); |
| 112 | #endif |
| 113 | #ifdef FEAT_VISUAL |
| 114 | static void v_swap_corners __ARGS((int cmdchar)); |
| 115 | #endif |
| 116 | static void nv_replace __ARGS((cmdarg_T *cap)); |
| 117 | static void n_swapchar __ARGS((cmdarg_T *cap)); |
| 118 | static void nv_cursormark __ARGS((cmdarg_T *cap, int flag, pos_T *pos)); |
| 119 | #ifdef FEAT_VISUAL |
| 120 | static void v_visop __ARGS((cmdarg_T *cap)); |
| 121 | #endif |
| 122 | static void nv_subst __ARGS((cmdarg_T *cap)); |
| 123 | static void nv_abbrev __ARGS((cmdarg_T *cap)); |
| 124 | static void nv_optrans __ARGS((cmdarg_T *cap)); |
| 125 | static void nv_gomark __ARGS((cmdarg_T *cap)); |
| 126 | static void nv_pcmark __ARGS((cmdarg_T *cap)); |
| 127 | static void nv_regname __ARGS((cmdarg_T *cap)); |
| 128 | #ifdef FEAT_VISUAL |
| 129 | static void nv_visual __ARGS((cmdarg_T *cap)); |
| 130 | static void n_start_visual_mode __ARGS((int c)); |
| 131 | #endif |
| 132 | static void nv_window __ARGS((cmdarg_T *cap)); |
| 133 | static void nv_suspend __ARGS((cmdarg_T *cap)); |
| 134 | static void nv_g_cmd __ARGS((cmdarg_T *cap)); |
| 135 | static void n_opencmd __ARGS((cmdarg_T *cap)); |
| 136 | static void nv_dot __ARGS((cmdarg_T *cap)); |
| 137 | static void nv_redo __ARGS((cmdarg_T *cap)); |
| 138 | static void nv_Undo __ARGS((cmdarg_T *cap)); |
| 139 | static void nv_tilde __ARGS((cmdarg_T *cap)); |
| 140 | static void nv_operator __ARGS((cmdarg_T *cap)); |
| 141 | static void nv_lineop __ARGS((cmdarg_T *cap)); |
| 142 | static void nv_home __ARGS((cmdarg_T *cap)); |
| 143 | static void nv_pipe __ARGS((cmdarg_T *cap)); |
| 144 | static void nv_bck_word __ARGS((cmdarg_T *cap)); |
| 145 | static void nv_wordcmd __ARGS((cmdarg_T *cap)); |
| 146 | static void nv_beginline __ARGS((cmdarg_T *cap)); |
| 147 | #ifdef FEAT_VISUAL |
| 148 | static void adjust_for_sel __ARGS((cmdarg_T *cap)); |
| 149 | static int unadjust_for_sel __ARGS((void)); |
| 150 | static void nv_select __ARGS((cmdarg_T *cap)); |
| 151 | #endif |
| 152 | static void nv_goto __ARGS((cmdarg_T *cap)); |
| 153 | static void nv_normal __ARGS((cmdarg_T *cap)); |
| 154 | static void nv_esc __ARGS((cmdarg_T *oap)); |
| 155 | static void nv_edit __ARGS((cmdarg_T *cap)); |
| 156 | static void invoke_edit __ARGS((cmdarg_T *cap, int repl, int cmd, int startln)); |
| 157 | #ifdef FEAT_TEXTOBJ |
| 158 | static void nv_object __ARGS((cmdarg_T *cap)); |
| 159 | #endif |
| 160 | static void nv_record __ARGS((cmdarg_T *cap)); |
| 161 | static void nv_at __ARGS((cmdarg_T *cap)); |
| 162 | static void nv_halfpage __ARGS((cmdarg_T *cap)); |
| 163 | static void nv_join __ARGS((cmdarg_T *cap)); |
| 164 | static void nv_put __ARGS((cmdarg_T *cap)); |
| 165 | static void nv_open __ARGS((cmdarg_T *cap)); |
| 166 | #ifdef FEAT_SNIFF |
| 167 | static void nv_sniff __ARGS((cmdarg_T *cap)); |
| 168 | #endif |
| 169 | #ifdef FEAT_NETBEANS_INTG |
| 170 | static void nv_nbcmd __ARGS((cmdarg_T *cap)); |
| 171 | #endif |
| 172 | #ifdef FEAT_DND |
| 173 | static void nv_drop __ARGS((cmdarg_T *cap)); |
| 174 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 175 | #ifdef FEAT_AUTOCMD |
| 176 | static void nv_cursorhold __ARGS((cmdarg_T *cap)); |
| 177 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Function to be called for a Normal or Visual mode command. |
| 181 | * The argument is a cmdarg_T. |
| 182 | */ |
| 183 | typedef void (*nv_func_T) __ARGS((cmdarg_T *cap)); |
| 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}, |
| 234 | {CAR, nv_down, 0, TRUE}, |
| 235 | {Ctrl_N, nv_down, NV_STS, FALSE}, |
| 236 | {Ctrl_O, nv_ctrlo, 0, 0}, |
| 237 | {Ctrl_P, nv_up, NV_STS, FALSE}, |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 238 | #ifdef FEAT_VISUAL |
| 239 | {Ctrl_Q, nv_visual, 0, FALSE}, |
| 240 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 241 | {Ctrl_Q, nv_ignore, 0, 0}, |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 242 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 243 | {Ctrl_R, nv_redo, 0, 0}, |
| 244 | {Ctrl_S, nv_ignore, 0, 0}, |
| 245 | {Ctrl_T, nv_tagpop, NV_NCW, 0}, |
| 246 | {Ctrl_U, nv_halfpage, 0, 0}, |
| 247 | #ifdef FEAT_VISUAL |
| 248 | {Ctrl_V, nv_visual, 0, FALSE}, |
| 249 | {'V', nv_visual, 0, FALSE}, |
| 250 | {'v', nv_visual, 0, FALSE}, |
| 251 | #else |
| 252 | {Ctrl_V, nv_error, 0, 0}, |
| 253 | {'V', nv_error, 0, 0}, |
| 254 | {'v', nv_error, 0, 0}, |
| 255 | #endif |
| 256 | {Ctrl_W, nv_window, 0, 0}, |
| 257 | {Ctrl_X, nv_addsub, 0, 0}, |
| 258 | {Ctrl_Y, nv_scroll_line, 0, FALSE}, |
| 259 | {Ctrl_Z, nv_suspend, 0, 0}, |
| 260 | {ESC, nv_esc, 0, FALSE}, |
| 261 | {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, |
| 262 | {Ctrl_RSB, nv_ident, NV_NCW, 0}, |
| 263 | {Ctrl_HAT, nv_hat, NV_NCW, 0}, |
| 264 | {Ctrl__, nv_error, 0, 0}, |
| 265 | {' ', nv_right, 0, 0}, |
| 266 | {'!', nv_operator, 0, 0}, |
| 267 | {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, |
| 268 | {'#', nv_ident, 0, 0}, |
| 269 | {'$', nv_dollar, 0, 0}, |
| 270 | {'%', nv_percent, 0, 0}, |
| 271 | {'&', nv_optrans, 0, 0}, |
| 272 | {'\'', nv_gomark, NV_NCH_ALW, TRUE}, |
| 273 | {'(', nv_brace, 0, BACKWARD}, |
| 274 | {')', nv_brace, 0, FORWARD}, |
| 275 | {'*', nv_ident, 0, 0}, |
| 276 | {'+', nv_down, 0, TRUE}, |
| 277 | {',', nv_csearch, 0, TRUE}, |
| 278 | {'-', nv_up, 0, TRUE}, |
| 279 | {'.', nv_dot, NV_KEEPREG, 0}, |
| 280 | {'/', nv_search, 0, FALSE}, |
| 281 | {'0', nv_beginline, 0, 0}, |
| 282 | {'1', nv_ignore, 0, 0}, |
| 283 | {'2', nv_ignore, 0, 0}, |
| 284 | {'3', nv_ignore, 0, 0}, |
| 285 | {'4', nv_ignore, 0, 0}, |
| 286 | {'5', nv_ignore, 0, 0}, |
| 287 | {'6', nv_ignore, 0, 0}, |
| 288 | {'7', nv_ignore, 0, 0}, |
| 289 | {'8', nv_ignore, 0, 0}, |
| 290 | {'9', nv_ignore, 0, 0}, |
| 291 | {':', nv_colon, 0, 0}, |
| 292 | {';', nv_csearch, 0, FALSE}, |
| 293 | {'<', nv_operator, NV_RL, 0}, |
| 294 | {'=', nv_operator, 0, 0}, |
| 295 | {'>', nv_operator, NV_RL, 0}, |
| 296 | {'?', nv_search, 0, FALSE}, |
| 297 | {'@', nv_at, NV_NCH_NOP, FALSE}, |
| 298 | {'A', nv_edit, 0, 0}, |
| 299 | {'B', nv_bck_word, 0, 1}, |
| 300 | {'C', nv_abbrev, NV_KEEPREG, 0}, |
| 301 | {'D', nv_abbrev, NV_KEEPREG, 0}, |
| 302 | {'E', nv_wordcmd, 0, TRUE}, |
| 303 | {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, |
| 304 | {'G', nv_goto, 0, TRUE}, |
| 305 | {'H', nv_scroll, 0, 0}, |
| 306 | {'I', nv_edit, 0, 0}, |
| 307 | {'J', nv_join, 0, 0}, |
| 308 | {'K', nv_ident, 0, 0}, |
| 309 | {'L', nv_scroll, 0, 0}, |
| 310 | {'M', nv_scroll, 0, 0}, |
| 311 | {'N', nv_next, 0, SEARCH_REV}, |
| 312 | {'O', nv_open, 0, 0}, |
| 313 | {'P', nv_put, 0, 0}, |
| 314 | {'Q', nv_exmode, NV_NCW, 0}, |
| 315 | {'R', nv_Replace, 0, FALSE}, |
| 316 | {'S', nv_subst, NV_KEEPREG, 0}, |
| 317 | {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, |
| 318 | {'U', nv_Undo, 0, 0}, |
| 319 | {'W', nv_wordcmd, 0, TRUE}, |
| 320 | {'X', nv_abbrev, NV_KEEPREG, 0}, |
| 321 | {'Y', nv_abbrev, NV_KEEPREG, 0}, |
| 322 | {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, |
| 323 | {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, |
| 324 | {'\\', nv_error, 0, 0}, |
| 325 | {']', nv_brackets, NV_NCH_ALW, FORWARD}, |
| 326 | {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, |
| 327 | {'_', nv_lineop, 0, 0}, |
| 328 | {'`', nv_gomark, NV_NCH_ALW, FALSE}, |
| 329 | {'a', nv_edit, NV_NCH, 0}, |
| 330 | {'b', nv_bck_word, 0, 0}, |
| 331 | {'c', nv_operator, 0, 0}, |
| 332 | {'d', nv_operator, 0, 0}, |
| 333 | {'e', nv_wordcmd, 0, FALSE}, |
| 334 | {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, |
| 335 | {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, |
| 336 | {'h', nv_left, NV_RL, 0}, |
| 337 | {'i', nv_edit, NV_NCH, 0}, |
| 338 | {'j', nv_down, 0, FALSE}, |
| 339 | {'k', nv_up, 0, FALSE}, |
| 340 | {'l', nv_right, NV_RL, 0}, |
| 341 | {'m', nv_mark, NV_NCH_NOP, 0}, |
| 342 | {'n', nv_next, 0, 0}, |
| 343 | {'o', nv_open, 0, 0}, |
| 344 | {'p', nv_put, 0, 0}, |
| 345 | {'q', nv_record, NV_NCH, 0}, |
| 346 | {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, |
| 347 | {'s', nv_subst, NV_KEEPREG, 0}, |
| 348 | {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, |
| 349 | {'u', nv_undo, 0, 0}, |
| 350 | {'w', nv_wordcmd, 0, FALSE}, |
| 351 | {'x', nv_abbrev, NV_KEEPREG, 0}, |
| 352 | {'y', nv_operator, 0, 0}, |
| 353 | {'z', nv_zet, NV_NCH_ALW, 0}, |
| 354 | {'{', nv_findpar, 0, BACKWARD}, |
| 355 | {'|', nv_pipe, 0, 0}, |
| 356 | {'}', nv_findpar, 0, FORWARD}, |
| 357 | {'~', nv_tilde, 0, 0}, |
| 358 | |
| 359 | /* pound sign */ |
| 360 | {POUND, nv_ident, 0, 0}, |
| 361 | #ifdef FEAT_MOUSE |
| 362 | {K_MOUSEUP, nv_mousescroll, 0, TRUE}, |
| 363 | {K_MOUSEDOWN, nv_mousescroll, 0, FALSE}, |
| 364 | {K_LEFTMOUSE, nv_mouse, 0, 0}, |
| 365 | {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, |
| 366 | {K_LEFTDRAG, nv_mouse, 0, 0}, |
| 367 | {K_LEFTRELEASE, nv_mouse, 0, 0}, |
| 368 | {K_LEFTRELEASE_NM, nv_mouse, 0, 0}, |
| 369 | {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
| 370 | {K_MIDDLEDRAG, nv_mouse, 0, 0}, |
| 371 | {K_MIDDLERELEASE, nv_mouse, 0, 0}, |
| 372 | {K_RIGHTMOUSE, nv_mouse, 0, 0}, |
| 373 | {K_RIGHTDRAG, nv_mouse, 0, 0}, |
| 374 | {K_RIGHTRELEASE, nv_mouse, 0, 0}, |
| 375 | {K_X1MOUSE, nv_mouse, 0, 0}, |
| 376 | {K_X1DRAG, nv_mouse, 0, 0}, |
| 377 | {K_X1RELEASE, nv_mouse, 0, 0}, |
| 378 | {K_X2MOUSE, nv_mouse, 0, 0}, |
| 379 | {K_X2DRAG, nv_mouse, 0, 0}, |
| 380 | {K_X2RELEASE, nv_mouse, 0, 0}, |
| 381 | #endif |
| 382 | {K_IGNORE, nv_ignore, 0, 0}, |
| 383 | {K_INS, nv_edit, 0, 0}, |
| 384 | {K_KINS, nv_edit, 0, 0}, |
| 385 | {K_BS, nv_ctrlh, 0, 0}, |
| 386 | {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, |
| 387 | {K_S_UP, nv_page, NV_SS, BACKWARD}, |
| 388 | {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, |
| 389 | {K_S_DOWN, nv_page, NV_SS, FORWARD}, |
| 390 | {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, |
| 391 | {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, |
| 392 | {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, |
| 393 | {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, |
| 394 | {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, |
| 395 | {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, |
| 396 | {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, |
| 397 | {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, |
| 398 | {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, |
| 399 | {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, |
| 400 | {K_END, nv_end, NV_SSS|NV_STS, FALSE}, |
| 401 | {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 402 | {K_S_END, nv_end, NV_SS, FALSE}, |
| 403 | {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, |
| 404 | {K_HOME, nv_home, NV_SSS|NV_STS, 0}, |
| 405 | {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 406 | {K_S_HOME, nv_home, NV_SS, 0}, |
| 407 | {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, |
| 408 | {K_DEL, nv_abbrev, 0, 0}, |
| 409 | {K_KDEL, nv_abbrev, 0, 0}, |
| 410 | {K_UNDO, nv_kundo, 0, 0}, |
| 411 | {K_HELP, nv_help, NV_NCW, 0}, |
| 412 | {K_F1, nv_help, NV_NCW, 0}, |
| 413 | {K_XF1, nv_help, NV_NCW, 0}, |
| 414 | #ifdef FEAT_VISUAL |
| 415 | {K_SELECT, nv_select, 0, 0}, |
| 416 | #endif |
| 417 | #ifdef FEAT_GUI |
| 418 | {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, |
| 419 | {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, |
| 420 | #endif |
| 421 | #ifdef FEAT_FKMAP |
| 422 | {K_F8, farsi_fkey, 0, 0}, |
| 423 | {K_F9, farsi_fkey, 0, 0}, |
| 424 | #endif |
| 425 | #ifdef FEAT_SNIFF |
| 426 | {K_SNIFF, nv_sniff, 0, 0}, |
| 427 | #endif |
| 428 | #ifdef FEAT_NETBEANS_INTG |
| 429 | {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, |
| 430 | #endif |
| 431 | #ifdef FEAT_DND |
| 432 | {K_DROP, nv_drop, NV_STS, 0}, |
| 433 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 434 | #ifdef FEAT_AUTOCMD |
| 435 | {K_CURSORHOLD, nv_cursorhold, 0, 0}, |
| 436 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | /* Number of commands in nv_cmds[]. */ |
| 440 | #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) |
| 441 | |
| 442 | /* Sorted index of commands in nv_cmds[]. */ |
| 443 | static short nv_cmd_idx[NV_CMDS_SIZE]; |
| 444 | |
| 445 | /* The highest index for which |
| 446 | * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ |
| 447 | static int nv_max_linear; |
| 448 | |
| 449 | /* |
| 450 | * Compare functions for qsort() below, that checks the command character |
| 451 | * through the index in nv_cmd_idx[]. |
| 452 | */ |
| 453 | static int |
| 454 | #ifdef __BORLANDC__ |
| 455 | _RTLENTRYF |
| 456 | #endif |
| 457 | nv_compare(s1, s2) |
| 458 | const void *s1; |
| 459 | const void *s2; |
| 460 | { |
| 461 | int c1, c2; |
| 462 | |
| 463 | /* The commands are sorted on absolute value. */ |
| 464 | c1 = nv_cmds[*(const short *)s1].cmd_char; |
| 465 | c2 = nv_cmds[*(const short *)s2].cmd_char; |
| 466 | if (c1 < 0) |
| 467 | c1 = -c1; |
| 468 | if (c2 < 0) |
| 469 | c2 = -c2; |
| 470 | return c1 - c2; |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * Initialize the nv_cmd_idx[] table. |
| 475 | */ |
| 476 | void |
| 477 | init_normal_cmds() |
| 478 | { |
| 479 | int i; |
| 480 | |
| 481 | /* Fill the index table with a one to one relation. */ |
| 482 | for (i = 0; i < NV_CMDS_SIZE; ++i) |
| 483 | nv_cmd_idx[i] = i; |
| 484 | |
| 485 | /* Sort the commands by the command character. */ |
| 486 | qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); |
| 487 | |
| 488 | /* Find the first entry that can't be indexed by the command character. */ |
| 489 | for (i = 0; i < NV_CMDS_SIZE; ++i) |
| 490 | if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
| 491 | break; |
| 492 | nv_max_linear = i - 1; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * Search for a command in the commands table. |
| 497 | * Returns -1 for invalid command. |
| 498 | */ |
| 499 | static int |
| 500 | find_command(cmdchar) |
| 501 | int cmdchar; |
| 502 | { |
| 503 | int i; |
| 504 | int idx; |
| 505 | int top, bot; |
| 506 | int c; |
| 507 | |
| 508 | #ifdef FEAT_MBYTE |
| 509 | /* A multi-byte character is never a command. */ |
| 510 | if (cmdchar >= 0x100) |
| 511 | return -1; |
| 512 | #endif |
| 513 | |
| 514 | /* We use the absolute value of the character. Special keys have a |
| 515 | * negative value, but are sorted on their absolute value. */ |
| 516 | if (cmdchar < 0) |
| 517 | cmdchar = -cmdchar; |
| 518 | |
| 519 | /* If the character is in the first part: The character is the index into |
| 520 | * nv_cmd_idx[]. */ |
| 521 | if (cmdchar <= nv_max_linear) |
| 522 | return nv_cmd_idx[cmdchar]; |
| 523 | |
| 524 | /* Perform a binary search. */ |
| 525 | bot = nv_max_linear + 1; |
| 526 | top = NV_CMDS_SIZE - 1; |
| 527 | idx = -1; |
| 528 | while (bot <= top) |
| 529 | { |
| 530 | i = (top + bot) / 2; |
| 531 | c = nv_cmds[nv_cmd_idx[i]].cmd_char; |
| 532 | if (c < 0) |
| 533 | c = -c; |
| 534 | if (cmdchar == c) |
| 535 | { |
| 536 | idx = nv_cmd_idx[i]; |
| 537 | break; |
| 538 | } |
| 539 | if (cmdchar > c) |
| 540 | bot = i + 1; |
| 541 | else |
| 542 | top = i - 1; |
| 543 | } |
| 544 | return idx; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Execute a command in Normal mode. |
| 549 | */ |
| 550 | /*ARGSUSED*/ |
| 551 | void |
| 552 | normal_cmd(oap, toplevel) |
| 553 | oparg_T *oap; |
| 554 | int toplevel; /* TRUE when called from main() */ |
| 555 | { |
| 556 | static long opcount = 0; /* ca.opcount saved here */ |
| 557 | cmdarg_T ca; /* command arguments */ |
| 558 | int c; |
| 559 | int ctrl_w = FALSE; /* got CTRL-W command */ |
| 560 | int old_col = curwin->w_curswant; |
| 561 | #ifdef FEAT_CMDL_INFO |
| 562 | int need_flushbuf; /* need to call out_flush() */ |
| 563 | #endif |
| 564 | #ifdef FEAT_VISUAL |
| 565 | pos_T old_pos; /* cursor position before command */ |
| 566 | int mapped_len; |
| 567 | #endif |
| 568 | static int old_mapped_len = 0; |
| 569 | int idx; |
| 570 | |
| 571 | vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ |
| 572 | ca.oap = oap; |
| 573 | ca.opcount = opcount; |
| 574 | |
| 575 | #ifdef FEAT_SNIFF |
| 576 | want_sniff_request = sniff_connected; |
| 577 | #endif |
| 578 | |
| 579 | /* |
| 580 | * If there is an operator pending, then the command we take this time |
| 581 | * will terminate it. Finish_op tells us to finish the operation before |
| 582 | * returning this time (unless the operation was cancelled). |
| 583 | */ |
| 584 | #ifdef CURSOR_SHAPE |
| 585 | c = finish_op; |
| 586 | #endif |
| 587 | finish_op = (oap->op_type != OP_NOP); |
| 588 | #ifdef CURSOR_SHAPE |
| 589 | if (finish_op != c) |
| 590 | { |
| 591 | ui_cursor_shape(); /* may show different cursor shape */ |
| 592 | # ifdef FEAT_MOUSESHAPE |
| 593 | update_mouseshape(-1); |
| 594 | # endif |
| 595 | } |
| 596 | #endif |
| 597 | |
| 598 | if (!finish_op && !oap->regname) |
| 599 | ca.opcount = 0; |
| 600 | |
| 601 | #ifdef FEAT_VISUAL |
| 602 | mapped_len = typebuf_maplen(); |
| 603 | #endif |
| 604 | |
| 605 | State = NORMAL_BUSY; |
| 606 | #ifdef USE_ON_FLY_SCROLL |
| 607 | dont_scroll = FALSE; /* allow scrolling here */ |
| 608 | #endif |
| 609 | |
| 610 | /* |
| 611 | * Get the command character from the user. |
| 612 | */ |
| 613 | c = safe_vgetc(); |
| 614 | |
| 615 | #ifdef FEAT_LANGMAP |
| 616 | LANGMAP_ADJUST(c, TRUE); |
| 617 | #endif |
| 618 | |
| 619 | /* |
| 620 | * If a mapping was started in Visual or Select mode, remember the length |
| 621 | * of the mapping. This is used below to not return to Insert mode for as |
| 622 | * long as the mapping is being executed. |
| 623 | */ |
| 624 | if (restart_edit == 0) |
| 625 | old_mapped_len = 0; |
| 626 | else if (old_mapped_len |
| 627 | #ifdef FEAT_VISUAL |
| 628 | || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0) |
| 629 | #endif |
| 630 | ) |
| 631 | old_mapped_len = typebuf_maplen(); |
| 632 | |
| 633 | if (c == NUL) |
| 634 | c = K_ZERO; |
| 635 | |
| 636 | #ifdef FEAT_VISUAL |
| 637 | /* |
| 638 | * In Select mode, typed text replaces the selection. |
| 639 | */ |
| 640 | if (VIsual_active |
| 641 | && VIsual_select |
| 642 | && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) |
| 643 | { |
| 644 | # ifdef FEAT_MBYTE |
| 645 | char_u buf[MB_MAXBYTES + 1]; |
| 646 | |
| 647 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 648 | # else |
| 649 | char_u buf[2]; |
| 650 | |
| 651 | buf[0] = c; |
| 652 | buf[1] = NUL; |
| 653 | # endif |
| 654 | /* Fake a "c"hange command. |
| 655 | * Insert the typed character in the typeahead buffer, so that it will |
| 656 | * be mapped in Insert mode. Required for ":lmap" to work. May cause |
| 657 | * mapping a character from ":vnoremap"... */ |
| 658 | (void)ins_typebuf(buf, REMAP_YES, 0, !KeyTyped, FALSE); |
| 659 | c = 'c'; |
| 660 | } |
| 661 | #endif |
| 662 | |
| 663 | #ifdef FEAT_CMDL_INFO |
| 664 | need_flushbuf = add_to_showcmd(c); |
| 665 | #endif |
| 666 | |
| 667 | getcount: |
| 668 | #ifdef FEAT_VISUAL |
| 669 | if (!(VIsual_active && VIsual_select)) |
| 670 | #endif |
| 671 | { |
| 672 | /* |
| 673 | * Handle a count before a command and compute ca.count0. |
| 674 | * Note that '0' is a command and not the start of a count, but it's |
| 675 | * part of a count after other digits. |
| 676 | */ |
| 677 | while ( (c >= '1' && c <= '9') |
| 678 | || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) |
| 679 | { |
| 680 | if (c == K_DEL || c == K_KDEL) |
| 681 | { |
| 682 | ca.count0 /= 10; |
| 683 | #ifdef FEAT_CMDL_INFO |
| 684 | del_from_showcmd(4); /* delete the digit and ~@% */ |
| 685 | #endif |
| 686 | } |
| 687 | else |
| 688 | ca.count0 = ca.count0 * 10 + (c - '0'); |
| 689 | if (ca.count0 < 0) /* got too large! */ |
| 690 | ca.count0 = 999999999L; |
| 691 | if (ctrl_w) |
| 692 | { |
| 693 | ++no_mapping; |
| 694 | ++allow_keys; /* no mapping for nchar, but keys */ |
| 695 | } |
| 696 | ++no_zero_mapping; /* don't map zero here */ |
| 697 | c = safe_vgetc(); |
| 698 | #ifdef FEAT_LANGMAP |
| 699 | LANGMAP_ADJUST(c, TRUE); |
| 700 | #endif |
| 701 | --no_zero_mapping; |
| 702 | if (ctrl_w) |
| 703 | { |
| 704 | --no_mapping; |
| 705 | --allow_keys; |
| 706 | } |
| 707 | #ifdef FEAT_CMDL_INFO |
| 708 | need_flushbuf |= add_to_showcmd(c); |
| 709 | #endif |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * If we got CTRL-W there may be a/another count |
| 714 | */ |
| 715 | if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) |
| 716 | { |
| 717 | ctrl_w = TRUE; |
| 718 | ca.opcount = ca.count0; /* remember first count */ |
| 719 | ca.count0 = 0; |
| 720 | ++no_mapping; |
| 721 | ++allow_keys; /* no mapping for nchar, but keys */ |
| 722 | c = safe_vgetc(); /* get next character */ |
| 723 | #ifdef FEAT_LANGMAP |
| 724 | LANGMAP_ADJUST(c, TRUE); |
| 725 | #endif |
| 726 | --no_mapping; |
| 727 | --allow_keys; |
| 728 | #ifdef FEAT_CMDL_INFO |
| 729 | need_flushbuf |= add_to_showcmd(c); |
| 730 | #endif |
| 731 | goto getcount; /* jump back */ |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * If we're in the middle of an operator (including after entering a yank |
| 737 | * buffer with '"') AND we had a count before the operator, then that |
| 738 | * count overrides the current value of ca.count0. |
| 739 | * What this means effectively, is that commands like "3dw" get turned |
| 740 | * into "d3w" which makes things fall into place pretty neatly. |
| 741 | * If you give a count before AND after the operator, they are multiplied. |
| 742 | */ |
| 743 | if (ca.opcount != 0) |
| 744 | { |
| 745 | if (ca.count0) |
| 746 | ca.count0 *= ca.opcount; |
| 747 | else |
| 748 | ca.count0 = ca.opcount; |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * Always remember the count. It will be set to zero (on the next call, |
| 753 | * above) when there is no pending operator. |
| 754 | * When called from main(), save the count for use by the "count" built-in |
| 755 | * variable. |
| 756 | */ |
| 757 | ca.opcount = ca.count0; |
| 758 | ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); |
| 759 | |
| 760 | #ifdef FEAT_EVAL |
| 761 | /* |
| 762 | * Only set v:count when called from main() and not a stuffed command. |
| 763 | */ |
| 764 | if (toplevel && stuff_empty()) |
| 765 | set_vcount(ca.count0, ca.count1); |
| 766 | #endif |
| 767 | |
| 768 | /* |
| 769 | * Find the command character in the table of commands. |
| 770 | * For CTRL-W we already got nchar when looking for a count. |
| 771 | */ |
| 772 | if (ctrl_w) |
| 773 | { |
| 774 | ca.nchar = c; |
| 775 | ca.cmdchar = Ctrl_W; |
| 776 | } |
| 777 | else |
| 778 | ca.cmdchar = c; |
| 779 | idx = find_command(ca.cmdchar); |
| 780 | if (idx < 0) |
| 781 | { |
| 782 | /* Not a known command: beep. */ |
| 783 | clearopbeep(oap); |
| 784 | goto normal_end; |
| 785 | } |
| 786 | #ifdef FEAT_CMDWIN |
| 787 | if (cmdwin_type != 0 && (nv_cmds[idx].cmd_flags & NV_NCW)) |
| 788 | { |
| 789 | /* This command is not allowed in the cmdline window: beep. */ |
| 790 | clearopbeep(oap); |
| 791 | EMSG(_(e_cmdwin)); |
| 792 | goto normal_end; |
| 793 | } |
| 794 | #endif |
| 795 | |
| 796 | #ifdef FEAT_VISUAL |
| 797 | /* |
| 798 | * In Visual/Select mode, a few keys are handled in a special way. |
| 799 | */ |
| 800 | if (VIsual_active) |
| 801 | { |
| 802 | /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ |
| 803 | if (km_stopsel |
| 804 | && (nv_cmds[idx].cmd_flags & NV_STS) |
| 805 | && !(mod_mask & MOD_MASK_SHIFT)) |
| 806 | { |
| 807 | end_visual_mode(); |
| 808 | redraw_curbuf_later(INVERTED); |
| 809 | } |
| 810 | |
| 811 | /* Keys that work different when 'keymodel' contains "startsel" */ |
| 812 | if (km_startsel) |
| 813 | { |
| 814 | if (nv_cmds[idx].cmd_flags & NV_SS) |
| 815 | { |
| 816 | unshift_special(&ca); |
| 817 | idx = find_command(ca.cmdchar); |
| 818 | } |
| 819 | else if ((nv_cmds[idx].cmd_flags & NV_SSS) |
| 820 | && (mod_mask & MOD_MASK_SHIFT)) |
| 821 | { |
| 822 | mod_mask &= ~MOD_MASK_SHIFT; |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | #endif |
| 827 | |
| 828 | #ifdef FEAT_RIGHTLEFT |
| 829 | if (curwin->w_p_rl && KeyTyped && !KeyStuffed |
| 830 | && (nv_cmds[idx].cmd_flags & NV_RL)) |
| 831 | { |
| 832 | /* Invert horizontal movements and operations. Only when typed by the |
| 833 | * user directly, not when the result of a mapping or "x" translated |
| 834 | * to "dl". */ |
| 835 | switch (ca.cmdchar) |
| 836 | { |
| 837 | case 'l': ca.cmdchar = 'h'; break; |
| 838 | case K_RIGHT: ca.cmdchar = K_LEFT; break; |
| 839 | case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; |
| 840 | case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; |
| 841 | case 'h': ca.cmdchar = 'l'; break; |
| 842 | case K_LEFT: ca.cmdchar = K_RIGHT; break; |
| 843 | case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; |
| 844 | case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; |
| 845 | case '>': ca.cmdchar = '<'; break; |
| 846 | case '<': ca.cmdchar = '>'; break; |
| 847 | } |
| 848 | idx = find_command(ca.cmdchar); |
| 849 | } |
| 850 | #endif |
| 851 | |
| 852 | /* |
| 853 | * Get an additional character if we need one. |
| 854 | */ |
| 855 | if ((nv_cmds[idx].cmd_flags & NV_NCH) |
| 856 | && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP |
| 857 | && oap->op_type == OP_NOP) |
| 858 | || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW |
| 859 | || (ca.cmdchar == 'q' |
| 860 | && oap->op_type == OP_NOP |
| 861 | && !Recording |
| 862 | && !Exec_reg) |
| 863 | || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
| 864 | && (oap->op_type != OP_NOP |
| 865 | #ifdef FEAT_VISUAL |
| 866 | || VIsual_active |
| 867 | #endif |
| 868 | )))) |
| 869 | { |
| 870 | int *cp; |
| 871 | int repl = FALSE; /* get character for replace mode */ |
| 872 | int lit = FALSE; /* get extra character literally */ |
| 873 | int langmap_active = FALSE; /* using :lmap mappings */ |
| 874 | int lang; /* getting a text character */ |
| 875 | #ifdef USE_IM_CONTROL |
| 876 | int save_smd; /* saved value of p_smd */ |
| 877 | #endif |
| 878 | |
| 879 | ++no_mapping; |
| 880 | ++allow_keys; /* no mapping for nchar, but allow key codes */ |
| 881 | if (ca.cmdchar == 'g') |
| 882 | { |
| 883 | /* |
| 884 | * For 'g' get the next character now, so that we can check for |
| 885 | * "gr", "g'" and "g`". |
| 886 | */ |
| 887 | ca.nchar = safe_vgetc(); |
| 888 | #ifdef FEAT_LANGMAP |
| 889 | LANGMAP_ADJUST(ca.nchar, TRUE); |
| 890 | #endif |
| 891 | #ifdef FEAT_CMDL_INFO |
| 892 | need_flushbuf |= add_to_showcmd(ca.nchar); |
| 893 | #endif |
| 894 | if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' |
| 895 | || ca.nchar == Ctrl_BSL) |
| 896 | { |
| 897 | cp = &ca.extra_char; /* need to get a third character */ |
| 898 | if (ca.nchar != 'r') |
| 899 | lit = TRUE; /* get it literally */ |
| 900 | else |
| 901 | repl = TRUE; /* get it in replace mode */ |
| 902 | } |
| 903 | else |
| 904 | cp = NULL; /* no third character needed */ |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | if (ca.cmdchar == 'r') /* get it in replace mode */ |
| 909 | repl = TRUE; |
| 910 | cp = &ca.nchar; |
| 911 | } |
| 912 | lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); |
| 913 | |
| 914 | /* |
| 915 | * Get a second or third character. |
| 916 | */ |
| 917 | if (cp != NULL) |
| 918 | { |
| 919 | #ifdef CURSOR_SHAPE |
| 920 | if (repl) |
| 921 | { |
| 922 | State = REPLACE; /* pretend Replace mode */ |
| 923 | ui_cursor_shape(); /* show different cursor shape */ |
| 924 | } |
| 925 | #endif |
| 926 | if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 927 | { |
| 928 | /* Allow mappings defined with ":lmap". */ |
| 929 | --no_mapping; |
| 930 | --allow_keys; |
| 931 | if (repl) |
| 932 | State = LREPLACE; |
| 933 | else |
| 934 | State = LANGMAP; |
| 935 | langmap_active = TRUE; |
| 936 | } |
| 937 | #ifdef USE_IM_CONTROL |
| 938 | save_smd = p_smd; |
| 939 | p_smd = FALSE; /* Don't let the IM code show the mode here */ |
| 940 | if (lang && curbuf->b_p_iminsert == B_IMODE_IM) |
| 941 | im_set_active(TRUE); |
| 942 | #endif |
| 943 | |
| 944 | *cp = safe_vgetc(); |
| 945 | |
| 946 | if (langmap_active) |
| 947 | { |
| 948 | /* Undo the decrement done above */ |
| 949 | ++no_mapping; |
| 950 | ++allow_keys; |
| 951 | State = NORMAL_BUSY; |
| 952 | } |
| 953 | #ifdef USE_IM_CONTROL |
| 954 | if (lang) |
| 955 | { |
| 956 | if (curbuf->b_p_iminsert != B_IMODE_LMAP) |
| 957 | im_save_status(&curbuf->b_p_iminsert); |
| 958 | im_set_active(FALSE); |
| 959 | } |
| 960 | p_smd = save_smd; |
| 961 | #endif |
| 962 | #ifdef CURSOR_SHAPE |
| 963 | State = NORMAL_BUSY; |
| 964 | #endif |
| 965 | #ifdef FEAT_CMDL_INFO |
| 966 | need_flushbuf |= add_to_showcmd(*cp); |
| 967 | #endif |
| 968 | |
| 969 | if (!lit) |
| 970 | { |
| 971 | #ifdef FEAT_DIGRAPHS |
| 972 | /* Typing CTRL-K gets a digraph. */ |
| 973 | if (*cp == Ctrl_K |
| 974 | && ((nv_cmds[idx].cmd_flags & NV_LANG) |
| 975 | || cp == &ca.extra_char) |
| 976 | && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) |
| 977 | { |
| 978 | c = get_digraph(FALSE); |
| 979 | if (c > 0) |
| 980 | { |
| 981 | *cp = c; |
| 982 | # ifdef FEAT_CMDL_INFO |
| 983 | /* Guessing how to update showcmd here... */ |
| 984 | del_from_showcmd(3); |
| 985 | need_flushbuf |= add_to_showcmd(*cp); |
| 986 | # endif |
| 987 | } |
| 988 | } |
| 989 | #endif |
| 990 | |
| 991 | #ifdef FEAT_LANGMAP |
| 992 | /* adjust chars > 127, except after "tTfFr" commands */ |
| 993 | LANGMAP_ADJUST(*cp, !lang); |
| 994 | #endif |
| 995 | #ifdef FEAT_RIGHTLEFT |
| 996 | /* adjust Hebrew mapped char */ |
| 997 | if (p_hkmap && lang && KeyTyped) |
| 998 | *cp = hkmap(*cp); |
| 999 | # ifdef FEAT_FKMAP |
| 1000 | /* adjust Farsi mapped char */ |
| 1001 | if (p_fkmap && lang && KeyTyped) |
| 1002 | *cp = fkmap(*cp); |
| 1003 | # endif |
| 1004 | #endif |
| 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * When the next character is CTRL-\ a following CTRL-N means the |
| 1009 | * command is aborted and we go to Normal mode. |
| 1010 | */ |
| 1011 | if (cp == &ca.extra_char |
| 1012 | && ca.nchar == Ctrl_BSL |
| 1013 | && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) |
| 1014 | { |
| 1015 | ca.cmdchar = Ctrl_BSL; |
| 1016 | ca.nchar = ca.extra_char; |
| 1017 | idx = find_command(ca.cmdchar); |
| 1018 | } |
| 1019 | else if (*cp == Ctrl_BSL) |
| 1020 | { |
| 1021 | long towait = (p_ttm >= 0 ? p_ttm : p_tm); |
| 1022 | |
| 1023 | /* There is a busy wait here when typing "f<C-\>" and then |
| 1024 | * something different from CTRL-N. Can't be avoided. */ |
| 1025 | while ((c = vpeekc()) <= 0 && towait > 0L) |
| 1026 | { |
| 1027 | do_sleep(towait > 50L ? 50L : towait); |
| 1028 | towait -= 50L; |
| 1029 | } |
| 1030 | if (c > 0) |
| 1031 | { |
| 1032 | c = safe_vgetc(); |
| 1033 | if (c != Ctrl_N && c != Ctrl_G) |
| 1034 | vungetc(c); |
| 1035 | else |
| 1036 | { |
| 1037 | ca.cmdchar = Ctrl_BSL; |
| 1038 | ca.nchar = c; |
| 1039 | idx = find_command(ca.cmdchar); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | #ifdef FEAT_MBYTE |
| 1045 | /* When getting a text character and the next character is a |
| 1046 | * multi-byte character, it could be a composing character. |
| 1047 | * However, don't wait for it to arrive. */ |
| 1048 | while (enc_utf8 && lang && (c = vpeekc()) > 0 |
| 1049 | && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) |
| 1050 | { |
| 1051 | c = safe_vgetc(); |
| 1052 | if (!utf_iscomposing(c)) |
| 1053 | { |
| 1054 | vungetc(c); /* it wasn't, put it back */ |
| 1055 | break; |
| 1056 | } |
| 1057 | else if (ca.ncharC1 == 0) |
| 1058 | ca.ncharC1 = c; |
| 1059 | else |
| 1060 | ca.ncharC2 = c; |
| 1061 | } |
| 1062 | #endif |
| 1063 | } |
| 1064 | --no_mapping; |
| 1065 | --allow_keys; |
| 1066 | } |
| 1067 | |
| 1068 | #ifdef FEAT_CMDL_INFO |
| 1069 | /* |
| 1070 | * Flush the showcmd characters onto the screen so we can see them while |
| 1071 | * the command is being executed. Only do this when the shown command was |
| 1072 | * actually displayed, otherwise this will slow down a lot when executing |
| 1073 | * mappings. |
| 1074 | */ |
| 1075 | if (need_flushbuf) |
| 1076 | out_flush(); |
| 1077 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 1078 | #ifdef FEAT_AUTOCMD |
| 1079 | did_cursorhold = FALSE; |
| 1080 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1081 | |
| 1082 | State = NORMAL; |
| 1083 | |
| 1084 | if (ca.nchar == ESC) |
| 1085 | { |
| 1086 | clearop(oap); |
| 1087 | if (restart_edit == 0 && goto_im()) |
| 1088 | restart_edit = 'a'; |
| 1089 | goto normal_end; |
| 1090 | } |
| 1091 | |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1092 | if (ca.cmdchar != K_IGNORE) |
| 1093 | { |
| 1094 | msg_didout = FALSE; /* don't scroll screen up for normal command */ |
| 1095 | msg_col = 0; |
| 1096 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1097 | |
| 1098 | #ifdef FEAT_VISUAL |
| 1099 | old_pos = curwin->w_cursor; /* remember where cursor was */ |
| 1100 | |
| 1101 | /* When 'keymodel' contains "startsel" some keys start Select/Visual |
| 1102 | * mode. */ |
| 1103 | if (!VIsual_active && km_startsel) |
| 1104 | { |
| 1105 | if (nv_cmds[idx].cmd_flags & NV_SS) |
| 1106 | { |
| 1107 | start_selection(); |
| 1108 | unshift_special(&ca); |
| 1109 | idx = find_command(ca.cmdchar); |
| 1110 | } |
| 1111 | else if ((nv_cmds[idx].cmd_flags & NV_SSS) |
| 1112 | && (mod_mask & MOD_MASK_SHIFT)) |
| 1113 | { |
| 1114 | start_selection(); |
| 1115 | mod_mask &= ~MOD_MASK_SHIFT; |
| 1116 | } |
| 1117 | } |
| 1118 | #endif |
| 1119 | |
| 1120 | /* |
| 1121 | * Execute the command! |
| 1122 | * Call the command function found in the commands table. |
| 1123 | */ |
| 1124 | ca.arg = nv_cmds[idx].cmd_arg; |
| 1125 | (nv_cmds[idx].cmd_func)(&ca); |
| 1126 | |
| 1127 | /* |
| 1128 | * If we didn't start or finish an operator, reset oap->regname, unless we |
| 1129 | * need it later. |
| 1130 | */ |
| 1131 | if (!finish_op |
| 1132 | && !oap->op_type |
| 1133 | && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) |
| 1134 | { |
| 1135 | clearop(oap); |
| 1136 | #ifdef FEAT_EVAL |
| 1137 | set_reg_var('"'); |
| 1138 | #endif |
| 1139 | } |
| 1140 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1141 | /* get the length of mapped chars again after typing a count, second |
| 1142 | * character or "z333<cr>". */ |
| 1143 | if (old_mapped_len > 0) |
| 1144 | old_mapped_len = typebuf_maplen(); |
| 1145 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1146 | /* |
| 1147 | * If an operation is pending, handle it... |
| 1148 | */ |
| 1149 | do_pending_operator(&ca, old_col, FALSE); |
| 1150 | |
| 1151 | /* |
| 1152 | * Wait for a moment when a message is displayed that will be overwritten |
| 1153 | * by the mode message. |
| 1154 | * In Visual mode and with "^O" in Insert mode, a short message will be |
| 1155 | * overwritten by the mode message. Wait a bit, until a key is hit. |
| 1156 | * In Visual mode, it's more important to keep the Visual area updated |
| 1157 | * than keeping a message (e.g. from a /pat search). |
| 1158 | * Only do this if the command was typed, not from a mapping. |
| 1159 | * Don't wait when emsg_silent is non-zero. |
| 1160 | * Also wait a bit after an error message, e.g. for "^O:". |
| 1161 | * Don't redraw the screen, it would remove the message. |
| 1162 | */ |
| 1163 | if ( ((p_smd |
| 1164 | && (restart_edit != 0 |
| 1165 | #ifdef FEAT_VISUAL |
| 1166 | || (VIsual_active |
| 1167 | && old_pos.lnum == curwin->w_cursor.lnum |
| 1168 | && old_pos.col == curwin->w_cursor.col) |
| 1169 | #endif |
| 1170 | ) |
| 1171 | && (clear_cmdline |
| 1172 | || redraw_cmdline) |
| 1173 | && (msg_didout || (msg_didany && msg_scroll)) |
| 1174 | && !msg_nowait |
| 1175 | && KeyTyped) |
| 1176 | || (restart_edit != 0 |
| 1177 | #ifdef FEAT_VISUAL |
| 1178 | && !VIsual_active |
| 1179 | #endif |
| 1180 | && (msg_scroll |
| 1181 | || emsg_on_display))) |
| 1182 | && oap->regname == 0 |
| 1183 | && !(ca.retval & CA_COMMAND_BUSY) |
| 1184 | && stuff_empty() |
| 1185 | && typebuf_typed() |
| 1186 | && emsg_silent == 0 |
| 1187 | && !did_wait_return |
| 1188 | && oap->op_type == OP_NOP) |
| 1189 | { |
| 1190 | int save_State = State; |
| 1191 | |
| 1192 | /* Draw the cursor with the right shape here */ |
| 1193 | if (restart_edit != 0) |
| 1194 | State = INSERT; |
| 1195 | |
| 1196 | /* If need to redraw, and there is a "keep_msg", redraw before the |
| 1197 | * delay */ |
| 1198 | if (must_redraw && keep_msg != NULL && !emsg_on_display) |
| 1199 | { |
| 1200 | char_u *kmsg; |
| 1201 | |
| 1202 | kmsg = keep_msg; |
| 1203 | keep_msg = NULL; |
| 1204 | /* showmode() will clear keep_msg, but we want to use it anyway */ |
| 1205 | update_screen(0); |
| 1206 | /* now reset it, otherwise it's put in the history again */ |
| 1207 | keep_msg = kmsg; |
| 1208 | msg_attr(kmsg, keep_msg_attr); |
| 1209 | vim_free(kmsg); |
| 1210 | } |
| 1211 | setcursor(); |
| 1212 | cursor_on(); |
| 1213 | out_flush(); |
| 1214 | if (msg_scroll || emsg_on_display) |
| 1215 | ui_delay(1000L, TRUE); /* wait at least one second */ |
| 1216 | ui_delay(3000L, FALSE); /* wait up to three seconds */ |
| 1217 | State = save_State; |
| 1218 | |
| 1219 | msg_scroll = FALSE; |
| 1220 | emsg_on_display = FALSE; |
| 1221 | } |
| 1222 | |
| 1223 | /* |
| 1224 | * Finish up after executing a Normal mode command. |
| 1225 | */ |
| 1226 | normal_end: |
| 1227 | |
| 1228 | msg_nowait = FALSE; |
| 1229 | |
| 1230 | /* Reset finish_op, in case it was set */ |
| 1231 | #ifdef CURSOR_SHAPE |
| 1232 | c = finish_op; |
| 1233 | #endif |
| 1234 | finish_op = FALSE; |
| 1235 | #ifdef CURSOR_SHAPE |
| 1236 | /* Redraw the cursor with another shape, if we were in Operator-pending |
| 1237 | * mode or did a replace command. */ |
| 1238 | if (c || ca.cmdchar == 'r') |
| 1239 | { |
| 1240 | ui_cursor_shape(); /* may show different cursor shape */ |
| 1241 | # ifdef FEAT_MOUSESHAPE |
| 1242 | update_mouseshape(-1); |
| 1243 | # endif |
| 1244 | } |
| 1245 | #endif |
| 1246 | |
| 1247 | #ifdef FEAT_CMDL_INFO |
| 1248 | if (oap->op_type == OP_NOP && oap->regname == 0) |
| 1249 | clear_showcmd(); |
| 1250 | #endif |
| 1251 | |
| 1252 | checkpcmark(); /* check if we moved since setting pcmark */ |
| 1253 | vim_free(ca.searchbuf); |
| 1254 | |
| 1255 | #ifdef FEAT_MBYTE |
| 1256 | if (has_mbyte) |
| 1257 | mb_adjust_cursor(); |
| 1258 | #endif |
| 1259 | |
| 1260 | #ifdef FEAT_SCROLLBIND |
| 1261 | if (curwin->w_p_scb && toplevel) |
| 1262 | { |
| 1263 | validate_cursor(); /* may need to update w_leftcol */ |
| 1264 | do_check_scrollbind(TRUE); |
| 1265 | } |
| 1266 | #endif |
| 1267 | |
| 1268 | /* |
| 1269 | * May restart edit(), if we got here with CTRL-O in Insert mode (but not |
| 1270 | * if still inside a mapping that started in Visual mode). |
| 1271 | * May switch from Visual to Select mode after CTRL-O command. |
| 1272 | */ |
| 1273 | if ( oap->op_type == OP_NOP |
| 1274 | #ifdef FEAT_VISUAL |
| 1275 | && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
| 1276 | || restart_VIsual_select == 1) |
| 1277 | #endif |
| 1278 | && !(ca.retval & CA_COMMAND_BUSY) |
| 1279 | && stuff_empty() |
| 1280 | && oap->regname == 0) |
| 1281 | { |
| 1282 | #ifdef FEAT_VISUAL |
| 1283 | if (restart_VIsual_select == 1) |
| 1284 | { |
| 1285 | VIsual_select = TRUE; |
| 1286 | showmode(); |
| 1287 | restart_VIsual_select = 0; |
| 1288 | } |
| 1289 | #endif |
| 1290 | if (restart_edit != 0 |
| 1291 | #ifdef FEAT_VISUAL |
| 1292 | && !VIsual_active |
| 1293 | #endif |
| 1294 | && old_mapped_len == 0) |
| 1295 | (void)edit(restart_edit, FALSE, 1L); |
| 1296 | } |
| 1297 | |
| 1298 | #ifdef FEAT_VISUAL |
| 1299 | if (restart_VIsual_select == 2) |
| 1300 | restart_VIsual_select = 1; |
| 1301 | #endif |
| 1302 | |
| 1303 | /* Save count before an operator for next time. */ |
| 1304 | opcount = ca.opcount; |
| 1305 | } |
| 1306 | |
| 1307 | /* |
| 1308 | * Handle an operator after visual mode or when the movement is finished |
| 1309 | */ |
| 1310 | void |
| 1311 | do_pending_operator(cap, old_col, gui_yank) |
| 1312 | cmdarg_T *cap; |
| 1313 | int old_col; |
| 1314 | int gui_yank; |
| 1315 | { |
| 1316 | oparg_T *oap = cap->oap; |
| 1317 | pos_T old_cursor; |
| 1318 | int empty_region_error; |
| 1319 | int restart_edit_save; |
| 1320 | |
| 1321 | #ifdef FEAT_VISUAL |
| 1322 | /* The visual area is remembered for redo */ |
| 1323 | static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ |
| 1324 | static linenr_T redo_VIsual_line_count; /* number of lines */ |
| 1325 | static colnr_T redo_VIsual_col; /* number of cols or end column */ |
| 1326 | static long redo_VIsual_count; /* count for Visual operator */ |
| 1327 | # ifdef FEAT_VIRTUALEDIT |
| 1328 | int include_line_break = FALSE; |
| 1329 | # endif |
| 1330 | #endif |
| 1331 | |
| 1332 | #if defined(FEAT_CLIPBOARD) |
| 1333 | /* |
| 1334 | * Yank the visual area into the GUI selection register before we operate |
| 1335 | * on it and lose it forever. |
| 1336 | * Don't do it if a specific register was specified, so that ""x"*P works. |
| 1337 | * This could call do_pending_operator() recursively, but that's OK |
| 1338 | * because gui_yank will be TRUE for the nested call. |
| 1339 | */ |
| 1340 | if (clip_star.available |
| 1341 | && oap->op_type != OP_NOP |
| 1342 | && !gui_yank |
| 1343 | # ifdef FEAT_VISUAL |
| 1344 | && VIsual_active |
| 1345 | && !redo_VIsual_busy |
| 1346 | # endif |
| 1347 | && oap->regname == 0) |
| 1348 | clip_auto_select(); |
| 1349 | #endif |
| 1350 | old_cursor = curwin->w_cursor; |
| 1351 | |
| 1352 | /* |
| 1353 | * If an operation is pending, handle it... |
| 1354 | */ |
| 1355 | if ((finish_op |
| 1356 | #ifdef FEAT_VISUAL |
| 1357 | || VIsual_active |
| 1358 | #endif |
| 1359 | ) && oap->op_type != OP_NOP) |
| 1360 | { |
| 1361 | #ifdef FEAT_VISUAL |
| 1362 | oap->is_VIsual = VIsual_active; |
| 1363 | if (oap->motion_force == 'V') |
| 1364 | oap->motion_type = MLINE; |
| 1365 | else if (oap->motion_force == 'v') |
| 1366 | { |
| 1367 | /* If the motion was linewise, "inclusive" will not have been set. |
| 1368 | * Use "exclusive" to be consistent. Makes "dvj" work nice. */ |
| 1369 | if (oap->motion_type == MLINE) |
| 1370 | oap->inclusive = FALSE; |
| 1371 | /* If the motion already was characterwise, toggle "inclusive" */ |
| 1372 | else if (oap->motion_type == MCHAR) |
| 1373 | oap->inclusive = !oap->inclusive; |
| 1374 | oap->motion_type = MCHAR; |
| 1375 | } |
| 1376 | else if (oap->motion_force == Ctrl_V) |
| 1377 | { |
| 1378 | /* Change line- or characterwise motion into Visual block mode. */ |
| 1379 | VIsual_active = TRUE; |
| 1380 | VIsual = oap->start; |
| 1381 | VIsual_mode = Ctrl_V; |
| 1382 | VIsual_select = FALSE; |
| 1383 | VIsual_reselect = FALSE; |
| 1384 | } |
| 1385 | #endif |
| 1386 | |
| 1387 | /* only redo yank when 'y' flag is in 'cpoptions' */ |
| 1388 | /* never redo "zf" (define fold) */ |
| 1389 | if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
| 1390 | #ifdef FEAT_VISUAL |
| 1391 | && (!VIsual_active || oap->motion_force) |
| 1392 | #endif |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 1393 | && cap->cmdchar != 'D' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1394 | #ifdef FEAT_FOLDING |
| 1395 | && oap->op_type != OP_FOLD |
| 1396 | && oap->op_type != OP_FOLDOPEN |
| 1397 | && oap->op_type != OP_FOLDOPENREC |
| 1398 | && oap->op_type != OP_FOLDCLOSE |
| 1399 | && oap->op_type != OP_FOLDCLOSEREC |
| 1400 | && oap->op_type != OP_FOLDDEL |
| 1401 | && oap->op_type != OP_FOLDDELREC |
| 1402 | #endif |
| 1403 | ) |
| 1404 | { |
| 1405 | prep_redo(oap->regname, cap->count0, |
| 1406 | get_op_char(oap->op_type), get_extra_op_char(oap->op_type), |
| 1407 | oap->motion_force, cap->cmdchar, cap->nchar); |
| 1408 | if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ |
| 1409 | { |
| 1410 | /* |
| 1411 | * If 'cpoptions' does not contain 'r', insert the search |
| 1412 | * pattern to really repeat the same command. |
| 1413 | */ |
| 1414 | if (vim_strchr(p_cpo, CPO_REDO) == NULL) |
| 1415 | AppendToRedobuffLit(cap->searchbuf); |
| 1416 | AppendToRedobuff(NL_STR); |
| 1417 | } |
| 1418 | else if (cap->cmdchar == ':') |
| 1419 | { |
| 1420 | /* do_cmdline() has stored the first typed line in |
| 1421 | * "repeat_cmdline". When several lines are typed repeating |
| 1422 | * won't be possible. */ |
| 1423 | if (repeat_cmdline == NULL) |
| 1424 | ResetRedobuff(); |
| 1425 | else |
| 1426 | { |
| 1427 | AppendToRedobuffLit(repeat_cmdline); |
| 1428 | AppendToRedobuff(NL_STR); |
| 1429 | vim_free(repeat_cmdline); |
| 1430 | repeat_cmdline = NULL; |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | #ifdef FEAT_VISUAL |
| 1436 | if (redo_VIsual_busy) |
| 1437 | { |
| 1438 | oap->start = curwin->w_cursor; |
| 1439 | curwin->w_cursor.lnum += redo_VIsual_line_count - 1; |
| 1440 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 1441 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 1442 | VIsual_mode = redo_VIsual_mode; |
| 1443 | if (VIsual_mode == 'v') |
| 1444 | { |
| 1445 | if (redo_VIsual_line_count <= 1) |
| 1446 | curwin->w_cursor.col += redo_VIsual_col - 1; |
| 1447 | else |
| 1448 | curwin->w_cursor.col = redo_VIsual_col; |
| 1449 | } |
| 1450 | if (redo_VIsual_col == MAXCOL) |
| 1451 | { |
| 1452 | curwin->w_curswant = MAXCOL; |
| 1453 | coladvance((colnr_T)MAXCOL); |
| 1454 | } |
| 1455 | cap->count0 = redo_VIsual_count; |
| 1456 | if (redo_VIsual_count != 0) |
| 1457 | cap->count1 = redo_VIsual_count; |
| 1458 | else |
| 1459 | cap->count1 = 1; |
| 1460 | } |
| 1461 | else if (VIsual_active) |
| 1462 | { |
| 1463 | /* Save the current VIsual area for '< and '> marks, and "gv" */ |
| 1464 | curbuf->b_visual_start = VIsual; |
| 1465 | curbuf->b_visual_end = curwin->w_cursor; |
| 1466 | curbuf->b_visual_mode = VIsual_mode; |
| 1467 | # ifdef FEAT_EVAL |
| 1468 | curbuf->b_visual_mode_eval = VIsual_mode; |
| 1469 | # endif |
| 1470 | curbuf->b_visual_curswant = curwin->w_curswant; |
| 1471 | |
| 1472 | /* In Select mode, a linewise selection is operated upon like a |
| 1473 | * characterwise selection. */ |
| 1474 | if (VIsual_select && VIsual_mode == 'V') |
| 1475 | { |
| 1476 | if (lt(VIsual, curwin->w_cursor)) |
| 1477 | { |
| 1478 | VIsual.col = 0; |
| 1479 | curwin->w_cursor.col = |
| 1480 | (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); |
| 1481 | } |
| 1482 | else |
| 1483 | { |
| 1484 | curwin->w_cursor.col = 0; |
| 1485 | VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); |
| 1486 | } |
| 1487 | VIsual_mode = 'v'; |
| 1488 | } |
| 1489 | /* If 'selection' is "exclusive", backup one character for |
| 1490 | * charwise selections. */ |
| 1491 | else if (VIsual_mode == 'v') |
| 1492 | { |
| 1493 | # ifdef FEAT_VIRTUALEDIT |
| 1494 | include_line_break = |
| 1495 | # endif |
| 1496 | unadjust_for_sel(); |
| 1497 | } |
| 1498 | |
| 1499 | oap->start = VIsual; |
| 1500 | if (VIsual_mode == 'V') |
| 1501 | oap->start.col = 0; |
| 1502 | } |
| 1503 | #endif /* FEAT_VISUAL */ |
| 1504 | |
| 1505 | /* |
| 1506 | * Set oap->start to the first position of the operated text, oap->end |
| 1507 | * to the end of the operated text. w_cursor is equal to oap->start. |
| 1508 | */ |
| 1509 | if (lt(oap->start, curwin->w_cursor)) |
| 1510 | { |
| 1511 | #ifdef FEAT_FOLDING |
| 1512 | /* Include folded lines completely. */ |
| 1513 | if (!VIsual_active) |
| 1514 | { |
| 1515 | if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) |
| 1516 | oap->start.col = 0; |
| 1517 | if (hasFolding(curwin->w_cursor.lnum, NULL, |
| 1518 | &curwin->w_cursor.lnum)) |
| 1519 | curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); |
| 1520 | } |
| 1521 | #endif |
| 1522 | oap->end = curwin->w_cursor; |
| 1523 | curwin->w_cursor = oap->start; |
| 1524 | |
| 1525 | /* w_virtcol may have been updated; if the cursor goes back to its |
| 1526 | * previous position w_virtcol becomes invalid and isn't updated |
| 1527 | * automatically. */ |
| 1528 | curwin->w_valid &= ~VALID_VIRTCOL; |
| 1529 | } |
| 1530 | else |
| 1531 | { |
| 1532 | #ifdef FEAT_FOLDING |
| 1533 | /* Include folded lines completely. */ |
| 1534 | if (!VIsual_active && oap->motion_type == MLINE) |
| 1535 | { |
| 1536 | if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, |
| 1537 | NULL)) |
| 1538 | curwin->w_cursor.col = 0; |
| 1539 | if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) |
| 1540 | oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); |
| 1541 | } |
| 1542 | #endif |
| 1543 | oap->end = oap->start; |
| 1544 | oap->start = curwin->w_cursor; |
| 1545 | } |
| 1546 | |
| 1547 | oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
| 1548 | |
| 1549 | #ifdef FEAT_VIRTUALEDIT |
| 1550 | /* Set "virtual_op" before resetting VIsual_active. */ |
| 1551 | virtual_op = virtual_active(); |
| 1552 | #endif |
| 1553 | |
| 1554 | #ifdef FEAT_VISUAL |
| 1555 | if (VIsual_active || redo_VIsual_busy) |
| 1556 | { |
| 1557 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 1558 | { |
| 1559 | colnr_T start, end; |
| 1560 | |
| 1561 | oap->block_mode = TRUE; |
| 1562 | |
| 1563 | getvvcol(curwin, &(oap->start), |
| 1564 | &oap->start_vcol, NULL, &oap->end_vcol); |
| 1565 | if (!redo_VIsual_busy) |
| 1566 | { |
| 1567 | getvvcol(curwin, &(oap->end), &start, NULL, &end); |
| 1568 | |
| 1569 | if (start < oap->start_vcol) |
| 1570 | oap->start_vcol = start; |
| 1571 | if (end > oap->end_vcol) |
| 1572 | { |
| 1573 | if (*p_sel == 'e' && start >= 1 |
| 1574 | && start - 1 >= oap->end_vcol) |
| 1575 | oap->end_vcol = start - 1; |
| 1576 | else |
| 1577 | oap->end_vcol = end; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | /* if '$' was used, get oap->end_vcol from longest line */ |
| 1582 | if (curwin->w_curswant == MAXCOL) |
| 1583 | { |
| 1584 | curwin->w_cursor.col = MAXCOL; |
| 1585 | oap->end_vcol = 0; |
| 1586 | for (curwin->w_cursor.lnum = oap->start.lnum; |
| 1587 | curwin->w_cursor.lnum <= oap->end.lnum; |
| 1588 | ++curwin->w_cursor.lnum) |
| 1589 | { |
| 1590 | getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); |
| 1591 | if (end > oap->end_vcol) |
| 1592 | oap->end_vcol = end; |
| 1593 | } |
| 1594 | } |
| 1595 | else if (redo_VIsual_busy) |
| 1596 | oap->end_vcol = oap->start_vcol + redo_VIsual_col - 1; |
| 1597 | /* |
| 1598 | * Correct oap->end.col and oap->start.col to be the |
| 1599 | * upper-left and lower-right corner of the block area. |
| 1600 | * |
| 1601 | * (Actually, this does convert column positions into character |
| 1602 | * positions) |
| 1603 | */ |
| 1604 | curwin->w_cursor.lnum = oap->end.lnum; |
| 1605 | coladvance(oap->end_vcol); |
| 1606 | oap->end = curwin->w_cursor; |
| 1607 | |
| 1608 | curwin->w_cursor = oap->start; |
| 1609 | coladvance(oap->start_vcol); |
| 1610 | oap->start = curwin->w_cursor; |
| 1611 | } |
| 1612 | |
| 1613 | if (!redo_VIsual_busy && !gui_yank) |
| 1614 | { |
| 1615 | /* |
| 1616 | * Prepare to reselect and redo Visual: this is based on the |
| 1617 | * size of the Visual text |
| 1618 | */ |
| 1619 | resel_VIsual_mode = VIsual_mode; |
| 1620 | if (curwin->w_curswant == MAXCOL) |
| 1621 | resel_VIsual_col = MAXCOL; |
| 1622 | else if (VIsual_mode == Ctrl_V) |
| 1623 | resel_VIsual_col = oap->end_vcol - oap->start_vcol + 1; |
| 1624 | else if (oap->line_count > 1) |
| 1625 | resel_VIsual_col = oap->end.col; |
| 1626 | else |
| 1627 | resel_VIsual_col = oap->end.col - oap->start.col + 1; |
| 1628 | resel_VIsual_line_count = oap->line_count; |
| 1629 | } |
| 1630 | |
| 1631 | /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ |
| 1632 | if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
| 1633 | && oap->op_type != OP_COLON |
| 1634 | #ifdef FEAT_FOLDING |
| 1635 | && oap->op_type != OP_FOLD |
| 1636 | && oap->op_type != OP_FOLDOPEN |
| 1637 | && oap->op_type != OP_FOLDOPENREC |
| 1638 | && oap->op_type != OP_FOLDCLOSE |
| 1639 | && oap->op_type != OP_FOLDCLOSEREC |
| 1640 | && oap->op_type != OP_FOLDDEL |
| 1641 | && oap->op_type != OP_FOLDDELREC |
| 1642 | #endif |
| 1643 | && oap->motion_force == NUL |
| 1644 | ) |
| 1645 | { |
| 1646 | /* Prepare for redoing. Only use the nchar field for "r", |
| 1647 | * otherwise it might be the second char of the operator. */ |
| 1648 | prep_redo(oap->regname, 0L, NUL, 'v', |
| 1649 | get_op_char(oap->op_type), |
| 1650 | get_extra_op_char(oap->op_type), |
| 1651 | oap->op_type == OP_REPLACE ? cap->nchar : NUL); |
| 1652 | if (!redo_VIsual_busy) |
| 1653 | { |
| 1654 | redo_VIsual_mode = resel_VIsual_mode; |
| 1655 | redo_VIsual_col = resel_VIsual_col; |
| 1656 | redo_VIsual_line_count = resel_VIsual_line_count; |
| 1657 | redo_VIsual_count = cap->count0; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /* |
| 1662 | * oap->inclusive defaults to TRUE. |
| 1663 | * If oap->end is on a NUL (empty line) oap->inclusive becomes |
| 1664 | * FALSE. This makes "d}P" and "v}dP" work the same. |
| 1665 | */ |
| 1666 | if (oap->motion_force == NUL || oap->motion_type == MLINE) |
| 1667 | oap->inclusive = TRUE; |
| 1668 | if (VIsual_mode == 'V') |
| 1669 | oap->motion_type = MLINE; |
| 1670 | else |
| 1671 | { |
| 1672 | oap->motion_type = MCHAR; |
| 1673 | if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL |
| 1674 | # ifdef FEAT_VIRTUALEDIT |
| 1675 | && (include_line_break || !virtual_op) |
| 1676 | # endif |
| 1677 | ) |
| 1678 | { |
| 1679 | oap->inclusive = FALSE; |
| 1680 | /* Try to include the newline, unless it's an operator |
| 1681 | * that works on lines only */ |
| 1682 | if (*p_sel != 'o' |
| 1683 | && !op_on_lines(oap->op_type) |
| 1684 | && oap->end.lnum < curbuf->b_ml.ml_line_count) |
| 1685 | { |
| 1686 | ++oap->end.lnum; |
| 1687 | oap->end.col = 0; |
| 1688 | # ifdef FEAT_VIRTUALEDIT |
| 1689 | oap->end.coladd = 0; |
| 1690 | # endif |
| 1691 | ++oap->line_count; |
| 1692 | } |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | redo_VIsual_busy = FALSE; |
| 1697 | /* |
| 1698 | * Switch Visual off now, so screen updating does |
| 1699 | * not show inverted text when the screen is redrawn. |
| 1700 | * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is |
| 1701 | * no screen redraw, so it is done here to remove the inverted |
| 1702 | * part. |
| 1703 | */ |
| 1704 | if (!gui_yank) |
| 1705 | { |
| 1706 | VIsual_active = FALSE; |
| 1707 | # ifdef FEAT_MOUSE |
| 1708 | setmouse(); |
| 1709 | mouse_dragging = 0; |
| 1710 | # endif |
| 1711 | if (p_smd) |
| 1712 | clear_cmdline = TRUE; /* unshow visual mode later */ |
| 1713 | #ifdef FEAT_CMDL_INFO |
| 1714 | else |
| 1715 | clear_showcmd(); |
| 1716 | #endif |
| 1717 | if ((oap->op_type == OP_YANK |
| 1718 | || oap->op_type == OP_COLON |
| 1719 | || oap->op_type == OP_FILTER) |
| 1720 | && oap->motion_force == NUL) |
| 1721 | redraw_curbuf_later(INVERTED); |
| 1722 | } |
| 1723 | } |
| 1724 | #endif |
| 1725 | |
| 1726 | #ifdef FEAT_MBYTE |
| 1727 | /* Include the trailing byte of a multi-byte char. */ |
| 1728 | if (has_mbyte && oap->inclusive) |
| 1729 | { |
| 1730 | int l; |
| 1731 | |
| 1732 | l = (*mb_ptr2len_check)(ml_get_pos(&oap->end)); |
| 1733 | if (l > 1) |
| 1734 | oap->end.col += l - 1; |
| 1735 | } |
| 1736 | #endif |
| 1737 | curwin->w_set_curswant = TRUE; |
| 1738 | |
| 1739 | /* |
| 1740 | * oap->empty is set when start and end are the same. The inclusive |
| 1741 | * flag affects this too, unless yanking and the end is on a NUL. |
| 1742 | */ |
| 1743 | oap->empty = (oap->motion_type == MCHAR |
| 1744 | && (!oap->inclusive |
| 1745 | || (oap->op_type == OP_YANK |
| 1746 | && gchar_pos(&oap->end) == NUL)) |
| 1747 | && equalpos(oap->start, oap->end) |
| 1748 | #ifdef FEAT_VIRTUALEDIT |
| 1749 | && !(virtual_op && oap->start.coladd != oap->end.coladd) |
| 1750 | #endif |
| 1751 | ); |
| 1752 | /* |
| 1753 | * For delete, change and yank, it's an error to operate on an |
| 1754 | * empty region, when 'E' included in 'cpoptions' (Vi compatible). |
| 1755 | */ |
| 1756 | empty_region_error = (oap->empty |
| 1757 | && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); |
| 1758 | |
| 1759 | #ifdef FEAT_VISUAL |
| 1760 | /* Force a redraw when operating on an empty Visual region, when |
| 1761 | * 'modifiable is off or creating a fold. */ |
| 1762 | if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma |
| 1763 | # ifdef FEAT_FOLDING |
| 1764 | || oap->op_type == OP_FOLD |
| 1765 | # endif |
| 1766 | )) |
| 1767 | redraw_curbuf_later(INVERTED); |
| 1768 | #endif |
| 1769 | |
| 1770 | /* |
| 1771 | * If the end of an operator is in column one while oap->motion_type |
| 1772 | * is MCHAR and oap->inclusive is FALSE, we put op_end after the last |
| 1773 | * character in the previous line. If op_start is on or before the |
| 1774 | * first non-blank in the line, the operator becomes linewise |
| 1775 | * (strange, but that's the way vi does it). |
| 1776 | */ |
| 1777 | if ( oap->motion_type == MCHAR |
| 1778 | && oap->inclusive == FALSE |
| 1779 | && !(cap->retval & CA_NO_ADJ_OP_END) |
| 1780 | && oap->end.col == 0 |
| 1781 | #ifdef FEAT_VISUAL |
| 1782 | && (!oap->is_VIsual || *p_sel == 'o') |
Bram Moolenaar | 3411469 | 2005-01-02 11:28:13 +0000 | [diff] [blame] | 1783 | && !oap->block_mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1784 | #endif |
| 1785 | && oap->line_count > 1) |
| 1786 | { |
| 1787 | oap->end_adjusted = TRUE; /* remember that we did this */ |
| 1788 | --oap->line_count; |
| 1789 | --oap->end.lnum; |
| 1790 | if (inindent(0)) |
| 1791 | oap->motion_type = MLINE; |
| 1792 | else |
| 1793 | { |
| 1794 | oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); |
| 1795 | if (oap->end.col) |
| 1796 | { |
| 1797 | --oap->end.col; |
| 1798 | oap->inclusive = TRUE; |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | else |
| 1803 | oap->end_adjusted = FALSE; |
| 1804 | |
| 1805 | switch (oap->op_type) |
| 1806 | { |
| 1807 | case OP_LSHIFT: |
| 1808 | case OP_RSHIFT: |
| 1809 | op_shift(oap, TRUE, |
| 1810 | #ifdef FEAT_VISUAL |
| 1811 | oap->is_VIsual ? (int)cap->count1 : |
| 1812 | #endif |
| 1813 | 1); |
| 1814 | auto_format(FALSE, TRUE); |
| 1815 | break; |
| 1816 | |
| 1817 | case OP_JOIN_NS: |
| 1818 | case OP_JOIN: |
| 1819 | if (oap->line_count < 2) |
| 1820 | oap->line_count = 2; |
| 1821 | if (curwin->w_cursor.lnum + oap->line_count - 1 > |
| 1822 | curbuf->b_ml.ml_line_count) |
| 1823 | beep_flush(); |
| 1824 | else |
| 1825 | { |
| 1826 | do_do_join(oap->line_count, oap->op_type == OP_JOIN); |
| 1827 | auto_format(FALSE, TRUE); |
| 1828 | } |
| 1829 | break; |
| 1830 | |
| 1831 | case OP_DELETE: |
| 1832 | #ifdef FEAT_VISUAL |
| 1833 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1834 | #endif |
| 1835 | if (empty_region_error) |
| 1836 | vim_beep(); |
| 1837 | else |
| 1838 | { |
| 1839 | (void)op_delete(oap); |
| 1840 | if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) |
| 1841 | u_save_cursor(); /* cursor line wasn't saved yet */ |
| 1842 | auto_format(FALSE, TRUE); |
| 1843 | } |
| 1844 | break; |
| 1845 | |
| 1846 | case OP_YANK: |
| 1847 | if (empty_region_error) |
| 1848 | { |
| 1849 | if (!gui_yank) |
| 1850 | vim_beep(); |
| 1851 | } |
| 1852 | else |
| 1853 | (void)op_yank(oap, FALSE, !gui_yank); |
| 1854 | check_cursor_col(); |
| 1855 | break; |
| 1856 | |
| 1857 | case OP_CHANGE: |
| 1858 | #ifdef FEAT_VISUAL |
| 1859 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1860 | #endif |
| 1861 | if (empty_region_error) |
| 1862 | vim_beep(); |
| 1863 | else |
| 1864 | { |
| 1865 | /* This is a new edit command, not a restart. Need to |
| 1866 | * remember it to make 'insertmode' work with mappings for |
| 1867 | * Visual mode. But do this only once and not when typed and |
| 1868 | * 'insertmode' isn't set. */ |
| 1869 | if (p_im || !KeyTyped) |
| 1870 | restart_edit_save = restart_edit; |
| 1871 | else |
| 1872 | restart_edit_save = 0; |
| 1873 | restart_edit = 0; |
| 1874 | /* Reset finish_op now, don't want it set inside edit(). */ |
| 1875 | finish_op = FALSE; |
| 1876 | if (op_change(oap)) /* will call edit() */ |
| 1877 | cap->retval |= CA_COMMAND_BUSY; |
| 1878 | if (restart_edit == 0) |
| 1879 | restart_edit = restart_edit_save; |
| 1880 | } |
| 1881 | break; |
| 1882 | |
| 1883 | case OP_FILTER: |
| 1884 | if (vim_strchr(p_cpo, CPO_FILTER) != NULL) |
| 1885 | AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ |
| 1886 | else |
| 1887 | bangredo = TRUE; /* do_bang() will put cmd in redo buffer */ |
| 1888 | |
| 1889 | case OP_INDENT: |
| 1890 | case OP_COLON: |
| 1891 | |
| 1892 | #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
| 1893 | /* |
| 1894 | * If 'equalprg' is empty, do the indenting internally. |
| 1895 | */ |
| 1896 | if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) |
| 1897 | { |
| 1898 | # ifdef FEAT_LISP |
| 1899 | if (curbuf->b_p_lisp) |
| 1900 | { |
| 1901 | op_reindent(oap, get_lisp_indent); |
| 1902 | break; |
| 1903 | } |
| 1904 | # endif |
| 1905 | # ifdef FEAT_CINDENT |
| 1906 | op_reindent(oap, |
| 1907 | # ifdef FEAT_EVAL |
| 1908 | *curbuf->b_p_inde != NUL ? get_expr_indent : |
| 1909 | # endif |
| 1910 | get_c_indent); |
| 1911 | break; |
| 1912 | # endif |
| 1913 | } |
| 1914 | #endif |
| 1915 | |
| 1916 | op_colon(oap); |
| 1917 | break; |
| 1918 | |
| 1919 | case OP_TILDE: |
| 1920 | case OP_UPPER: |
| 1921 | case OP_LOWER: |
| 1922 | case OP_ROT13: |
| 1923 | if (empty_region_error) |
| 1924 | vim_beep(); |
| 1925 | else |
| 1926 | op_tilde(oap); |
| 1927 | check_cursor_col(); |
| 1928 | break; |
| 1929 | |
| 1930 | case OP_FORMAT: |
| 1931 | if (*p_fp != NUL) |
| 1932 | op_colon(oap); /* use external command */ |
| 1933 | else |
| 1934 | op_format(oap, FALSE); /* use internal function */ |
| 1935 | break; |
| 1936 | |
| 1937 | case OP_FORMAT2: |
| 1938 | op_format(oap, TRUE); /* use internal function */ |
| 1939 | break; |
| 1940 | |
| 1941 | case OP_INSERT: |
| 1942 | case OP_APPEND: |
| 1943 | #ifdef FEAT_VISUAL |
| 1944 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1945 | #endif |
| 1946 | #ifdef FEAT_VISUALEXTRA |
| 1947 | if (empty_region_error) |
| 1948 | vim_beep(); |
| 1949 | else |
| 1950 | { |
| 1951 | /* This is a new edit command, not a restart. Need to |
| 1952 | * remember it to make 'insertmode' work with mappings for |
| 1953 | * Visual mode. But do this only once. */ |
| 1954 | restart_edit_save = restart_edit; |
| 1955 | restart_edit = 0; |
| 1956 | |
| 1957 | op_insert(oap, cap->count1); |
| 1958 | |
| 1959 | /* TODO: when inserting in several lines, should format all |
| 1960 | * the lines. */ |
| 1961 | auto_format(FALSE, TRUE); |
| 1962 | |
| 1963 | if (restart_edit == 0) |
| 1964 | restart_edit = restart_edit_save; |
| 1965 | } |
| 1966 | #else |
| 1967 | vim_beep(); |
| 1968 | #endif |
| 1969 | break; |
| 1970 | |
| 1971 | case OP_REPLACE: |
| 1972 | #ifdef FEAT_VISUAL |
| 1973 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1974 | #endif |
| 1975 | #ifdef FEAT_VISUALEXTRA |
| 1976 | if (empty_region_error) |
| 1977 | #endif |
| 1978 | vim_beep(); |
| 1979 | #ifdef FEAT_VISUALEXTRA |
| 1980 | else |
| 1981 | op_replace(oap, cap->nchar); |
| 1982 | #endif |
| 1983 | break; |
| 1984 | |
| 1985 | #ifdef FEAT_FOLDING |
| 1986 | case OP_FOLD: |
| 1987 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1988 | foldCreate(oap->start.lnum, oap->end.lnum); |
| 1989 | break; |
| 1990 | |
| 1991 | case OP_FOLDOPEN: |
| 1992 | case OP_FOLDOPENREC: |
| 1993 | case OP_FOLDCLOSE: |
| 1994 | case OP_FOLDCLOSEREC: |
| 1995 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 1996 | opFoldRange(oap->start.lnum, oap->end.lnum, |
| 1997 | oap->op_type == OP_FOLDOPEN |
| 1998 | || oap->op_type == OP_FOLDOPENREC, |
| 1999 | oap->op_type == OP_FOLDOPENREC |
| 2000 | || oap->op_type == OP_FOLDCLOSEREC, |
| 2001 | oap->is_VIsual); |
| 2002 | break; |
| 2003 | |
| 2004 | case OP_FOLDDEL: |
| 2005 | case OP_FOLDDELREC: |
| 2006 | VIsual_reselect = FALSE; /* don't reselect now */ |
| 2007 | deleteFold(oap->start.lnum, oap->end.lnum, |
| 2008 | oap->op_type == OP_FOLDDELREC, oap->is_VIsual); |
| 2009 | break; |
| 2010 | #endif |
| 2011 | default: |
| 2012 | clearopbeep(oap); |
| 2013 | } |
| 2014 | #ifdef FEAT_VIRTUALEDIT |
| 2015 | virtual_op = MAYBE; |
| 2016 | #endif |
| 2017 | if (!gui_yank) |
| 2018 | { |
| 2019 | /* |
| 2020 | * if 'sol' not set, go back to old column for some commands |
| 2021 | */ |
| 2022 | if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted |
| 2023 | && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT |
| 2024 | || oap->op_type == OP_DELETE)) |
| 2025 | coladvance(curwin->w_curswant = old_col); |
| 2026 | } |
| 2027 | else |
| 2028 | { |
| 2029 | curwin->w_cursor = old_cursor; |
| 2030 | } |
| 2031 | #ifdef FEAT_VISUAL |
| 2032 | oap->block_mode = FALSE; |
| 2033 | #endif |
| 2034 | clearop(oap); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | /* |
| 2039 | * Handle indent and format operators and visual mode ":". |
| 2040 | */ |
| 2041 | static void |
| 2042 | op_colon(oap) |
| 2043 | oparg_T *oap; |
| 2044 | { |
| 2045 | stuffcharReadbuff(':'); |
| 2046 | #ifdef FEAT_VISUAL |
| 2047 | if (oap->is_VIsual) |
| 2048 | stuffReadbuff((char_u *)"'<,'>"); |
| 2049 | else |
| 2050 | #endif |
| 2051 | { |
| 2052 | /* |
| 2053 | * Make the range look nice, so it can be repeated. |
| 2054 | */ |
| 2055 | if (oap->start.lnum == curwin->w_cursor.lnum) |
| 2056 | stuffcharReadbuff('.'); |
| 2057 | else |
| 2058 | stuffnumReadbuff((long)oap->start.lnum); |
| 2059 | if (oap->end.lnum != oap->start.lnum) |
| 2060 | { |
| 2061 | stuffcharReadbuff(','); |
| 2062 | if (oap->end.lnum == curwin->w_cursor.lnum) |
| 2063 | stuffcharReadbuff('.'); |
| 2064 | else if (oap->end.lnum == curbuf->b_ml.ml_line_count) |
| 2065 | stuffcharReadbuff('$'); |
| 2066 | else if (oap->start.lnum == curwin->w_cursor.lnum) |
| 2067 | { |
| 2068 | stuffReadbuff((char_u *)".+"); |
| 2069 | stuffnumReadbuff((long)oap->line_count - 1); |
| 2070 | } |
| 2071 | else |
| 2072 | stuffnumReadbuff((long)oap->end.lnum); |
| 2073 | } |
| 2074 | } |
| 2075 | if (oap->op_type != OP_COLON) |
| 2076 | stuffReadbuff((char_u *)"!"); |
| 2077 | if (oap->op_type == OP_INDENT) |
| 2078 | { |
| 2079 | #ifndef FEAT_CINDENT |
| 2080 | if (*get_equalprg() == NUL) |
| 2081 | stuffReadbuff((char_u *)"indent"); |
| 2082 | else |
| 2083 | #endif |
| 2084 | stuffReadbuff(get_equalprg()); |
| 2085 | stuffReadbuff((char_u *)"\n"); |
| 2086 | } |
| 2087 | else if (oap->op_type == OP_FORMAT) |
| 2088 | { |
| 2089 | if (*p_fp == NUL) |
| 2090 | stuffReadbuff((char_u *)"fmt"); |
| 2091 | else |
| 2092 | stuffReadbuff(p_fp); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2093 | stuffReadbuff((char_u *)"\n']"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | /* |
| 2097 | * do_cmdline() does the rest |
| 2098 | */ |
| 2099 | } |
| 2100 | |
| 2101 | #if defined(FEAT_MOUSE) || defined(PROTO) |
| 2102 | /* |
| 2103 | * Do the appropriate action for the current mouse click in the current mode. |
| 2104 | * Not used for Command-line mode. |
| 2105 | * |
| 2106 | * Normal Mode: |
| 2107 | * event modi- position visual change action |
| 2108 | * fier cursor window |
| 2109 | * left press - yes end yes |
| 2110 | * left press C yes end yes "^]" (2) |
| 2111 | * left press S yes end yes "*" (2) |
| 2112 | * left drag - yes start if moved no |
| 2113 | * left relse - yes start if moved no |
| 2114 | * middle press - yes if not active no put register |
| 2115 | * middle press - yes if active no yank and put |
| 2116 | * right press - yes start or extend yes |
| 2117 | * right press S yes no change yes "#" (2) |
| 2118 | * right drag - yes extend no |
| 2119 | * right relse - yes extend no |
| 2120 | * |
| 2121 | * Insert or Replace Mode: |
| 2122 | * event modi- position visual change action |
| 2123 | * fier cursor window |
| 2124 | * left press - yes (cannot be active) yes |
| 2125 | * left press C yes (cannot be active) yes "CTRL-O^]" (2) |
| 2126 | * left press S yes (cannot be active) yes "CTRL-O*" (2) |
| 2127 | * left drag - yes start or extend (1) no CTRL-O (1) |
| 2128 | * left relse - yes start or extend (1) no CTRL-O (1) |
| 2129 | * middle press - no (cannot be active) no put register |
| 2130 | * right press - yes start or extend yes CTRL-O |
| 2131 | * right press S yes (cannot be active) yes "CTRL-O#" (2) |
| 2132 | * |
| 2133 | * (1) only if mouse pointer moved since press |
| 2134 | * (2) only if click is in same buffer |
| 2135 | * |
| 2136 | * Return TRUE if start_arrow() should be called for edit mode. |
| 2137 | */ |
| 2138 | int |
| 2139 | do_mouse(oap, c, dir, count, fixindent) |
| 2140 | oparg_T *oap; /* operator argument, can be NULL */ |
| 2141 | int c; /* K_LEFTMOUSE, etc */ |
| 2142 | int dir; /* Direction to 'put' if necessary */ |
| 2143 | long count; |
| 2144 | int fixindent; /* PUT_FIXINDENT if fixing indent necessary */ |
| 2145 | { |
| 2146 | static int do_always = FALSE; /* ignore 'mouse' setting next time */ |
| 2147 | static int got_click = FALSE; /* got a click some time back */ |
| 2148 | |
| 2149 | int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ |
| 2150 | int is_click; /* If FALSE it's a drag or release event */ |
| 2151 | int is_drag; /* If TRUE it's a drag event */ |
| 2152 | int jump_flags = 0; /* flags for jump_to_mouse() */ |
| 2153 | pos_T start_visual; |
| 2154 | int moved; /* Has cursor moved? */ |
| 2155 | int in_status_line; /* mouse in status line */ |
| 2156 | #ifdef FEAT_VERTSPLIT |
| 2157 | int in_sep_line; /* mouse in vertical separator line */ |
| 2158 | #endif |
| 2159 | int c1, c2; |
| 2160 | #if defined(FEAT_FOLDING) |
| 2161 | pos_T save_cursor; |
| 2162 | #endif |
| 2163 | win_T *old_curwin = curwin; |
| 2164 | #ifdef FEAT_VISUAL |
| 2165 | static pos_T orig_cursor; |
| 2166 | colnr_T leftcol, rightcol; |
| 2167 | pos_T end_visual; |
| 2168 | int diff; |
| 2169 | int old_active = VIsual_active; |
| 2170 | int old_mode = VIsual_mode; |
| 2171 | #endif |
| 2172 | int regname; |
| 2173 | |
| 2174 | #if defined(FEAT_FOLDING) |
| 2175 | save_cursor = curwin->w_cursor; |
| 2176 | #endif |
| 2177 | |
| 2178 | /* |
| 2179 | * When GUI is active, always recognize mouse events, otherwise: |
| 2180 | * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. |
| 2181 | * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. |
| 2182 | * - For command line and insert mode 'mouse' is checked before calling |
| 2183 | * do_mouse(). |
| 2184 | */ |
| 2185 | if (do_always) |
| 2186 | do_always = FALSE; |
| 2187 | else |
| 2188 | #ifdef FEAT_GUI |
| 2189 | if (!gui.in_use) |
| 2190 | #endif |
| 2191 | { |
| 2192 | #ifdef FEAT_VISUAL |
| 2193 | if (VIsual_active) |
| 2194 | { |
| 2195 | if (!mouse_has(MOUSE_VISUAL)) |
| 2196 | return FALSE; |
| 2197 | } |
| 2198 | else |
| 2199 | #endif |
| 2200 | if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
| 2201 | return FALSE; |
| 2202 | } |
| 2203 | |
| 2204 | which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); |
| 2205 | |
| 2206 | #ifdef FEAT_MOUSESHAPE |
| 2207 | /* May have stopped dragging the status or separator line. The pointer is |
| 2208 | * most likely still on the status or separator line. */ |
| 2209 | if (!is_drag && drag_status_line) |
| 2210 | { |
| 2211 | drag_status_line = FALSE; |
| 2212 | update_mouseshape(SHAPE_IDX_STATUS); |
| 2213 | } |
| 2214 | # ifdef FEAT_VERTSPLIT |
| 2215 | if (!is_drag && drag_sep_line) |
| 2216 | { |
| 2217 | drag_sep_line = FALSE; |
| 2218 | update_mouseshape(SHAPE_IDX_VSEP); |
| 2219 | } |
| 2220 | # endif |
| 2221 | #endif |
| 2222 | |
| 2223 | /* |
| 2224 | * Ignore drag and release events if we didn't get a click. |
| 2225 | */ |
| 2226 | if (is_click) |
| 2227 | got_click = TRUE; |
| 2228 | else |
| 2229 | { |
| 2230 | if (!got_click) /* didn't get click, ignore */ |
| 2231 | return FALSE; |
| 2232 | if (!is_drag) /* release, reset got_click */ |
| 2233 | got_click = FALSE; |
| 2234 | } |
| 2235 | |
| 2236 | /* |
| 2237 | * ALT is currently ignored |
| 2238 | */ |
| 2239 | if ((mod_mask & MOD_MASK_ALT)) |
| 2240 | return FALSE; |
| 2241 | |
| 2242 | /* |
| 2243 | * CTRL right mouse button does CTRL-T |
| 2244 | */ |
| 2245 | if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) |
| 2246 | { |
| 2247 | if (State & INSERT) |
| 2248 | stuffcharReadbuff(Ctrl_O); |
| 2249 | if (count > 1) |
| 2250 | stuffnumReadbuff(count); |
| 2251 | stuffcharReadbuff(Ctrl_T); |
| 2252 | got_click = FALSE; /* ignore drag&release now */ |
| 2253 | return FALSE; |
| 2254 | } |
| 2255 | |
| 2256 | /* |
| 2257 | * CTRL only works with left mouse button |
| 2258 | */ |
| 2259 | if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) |
| 2260 | return FALSE; |
| 2261 | |
| 2262 | /* |
| 2263 | * When a modifier is down, ignore drag and release events, as well as |
| 2264 | * multiple clicks and the middle mouse button. |
| 2265 | * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". |
| 2266 | */ |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2267 | if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
| 2268 | | MOD_MASK_META)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2269 | && (!is_click |
| 2270 | || (mod_mask & MOD_MASK_MULTI_CLICK) |
| 2271 | || which_button == MOUSE_MIDDLE) |
| 2272 | && !((mod_mask & MOD_MASK_SHIFT) |
| 2273 | && mouse_model_popup() |
| 2274 | && which_button == MOUSE_LEFT) |
| 2275 | ) |
| 2276 | return FALSE; |
| 2277 | |
| 2278 | /* |
| 2279 | * If the button press was used as the movement command for an operator |
| 2280 | * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore |
| 2281 | * drag/release events. |
| 2282 | */ |
| 2283 | if (!is_click && which_button == MOUSE_MIDDLE) |
| 2284 | return FALSE; |
| 2285 | |
| 2286 | if (oap != NULL) |
| 2287 | regname = oap->regname; |
| 2288 | else |
| 2289 | regname = 0; |
| 2290 | |
| 2291 | /* |
| 2292 | * Middle mouse button does a 'put' of the selected text |
| 2293 | */ |
| 2294 | if (which_button == MOUSE_MIDDLE) |
| 2295 | { |
| 2296 | if (State == NORMAL) |
| 2297 | { |
| 2298 | /* |
| 2299 | * If an operator was pending, we don't know what the user wanted |
| 2300 | * to do. Go back to normal mode: Clear the operator and beep(). |
| 2301 | */ |
| 2302 | if (oap != NULL && oap->op_type != OP_NOP) |
| 2303 | { |
| 2304 | clearopbeep(oap); |
| 2305 | return FALSE; |
| 2306 | } |
| 2307 | |
| 2308 | #ifdef FEAT_VISUAL |
| 2309 | /* |
| 2310 | * If visual was active, yank the highlighted text and put it |
| 2311 | * before the mouse pointer position. |
| 2312 | */ |
| 2313 | if (VIsual_active) |
| 2314 | { |
| 2315 | stuffcharReadbuff('y'); |
| 2316 | stuffcharReadbuff(K_MIDDLEMOUSE); |
| 2317 | do_always = TRUE; /* ignore 'mouse' setting next time */ |
| 2318 | return FALSE; |
| 2319 | } |
| 2320 | #endif |
| 2321 | /* |
| 2322 | * The rest is below jump_to_mouse() |
| 2323 | */ |
| 2324 | } |
| 2325 | |
| 2326 | else if ((State & INSERT) == 0) |
| 2327 | return FALSE; |
| 2328 | |
| 2329 | /* |
| 2330 | * Middle click in insert mode doesn't move the mouse, just insert the |
| 2331 | * contents of a register. '.' register is special, can't insert that |
| 2332 | * with do_put(). |
| 2333 | * Also paste at the cursor if the current mode isn't in 'mouse' (only |
| 2334 | * happens for the GUI). |
| 2335 | */ |
| 2336 | if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) |
| 2337 | { |
| 2338 | if (regname == '.') |
| 2339 | insert_reg(regname, TRUE); |
| 2340 | else |
| 2341 | { |
| 2342 | #ifdef FEAT_CLIPBOARD |
| 2343 | if (clip_star.available && regname == 0) |
| 2344 | regname = '*'; |
| 2345 | #endif |
| 2346 | if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) |
| 2347 | insert_reg(regname, TRUE); |
| 2348 | else |
| 2349 | { |
| 2350 | do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); |
| 2351 | |
| 2352 | /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ |
| 2353 | AppendCharToRedobuff(Ctrl_R); |
| 2354 | AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); |
| 2355 | AppendCharToRedobuff(regname == 0 ? '"' : regname); |
| 2356 | } |
| 2357 | } |
| 2358 | return FALSE; |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | /* When dragging or button-up stay in the same window. */ |
| 2363 | if (!is_click) |
| 2364 | jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; |
| 2365 | |
| 2366 | start_visual.lnum = 0; |
| 2367 | |
| 2368 | /* |
| 2369 | * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: |
| 2370 | * right button up -> pop-up menu |
| 2371 | * shift-left button -> right button |
| 2372 | */ |
| 2373 | if (mouse_model_popup()) |
| 2374 | { |
| 2375 | if (which_button == MOUSE_RIGHT |
| 2376 | && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) |
| 2377 | { |
| 2378 | /* |
| 2379 | * NOTE: Ignore right button down and drag mouse events. |
| 2380 | * Windows only shows the popup menu on the button up event. |
| 2381 | */ |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 2382 | #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_KDE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2383 | if (!is_click) |
| 2384 | return FALSE; |
| 2385 | #endif |
| 2386 | #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) |
| 2387 | if (is_click || is_drag) |
| 2388 | return FALSE; |
| 2389 | #endif |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 2390 | #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2391 | || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
| 2392 | || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) |
| 2393 | if (gui.in_use) |
| 2394 | { |
| 2395 | jump_flags = 0; |
| 2396 | if (STRCMP(p_mousem, "popup_setpos") == 0) |
| 2397 | { |
| 2398 | /* First set the cursor position before showing the popup |
| 2399 | * menu. */ |
| 2400 | #ifdef FEAT_VISUAL |
| 2401 | if (VIsual_active) |
| 2402 | { |
| 2403 | pos_T m_pos; |
| 2404 | |
| 2405 | /* |
| 2406 | * set MOUSE_MAY_STOP_VIS if we are outside the |
| 2407 | * selection or the current window (might have false |
| 2408 | * negative here) |
| 2409 | */ |
| 2410 | if (mouse_row < W_WINROW(curwin) |
| 2411 | || mouse_row |
| 2412 | > (W_WINROW(curwin) + curwin->w_height)) |
| 2413 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2414 | else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) |
| 2415 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2416 | else |
| 2417 | { |
| 2418 | if ((lt(curwin->w_cursor, VIsual) |
| 2419 | && (lt(m_pos, curwin->w_cursor) |
| 2420 | || lt(VIsual, m_pos))) |
| 2421 | || (lt(VIsual, curwin->w_cursor) |
| 2422 | && (lt(m_pos, VIsual) |
| 2423 | || lt(curwin->w_cursor, m_pos)))) |
| 2424 | { |
| 2425 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2426 | } |
| 2427 | else if (VIsual_mode == Ctrl_V) |
| 2428 | { |
| 2429 | getvcols(curwin, &curwin->w_cursor, &VIsual, |
| 2430 | &leftcol, &rightcol); |
| 2431 | getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); |
| 2432 | if (m_pos.col < leftcol || m_pos.col > rightcol) |
| 2433 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | else |
| 2438 | jump_flags = MOUSE_MAY_STOP_VIS; |
| 2439 | #endif |
| 2440 | } |
| 2441 | if (jump_flags) |
| 2442 | { |
| 2443 | jump_flags = jump_to_mouse(jump_flags, NULL, which_button); |
| 2444 | update_curbuf( |
| 2445 | #ifdef FEAT_VISUAL |
| 2446 | VIsual_active ? INVERTED : |
| 2447 | #endif |
| 2448 | VALID); |
| 2449 | setcursor(); |
| 2450 | out_flush(); /* Update before showing popup menu */ |
| 2451 | } |
| 2452 | # ifdef FEAT_MENU |
| 2453 | gui_show_popupmenu(); |
| 2454 | # endif |
| 2455 | return (jump_flags & CURSOR_MOVED) != 0; |
| 2456 | } |
| 2457 | else |
| 2458 | return FALSE; |
| 2459 | #else |
| 2460 | return FALSE; |
| 2461 | #endif |
| 2462 | } |
| 2463 | if (which_button == MOUSE_LEFT && (mod_mask & MOD_MASK_SHIFT)) |
| 2464 | { |
| 2465 | which_button = MOUSE_RIGHT; |
| 2466 | mod_mask &= ~MOD_MASK_SHIFT; |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | #ifdef FEAT_VISUAL |
| 2471 | if ((State & (NORMAL | INSERT)) |
| 2472 | && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) |
| 2473 | { |
| 2474 | if (which_button == MOUSE_LEFT) |
| 2475 | { |
| 2476 | if (is_click) |
| 2477 | { |
| 2478 | /* stop Visual mode for a left click in a window, but not when |
| 2479 | * on a status line */ |
| 2480 | if (VIsual_active) |
| 2481 | jump_flags |= MOUSE_MAY_STOP_VIS; |
| 2482 | } |
| 2483 | else if (mouse_has(MOUSE_VISUAL)) |
| 2484 | jump_flags |= MOUSE_MAY_VIS; |
| 2485 | } |
| 2486 | else if (which_button == MOUSE_RIGHT) |
| 2487 | { |
| 2488 | if (is_click && VIsual_active) |
| 2489 | { |
| 2490 | /* |
| 2491 | * Remember the start and end of visual before moving the |
| 2492 | * cursor. |
| 2493 | */ |
| 2494 | if (lt(curwin->w_cursor, VIsual)) |
| 2495 | { |
| 2496 | start_visual = curwin->w_cursor; |
| 2497 | end_visual = VIsual; |
| 2498 | } |
| 2499 | else |
| 2500 | { |
| 2501 | start_visual = VIsual; |
| 2502 | end_visual = curwin->w_cursor; |
| 2503 | } |
| 2504 | } |
| 2505 | jump_flags |= MOUSE_FOCUS; |
| 2506 | if (mouse_has(MOUSE_VISUAL)) |
| 2507 | jump_flags |= MOUSE_MAY_VIS; |
| 2508 | } |
| 2509 | } |
| 2510 | #endif |
| 2511 | |
| 2512 | /* |
| 2513 | * If an operator is pending, ignore all drags and releases until the |
| 2514 | * next mouse click. |
| 2515 | */ |
| 2516 | if (!is_drag && oap != NULL && oap->op_type != OP_NOP) |
| 2517 | { |
| 2518 | got_click = FALSE; |
| 2519 | oap->motion_type = MCHAR; |
| 2520 | } |
| 2521 | |
| 2522 | /* When releasing the button let jump_to_mouse() know. */ |
| 2523 | if (!is_click && !is_drag) |
| 2524 | jump_flags |= MOUSE_RELEASED; |
| 2525 | |
| 2526 | /* |
| 2527 | * JUMP! |
| 2528 | */ |
| 2529 | jump_flags = jump_to_mouse(jump_flags, |
| 2530 | oap == NULL ? NULL : &(oap->inclusive), which_button); |
| 2531 | moved = (jump_flags & CURSOR_MOVED); |
| 2532 | in_status_line = (jump_flags & IN_STATUS_LINE); |
| 2533 | #ifdef FEAT_VERTSPLIT |
| 2534 | in_sep_line = (jump_flags & IN_SEP_LINE); |
| 2535 | #endif |
| 2536 | |
| 2537 | #ifdef FEAT_NETBEANS_INTG |
| 2538 | if (usingNetbeans && isNetbeansBuffer(curbuf) |
| 2539 | && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
| 2540 | { |
| 2541 | int key = KEY2TERMCAP1(c); |
| 2542 | |
| 2543 | if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE |
| 2544 | || key == (int)KE_RIGHTRELEASE) |
| 2545 | netbeans_button_release(which_button); |
| 2546 | } |
| 2547 | #endif |
| 2548 | |
| 2549 | /* When jumping to another window, clear a pending operator. That's a bit |
| 2550 | * friendlier than beeping and not jumping to that window. */ |
| 2551 | if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) |
| 2552 | clearop(oap); |
| 2553 | |
| 2554 | #ifdef FEAT_FOLDING |
| 2555 | if (mod_mask == 0 |
| 2556 | && !is_drag |
| 2557 | && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) |
| 2558 | && which_button == MOUSE_LEFT) |
| 2559 | { |
| 2560 | /* open or close a fold at this line */ |
| 2561 | if (jump_flags & MOUSE_FOLD_OPEN) |
| 2562 | openFold(curwin->w_cursor.lnum, 1L); |
| 2563 | else |
| 2564 | closeFold(curwin->w_cursor.lnum, 1L); |
| 2565 | /* don't move the cursor if still in the same window */ |
| 2566 | if (curwin == old_curwin) |
| 2567 | curwin->w_cursor = save_cursor; |
| 2568 | } |
| 2569 | #endif |
| 2570 | |
| 2571 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) |
| 2572 | if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) |
| 2573 | { |
| 2574 | clip_modeless(which_button, is_click, is_drag); |
| 2575 | return FALSE; |
| 2576 | } |
| 2577 | #endif |
| 2578 | |
| 2579 | #ifdef FEAT_VISUAL |
| 2580 | /* Set global flag that we are extending the Visual area with mouse |
| 2581 | * dragging; temporarily mimimize 'scrolloff'. */ |
| 2582 | if (VIsual_active && is_drag && p_so) |
| 2583 | { |
| 2584 | /* In the very first line, allow scrolling one line */ |
| 2585 | if (mouse_row == 0) |
| 2586 | mouse_dragging = 2; |
| 2587 | else |
| 2588 | mouse_dragging = 1; |
| 2589 | } |
| 2590 | |
| 2591 | /* When dragging the mouse above the window, scroll down. */ |
| 2592 | if (is_drag && mouse_row < 0 && !in_status_line) |
| 2593 | { |
| 2594 | scroll_redraw(FALSE, 1L); |
| 2595 | mouse_row = 0; |
| 2596 | } |
| 2597 | |
| 2598 | if (start_visual.lnum) /* right click in visual mode */ |
| 2599 | { |
| 2600 | /* |
| 2601 | * In Visual-block mode, divide the area in four, pick up the corner |
| 2602 | * that is in the quarter that the cursor is in. |
| 2603 | */ |
| 2604 | if (VIsual_mode == Ctrl_V) |
| 2605 | { |
| 2606 | getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); |
| 2607 | if (curwin->w_curswant > (leftcol + rightcol) / 2) |
| 2608 | end_visual.col = leftcol; |
| 2609 | else |
| 2610 | end_visual.col = rightcol; |
| 2611 | if (curwin->w_cursor.lnum < |
| 2612 | (start_visual.lnum + end_visual.lnum) / 2) |
| 2613 | end_visual.lnum = end_visual.lnum; |
| 2614 | else |
| 2615 | end_visual.lnum = start_visual.lnum; |
| 2616 | |
| 2617 | /* move VIsual to the right column */ |
| 2618 | start_visual = curwin->w_cursor; /* save the cursor pos */ |
| 2619 | curwin->w_cursor = end_visual; |
| 2620 | coladvance(end_visual.col); |
| 2621 | VIsual = curwin->w_cursor; |
| 2622 | curwin->w_cursor = start_visual; /* restore the cursor */ |
| 2623 | } |
| 2624 | else |
| 2625 | { |
| 2626 | /* |
| 2627 | * If the click is before the start of visual, change the start. |
| 2628 | * If the click is after the end of visual, change the end. If |
| 2629 | * the click is inside the visual, change the closest side. |
| 2630 | */ |
| 2631 | if (lt(curwin->w_cursor, start_visual)) |
| 2632 | VIsual = end_visual; |
| 2633 | else if (lt(end_visual, curwin->w_cursor)) |
| 2634 | VIsual = start_visual; |
| 2635 | else |
| 2636 | { |
| 2637 | /* In the same line, compare column number */ |
| 2638 | if (end_visual.lnum == start_visual.lnum) |
| 2639 | { |
| 2640 | if (curwin->w_cursor.col - start_visual.col > |
| 2641 | end_visual.col - curwin->w_cursor.col) |
| 2642 | VIsual = start_visual; |
| 2643 | else |
| 2644 | VIsual = end_visual; |
| 2645 | } |
| 2646 | |
| 2647 | /* In different lines, compare line number */ |
| 2648 | else |
| 2649 | { |
| 2650 | diff = (curwin->w_cursor.lnum - start_visual.lnum) - |
| 2651 | (end_visual.lnum - curwin->w_cursor.lnum); |
| 2652 | |
| 2653 | if (diff > 0) /* closest to end */ |
| 2654 | VIsual = start_visual; |
| 2655 | else if (diff < 0) /* closest to start */ |
| 2656 | VIsual = end_visual; |
| 2657 | else /* in the middle line */ |
| 2658 | { |
| 2659 | if (curwin->w_cursor.col < |
| 2660 | (start_visual.col + end_visual.col) / 2) |
| 2661 | VIsual = end_visual; |
| 2662 | else |
| 2663 | VIsual = start_visual; |
| 2664 | } |
| 2665 | } |
| 2666 | } |
| 2667 | } |
| 2668 | } |
| 2669 | /* |
| 2670 | * If Visual mode started in insert mode, execute "CTRL-O" |
| 2671 | */ |
| 2672 | else if ((State & INSERT) && VIsual_active) |
| 2673 | stuffcharReadbuff(Ctrl_O); |
| 2674 | #endif |
| 2675 | |
| 2676 | /* |
| 2677 | * Middle mouse click: Put text before cursor. |
| 2678 | */ |
| 2679 | if (which_button == MOUSE_MIDDLE) |
| 2680 | { |
| 2681 | #ifdef FEAT_CLIPBOARD |
| 2682 | if (clip_star.available && regname == 0) |
| 2683 | regname = '*'; |
| 2684 | #endif |
| 2685 | if (yank_register_mline(regname)) |
| 2686 | { |
| 2687 | if (mouse_past_bottom) |
| 2688 | dir = FORWARD; |
| 2689 | } |
| 2690 | else if (mouse_past_eol) |
| 2691 | dir = FORWARD; |
| 2692 | |
| 2693 | if (fixindent) |
| 2694 | { |
| 2695 | c1 = (dir == BACKWARD) ? '[' : ']'; |
| 2696 | c2 = 'p'; |
| 2697 | } |
| 2698 | else |
| 2699 | { |
| 2700 | c1 = (dir == FORWARD) ? 'p' : 'P'; |
| 2701 | c2 = NUL; |
| 2702 | } |
| 2703 | prep_redo(regname, count, NUL, c1, NUL, c2, NUL); |
| 2704 | |
| 2705 | /* |
| 2706 | * Remember where the paste started, so in edit() Insstart can be set |
| 2707 | * to this position |
| 2708 | */ |
| 2709 | if (restart_edit != 0) |
| 2710 | where_paste_started = curwin->w_cursor; |
| 2711 | do_put(regname, dir, count, fixindent | PUT_CURSEND); |
| 2712 | } |
| 2713 | |
| 2714 | #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
| 2715 | /* |
| 2716 | * Ctrl-Mouse click or double click in a quickfix window jumps to the |
| 2717 | * error under the mouse pointer. |
| 2718 | */ |
| 2719 | else if (((mod_mask & MOD_MASK_CTRL) |
| 2720 | || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 2721 | && bt_quickfix(curbuf)) |
| 2722 | { |
| 2723 | if (State & INSERT) |
| 2724 | stuffcharReadbuff(Ctrl_O); |
| 2725 | stuffReadbuff((char_u *)":.cc\n"); |
| 2726 | got_click = FALSE; /* ignore drag&release now */ |
| 2727 | } |
| 2728 | #endif |
| 2729 | |
| 2730 | /* |
| 2731 | * Ctrl-Mouse click (or double click in a help window) jumps to the tag |
| 2732 | * under the mouse pointer. |
| 2733 | */ |
| 2734 | else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help |
| 2735 | && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) |
| 2736 | { |
| 2737 | if (State & INSERT) |
| 2738 | stuffcharReadbuff(Ctrl_O); |
| 2739 | stuffcharReadbuff(Ctrl_RSB); |
| 2740 | got_click = FALSE; /* ignore drag&release now */ |
| 2741 | } |
| 2742 | |
| 2743 | /* |
| 2744 | * Shift-Mouse click searches for the next occurrence of the word under |
| 2745 | * the mouse pointer |
| 2746 | */ |
| 2747 | else if ((mod_mask & MOD_MASK_SHIFT)) |
| 2748 | { |
| 2749 | if (State & INSERT |
| 2750 | #ifdef FEAT_VISUAL |
| 2751 | || (VIsual_active && VIsual_select) |
| 2752 | #endif |
| 2753 | ) |
| 2754 | stuffcharReadbuff(Ctrl_O); |
| 2755 | if (which_button == MOUSE_LEFT) |
| 2756 | stuffcharReadbuff('*'); |
| 2757 | else /* MOUSE_RIGHT */ |
| 2758 | stuffcharReadbuff('#'); |
| 2759 | } |
| 2760 | |
| 2761 | /* Handle double clicks, unless on status line */ |
| 2762 | else if (in_status_line) |
| 2763 | { |
| 2764 | #ifdef FEAT_MOUSESHAPE |
| 2765 | if ((is_drag || is_click) && !drag_status_line) |
| 2766 | { |
| 2767 | drag_status_line = TRUE; |
| 2768 | update_mouseshape(-1); |
| 2769 | } |
| 2770 | #endif |
| 2771 | } |
| 2772 | #ifdef FEAT_VERTSPLIT |
| 2773 | else if (in_sep_line) |
| 2774 | { |
| 2775 | # ifdef FEAT_MOUSESHAPE |
| 2776 | if ((is_drag || is_click) && !drag_sep_line) |
| 2777 | { |
| 2778 | drag_sep_line = TRUE; |
| 2779 | update_mouseshape(-1); |
| 2780 | } |
| 2781 | # endif |
| 2782 | } |
| 2783 | #endif |
| 2784 | #ifdef FEAT_VISUAL |
| 2785 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
| 2786 | && mouse_has(MOUSE_VISUAL)) |
| 2787 | { |
| 2788 | if (is_click || !VIsual_active) |
| 2789 | { |
| 2790 | if (VIsual_active) |
| 2791 | orig_cursor = VIsual; |
| 2792 | else |
| 2793 | { |
| 2794 | check_visual_highlight(); |
| 2795 | VIsual = curwin->w_cursor; |
| 2796 | orig_cursor = VIsual; |
| 2797 | VIsual_active = TRUE; |
| 2798 | VIsual_reselect = TRUE; |
| 2799 | /* start Select mode if 'selectmode' contains "mouse" */ |
| 2800 | may_start_select('o'); |
| 2801 | setmouse(); |
| 2802 | } |
| 2803 | if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 2804 | VIsual_mode = 'v'; |
| 2805 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
| 2806 | VIsual_mode = 'V'; |
| 2807 | else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) |
| 2808 | VIsual_mode = Ctrl_V; |
| 2809 | #ifdef FEAT_CLIPBOARD |
| 2810 | /* Make sure the clipboard gets updated. Needed because start and |
| 2811 | * end may still be the same, and the selection needs to be owned */ |
| 2812 | clip_star.vmode = NUL; |
| 2813 | #endif |
| 2814 | } |
| 2815 | /* |
| 2816 | * A double click selects a word or a block. |
| 2817 | */ |
| 2818 | if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
| 2819 | { |
| 2820 | pos_T *pos = NULL; |
| 2821 | |
| 2822 | if (is_click) |
| 2823 | { |
| 2824 | /* If the character under the cursor (skipping white space) is |
| 2825 | * not a word character, try finding a match and select a (), |
| 2826 | * {}, [], #if/#endif, etc. block. */ |
| 2827 | end_visual = curwin->w_cursor; |
| 2828 | while (vim_iswhite(gchar_pos(&end_visual))) |
| 2829 | inc(&end_visual); |
| 2830 | if (oap != NULL) |
| 2831 | oap->motion_type = MCHAR; |
| 2832 | if (oap != NULL |
| 2833 | && VIsual_mode == 'v' |
| 2834 | && !vim_iswordc(gchar_pos(&end_visual)) |
| 2835 | && equalpos(curwin->w_cursor, VIsual) |
| 2836 | && (pos = findmatch(oap, NUL)) != NULL) |
| 2837 | { |
| 2838 | curwin->w_cursor = *pos; |
| 2839 | if (oap->motion_type == MLINE) |
| 2840 | VIsual_mode = 'V'; |
| 2841 | else if (*p_sel == 'e') |
| 2842 | { |
| 2843 | if (lt(curwin->w_cursor, VIsual)) |
| 2844 | ++VIsual.col; |
| 2845 | else |
| 2846 | ++curwin->w_cursor.col; |
| 2847 | } |
| 2848 | } |
| 2849 | } |
| 2850 | |
| 2851 | if (pos == NULL && (is_click || is_drag)) |
| 2852 | { |
| 2853 | /* When not found a match or when dragging: extend to include |
| 2854 | * a word. */ |
| 2855 | if (lt(curwin->w_cursor, orig_cursor)) |
| 2856 | { |
| 2857 | find_start_of_word(&curwin->w_cursor); |
| 2858 | find_end_of_word(&VIsual); |
| 2859 | } |
| 2860 | else |
| 2861 | { |
| 2862 | find_start_of_word(&VIsual); |
| 2863 | if (*p_sel == 'e' && *ml_get_cursor() != NUL) |
| 2864 | #ifdef FEAT_MBYTE |
| 2865 | curwin->w_cursor.col += |
| 2866 | (*mb_ptr2len_check)(ml_get_cursor()); |
| 2867 | #else |
| 2868 | ++curwin->w_cursor.col; |
| 2869 | #endif |
| 2870 | find_end_of_word(&curwin->w_cursor); |
| 2871 | } |
| 2872 | } |
| 2873 | curwin->w_set_curswant = TRUE; |
| 2874 | } |
| 2875 | if (is_click) |
| 2876 | redraw_curbuf_later(INVERTED); /* update the inversion */ |
| 2877 | } |
| 2878 | else if (VIsual_active && !old_active) |
| 2879 | VIsual_mode = 'v'; |
| 2880 | |
| 2881 | /* If Visual mode changed show it later. */ |
| 2882 | if (p_smd && (VIsual_active != old_active || VIsual_mode != old_mode)) |
| 2883 | redraw_cmdline = TRUE; |
| 2884 | #endif |
| 2885 | |
| 2886 | return moved; |
| 2887 | } |
| 2888 | |
| 2889 | #ifdef FEAT_VISUAL |
| 2890 | /* |
| 2891 | * Move "pos" back to the start of the word it's in. |
| 2892 | */ |
| 2893 | static void |
| 2894 | find_start_of_word(pos) |
| 2895 | pos_T *pos; |
| 2896 | { |
| 2897 | char_u *line; |
| 2898 | int cclass; |
| 2899 | int col; |
| 2900 | |
| 2901 | line = ml_get(pos->lnum); |
| 2902 | cclass = get_mouse_class(line + pos->col); |
| 2903 | |
| 2904 | while (pos->col > 0) |
| 2905 | { |
| 2906 | col = pos->col - 1; |
| 2907 | #ifdef FEAT_MBYTE |
| 2908 | col -= (*mb_head_off)(line, line + col); |
| 2909 | #endif |
| 2910 | if (get_mouse_class(line + col) != cclass) |
| 2911 | break; |
| 2912 | pos->col = col; |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | /* |
| 2917 | * Move "pos" forward to the end of the word it's in. |
| 2918 | * When 'selection' is "exclusive", the position is just after the word. |
| 2919 | */ |
| 2920 | static void |
| 2921 | find_end_of_word(pos) |
| 2922 | pos_T *pos; |
| 2923 | { |
| 2924 | char_u *line; |
| 2925 | int cclass; |
| 2926 | int col; |
| 2927 | |
| 2928 | line = ml_get(pos->lnum); |
| 2929 | if (*p_sel == 'e' && pos->col > 0) |
| 2930 | { |
| 2931 | --pos->col; |
| 2932 | #ifdef FEAT_MBYTE |
| 2933 | pos->col -= (*mb_head_off)(line, line + pos->col); |
| 2934 | #endif |
| 2935 | } |
| 2936 | cclass = get_mouse_class(line + pos->col); |
| 2937 | while (line[pos->col] != NUL) |
| 2938 | { |
| 2939 | #ifdef FEAT_MBYTE |
| 2940 | col = pos->col + (*mb_ptr2len_check)(line + pos->col); |
| 2941 | #else |
| 2942 | col = pos->col + 1; |
| 2943 | #endif |
| 2944 | if (get_mouse_class(line + col) != cclass) |
| 2945 | { |
| 2946 | if (*p_sel == 'e') |
| 2947 | pos->col = col; |
| 2948 | break; |
| 2949 | } |
| 2950 | pos->col = col; |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | /* |
| 2955 | * Get class of a character for selection: same class means same word. |
| 2956 | * 0: blank |
| 2957 | * 1: punctuation groups |
| 2958 | * 2: normal word character |
| 2959 | * >2: multi-byte word character. |
| 2960 | */ |
| 2961 | static int |
| 2962 | get_mouse_class(p) |
| 2963 | char_u *p; |
| 2964 | { |
| 2965 | int c; |
| 2966 | |
| 2967 | #ifdef FEAT_MBYTE |
| 2968 | if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) |
| 2969 | return mb_get_class(p); |
| 2970 | #endif |
| 2971 | |
| 2972 | c = *p; |
| 2973 | if (c == ' ' || c == '\t') |
| 2974 | return 0; |
| 2975 | |
| 2976 | if (vim_iswordc(c)) |
| 2977 | return 2; |
| 2978 | |
| 2979 | /* |
| 2980 | * There are a few special cases where we want certain combinations of |
| 2981 | * characters to be considered as a single word. These are things like |
| 2982 | * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each |
| 2983 | * character is in it's own class. |
| 2984 | */ |
| 2985 | if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) |
| 2986 | return 1; |
| 2987 | return c; |
| 2988 | } |
| 2989 | #endif /* FEAT_VISUAL */ |
| 2990 | #endif /* FEAT_MOUSE */ |
| 2991 | |
| 2992 | #if defined(FEAT_VISUAL) || defined(PROTO) |
| 2993 | /* |
| 2994 | * Check if highlighting for visual mode is possible, give a warning message |
| 2995 | * if not. |
| 2996 | */ |
| 2997 | void |
| 2998 | check_visual_highlight() |
| 2999 | { |
| 3000 | static int did_check = FALSE; |
| 3001 | |
| 3002 | if (full_screen) |
| 3003 | { |
| 3004 | if (!did_check && hl_attr(HLF_V) == 0) |
| 3005 | MSG(_("Warning: terminal cannot highlight")); |
| 3006 | did_check = TRUE; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | /* |
| 3011 | * End visual mode. |
| 3012 | * This function should ALWAYS be called to end Visual mode, except from |
| 3013 | * do_pending_operator(). |
| 3014 | */ |
| 3015 | void |
| 3016 | end_visual_mode() |
| 3017 | { |
| 3018 | #ifdef FEAT_CLIPBOARD |
| 3019 | /* |
| 3020 | * If we are using the clipboard, then remember what was selected in case |
| 3021 | * we need to paste it somewhere while we still own the selection. |
| 3022 | * Only do this when the clipboard is already owned. Don't want to grab |
| 3023 | * the selection when hitting ESC. |
| 3024 | */ |
| 3025 | if (clip_star.available && clip_star.owned) |
| 3026 | clip_auto_select(); |
| 3027 | #endif |
| 3028 | |
| 3029 | VIsual_active = FALSE; |
| 3030 | #ifdef FEAT_MOUSE |
| 3031 | setmouse(); |
| 3032 | mouse_dragging = 0; |
| 3033 | #endif |
| 3034 | |
| 3035 | /* Save the current VIsual area for '< and '> marks, and "gv" */ |
| 3036 | curbuf->b_visual_mode = VIsual_mode; |
| 3037 | #ifdef FEAT_EVAL |
| 3038 | curbuf->b_visual_mode_eval = VIsual_mode; |
| 3039 | #endif |
| 3040 | curbuf->b_visual_start = VIsual; |
| 3041 | curbuf->b_visual_end = curwin->w_cursor; |
| 3042 | curbuf->b_visual_curswant = curwin->w_curswant; |
| 3043 | #ifdef FEAT_VIRTUALEDIT |
| 3044 | if (!virtual_active()) |
| 3045 | curwin->w_cursor.coladd = 0; |
| 3046 | #endif |
| 3047 | |
| 3048 | if (p_smd) |
| 3049 | clear_cmdline = TRUE; /* unshow visual mode later */ |
| 3050 | #ifdef FEAT_CMDL_INFO |
| 3051 | else |
| 3052 | clear_showcmd(); |
| 3053 | #endif |
| 3054 | |
| 3055 | /* Don't leave the cursor past the end of the line */ |
| 3056 | if (curwin->w_cursor.col > 0 && *ml_get_cursor() == NUL) |
| 3057 | --curwin->w_cursor.col; |
| 3058 | } |
| 3059 | |
| 3060 | /* |
| 3061 | * Reset VIsual_active and VIsual_reselect. |
| 3062 | */ |
| 3063 | void |
| 3064 | reset_VIsual_and_resel() |
| 3065 | { |
| 3066 | if (VIsual_active) |
| 3067 | { |
| 3068 | end_visual_mode(); |
| 3069 | redraw_curbuf_later(INVERTED); /* delete the inversion later */ |
| 3070 | } |
| 3071 | VIsual_reselect = FALSE; |
| 3072 | } |
| 3073 | |
| 3074 | /* |
| 3075 | * Reset VIsual_active and VIsual_reselect if it's set. |
| 3076 | */ |
| 3077 | void |
| 3078 | reset_VIsual() |
| 3079 | { |
| 3080 | if (VIsual_active) |
| 3081 | { |
| 3082 | end_visual_mode(); |
| 3083 | redraw_curbuf_later(INVERTED); /* delete the inversion later */ |
| 3084 | VIsual_reselect = FALSE; |
| 3085 | } |
| 3086 | } |
| 3087 | #endif /* FEAT_VISUAL */ |
| 3088 | |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3089 | #if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3090 | static int find_is_eval_item __ARGS((char_u *ptr, int *colp, int *nbp, int dir)); |
| 3091 | |
| 3092 | /* |
| 3093 | * Check for a balloon-eval special item to include when searching for an |
| 3094 | * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! |
| 3095 | * Returns TRUE if the character at "*ptr" should be included. |
| 3096 | * "dir" is FORWARD or BACKWARD, the direction of searching. |
| 3097 | * "*colp" is in/decremented if "ptr[-dir]" should also be included. |
| 3098 | * "bnp" points to a counter for square brackets. |
| 3099 | */ |
| 3100 | static int |
| 3101 | find_is_eval_item(ptr, colp, bnp, dir) |
| 3102 | char_u *ptr; |
| 3103 | int *colp; |
| 3104 | int *bnp; |
| 3105 | int dir; |
| 3106 | { |
| 3107 | /* Accept everything inside []. */ |
| 3108 | if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) |
| 3109 | ++*bnp; |
| 3110 | if (*bnp > 0) |
| 3111 | { |
| 3112 | if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) |
| 3113 | --*bnp; |
| 3114 | return TRUE; |
| 3115 | } |
| 3116 | |
| 3117 | /* skip over "s.var" */ |
| 3118 | if (*ptr == '.') |
| 3119 | return TRUE; |
| 3120 | |
| 3121 | /* two-character item: s->var */ |
| 3122 | if (ptr[dir == BACKWARD ? 0 : 1] == '>' |
| 3123 | && ptr[dir == BACKWARD ? -1 : 0] == '-') |
| 3124 | { |
| 3125 | *colp += dir; |
| 3126 | return TRUE; |
| 3127 | } |
| 3128 | return FALSE; |
| 3129 | } |
| 3130 | #endif |
| 3131 | |
| 3132 | /* |
| 3133 | * Find the identifier under or to the right of the cursor. |
| 3134 | * "find_type" can have one of three values: |
| 3135 | * FIND_IDENT: find an identifier (keyword) |
| 3136 | * FIND_STRING: find any non-white string |
| 3137 | * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3138 | * FIND_EVAL: find text useful for C program debugging |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3139 | * |
| 3140 | * There are three steps: |
| 3141 | * 1. Search forward for the start of an identifier/string. Doesn't move if |
| 3142 | * already on one. |
| 3143 | * 2. Search backward for the start of this identifier/string. |
| 3144 | * This doesn't match the real Vi but I like it a little better and it |
| 3145 | * shouldn't bother anyone. |
| 3146 | * 3. Search forward to the end of this identifier/string. |
| 3147 | * When FIND_IDENT isn't defined, we backup until a blank. |
| 3148 | * |
| 3149 | * Returns the length of the string, or zero if no string is found. |
| 3150 | * If a string is found, a pointer to the string is put in "*string". This |
| 3151 | * string is not always NUL terminated. |
| 3152 | */ |
| 3153 | int |
| 3154 | find_ident_under_cursor(string, find_type) |
| 3155 | char_u **string; |
| 3156 | int find_type; |
| 3157 | { |
| 3158 | return find_ident_at_pos(curwin, curwin->w_cursor.lnum, |
| 3159 | curwin->w_cursor.col, string, find_type); |
| 3160 | } |
| 3161 | |
| 3162 | /* |
| 3163 | * Like find_ident_under_cursor(), but for any window and any position. |
| 3164 | * However: Uses 'iskeyword' from the current window!. |
| 3165 | */ |
| 3166 | int |
| 3167 | find_ident_at_pos(wp, lnum, startcol, string, find_type) |
| 3168 | win_T *wp; |
| 3169 | linenr_T lnum; |
| 3170 | colnr_T startcol; |
| 3171 | char_u **string; |
| 3172 | int find_type; |
| 3173 | { |
| 3174 | char_u *ptr; |
| 3175 | int col = 0; /* init to shut up GCC */ |
| 3176 | int i; |
| 3177 | #ifdef FEAT_MBYTE |
| 3178 | int this_class = 0; |
| 3179 | int prev_class; |
| 3180 | int prevcol; |
| 3181 | #endif |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3182 | #if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3183 | int bn = 0; /* bracket nesting */ |
| 3184 | #endif |
| 3185 | |
| 3186 | /* |
| 3187 | * if i == 0: try to find an identifier |
| 3188 | * if i == 1: try to find any non-white string |
| 3189 | */ |
| 3190 | ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3191 | for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) |
| 3192 | { |
| 3193 | /* |
| 3194 | * 1. skip to start of identifier/string |
| 3195 | */ |
| 3196 | col = startcol; |
| 3197 | #ifdef FEAT_MBYTE |
| 3198 | if (has_mbyte) |
| 3199 | { |
| 3200 | while (ptr[col] != NUL) |
| 3201 | { |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3202 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3203 | /* Stop at a ']' to evaluate "a[x]". */ |
| 3204 | if ((find_type & FIND_EVAL) && ptr[col] == ']') |
| 3205 | break; |
| 3206 | # endif |
| 3207 | this_class = mb_get_class(ptr + col); |
| 3208 | if (this_class != 0 && (i == 1 || this_class != 1)) |
| 3209 | break; |
| 3210 | col += (*mb_ptr2len_check)(ptr + col); |
| 3211 | } |
| 3212 | } |
| 3213 | else |
| 3214 | #endif |
| 3215 | while (ptr[col] != NUL |
| 3216 | && (i == 0 ? !vim_iswordc(ptr[col]) : vim_iswhite(ptr[col])) |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3217 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3218 | && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
| 3219 | # endif |
| 3220 | ) |
| 3221 | ++col; |
| 3222 | |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3223 | #if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3224 | /* When starting on a ']' count it, so that we include the '['. */ |
| 3225 | bn = ptr[col] == ']'; |
| 3226 | #endif |
| 3227 | |
| 3228 | /* |
| 3229 | * 2. Back up to start of identifier/string. |
| 3230 | */ |
| 3231 | #ifdef FEAT_MBYTE |
| 3232 | if (has_mbyte) |
| 3233 | { |
| 3234 | /* Remember class of character under cursor. */ |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3235 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3236 | if ((find_type & FIND_EVAL) && ptr[col] == ']') |
| 3237 | this_class = mb_get_class((char_u *)"a"); |
| 3238 | else |
| 3239 | # endif |
| 3240 | this_class = mb_get_class(ptr + col); |
| 3241 | while (col > 0) |
| 3242 | { |
| 3243 | prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); |
| 3244 | prev_class = mb_get_class(ptr + prevcol); |
| 3245 | if (this_class != prev_class |
| 3246 | && (i == 0 |
| 3247 | || prev_class == 0 |
| 3248 | || (find_type & FIND_IDENT)) |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3249 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3250 | && (!(find_type & FIND_EVAL) |
| 3251 | || prevcol == 0 |
| 3252 | || !find_is_eval_item(ptr + prevcol, &prevcol, |
| 3253 | &bn, BACKWARD)) |
| 3254 | # endif |
| 3255 | ) |
| 3256 | break; |
| 3257 | col = prevcol; |
| 3258 | } |
| 3259 | |
| 3260 | /* If we don't want just any old string, or we've found an |
| 3261 | * identifier, stop searching. */ |
| 3262 | if (this_class > 2) |
| 3263 | this_class = 2; |
| 3264 | if (!(find_type & FIND_STRING) || this_class == 2) |
| 3265 | break; |
| 3266 | } |
| 3267 | else |
| 3268 | #endif |
| 3269 | { |
| 3270 | while (col > 0 |
| 3271 | && ((i == 0 |
| 3272 | ? vim_iswordc(ptr[col - 1]) |
| 3273 | : (!vim_iswhite(ptr[col - 1]) |
| 3274 | && (!(find_type & FIND_IDENT) |
| 3275 | || !vim_iswordc(ptr[col - 1])))) |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3276 | #if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3277 | || ((find_type & FIND_EVAL) |
| 3278 | && col > 1 |
| 3279 | && find_is_eval_item(ptr + col - 1, &col, |
| 3280 | &bn, BACKWARD)) |
| 3281 | #endif |
| 3282 | )) |
| 3283 | --col; |
| 3284 | |
| 3285 | /* If we don't want just any old string, or we've found an |
| 3286 | * identifier, stop searching. */ |
| 3287 | if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
| 3288 | break; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | if (ptr[col] == NUL || (i == 0 && ( |
| 3293 | #ifdef FEAT_MBYTE |
| 3294 | has_mbyte ? this_class != 2 : |
| 3295 | #endif |
| 3296 | !vim_iswordc(ptr[col])))) |
| 3297 | { |
| 3298 | /* |
| 3299 | * didn't find an identifier or string |
| 3300 | */ |
| 3301 | if (find_type & FIND_STRING) |
| 3302 | EMSG(_("E348: No string under cursor")); |
| 3303 | else |
| 3304 | EMSG(_("E349: No identifier under cursor")); |
| 3305 | return 0; |
| 3306 | } |
| 3307 | ptr += col; |
| 3308 | *string = ptr; |
| 3309 | |
| 3310 | /* |
| 3311 | * 3. Find the end if the identifier/string. |
| 3312 | */ |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3313 | #if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3314 | bn = 0; |
| 3315 | startcol -= col; |
| 3316 | #endif |
| 3317 | col = 0; |
| 3318 | #ifdef FEAT_MBYTE |
| 3319 | if (has_mbyte) |
| 3320 | { |
| 3321 | /* Search for point of changing multibyte character class. */ |
| 3322 | this_class = mb_get_class(ptr); |
| 3323 | while (ptr[col] != NUL |
| 3324 | && ((i == 0 ? mb_get_class(ptr + col) == this_class |
| 3325 | : mb_get_class(ptr + col) != 0) |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3326 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3327 | || ((find_type & FIND_EVAL) |
| 3328 | && col <= (int)startcol |
| 3329 | && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) |
| 3330 | # endif |
| 3331 | )) |
| 3332 | col += (*mb_ptr2len_check)(ptr + col); |
| 3333 | } |
| 3334 | else |
| 3335 | #endif |
| 3336 | while ((i == 0 ? vim_iswordc(ptr[col]) |
| 3337 | : (ptr[col] != NUL && !vim_iswhite(ptr[col]))) |
Bram Moolenaar | 52b4b55 | 2005-03-07 23:00:57 +0000 | [diff] [blame] | 3338 | # if defined(FEAT_BEVAL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3339 | || ((find_type & FIND_EVAL) |
| 3340 | && col <= (int)startcol |
| 3341 | && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) |
| 3342 | # endif |
| 3343 | ) |
| 3344 | { |
| 3345 | ++col; |
| 3346 | } |
| 3347 | |
| 3348 | return col; |
| 3349 | } |
| 3350 | |
| 3351 | /* |
| 3352 | * Prepare for redo of a normal command. |
| 3353 | */ |
| 3354 | static void |
| 3355 | prep_redo_cmd(cap) |
| 3356 | cmdarg_T *cap; |
| 3357 | { |
| 3358 | prep_redo(cap->oap->regname, cap->count0, |
| 3359 | NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
| 3360 | } |
| 3361 | |
| 3362 | /* |
| 3363 | * Prepare for redo of any command. |
| 3364 | * Note that only the last argument can be a multi-byte char. |
| 3365 | */ |
| 3366 | static void |
| 3367 | prep_redo(regname, num, cmd1, cmd2, cmd3, cmd4, cmd5) |
| 3368 | int regname; |
| 3369 | long num; |
| 3370 | int cmd1; |
| 3371 | int cmd2; |
| 3372 | int cmd3; |
| 3373 | int cmd4; |
| 3374 | int cmd5; |
| 3375 | { |
| 3376 | ResetRedobuff(); |
| 3377 | if (regname != 0) /* yank from specified buffer */ |
| 3378 | { |
| 3379 | AppendCharToRedobuff('"'); |
| 3380 | AppendCharToRedobuff(regname); |
| 3381 | } |
| 3382 | if (num) |
| 3383 | AppendNumberToRedobuff(num); |
| 3384 | |
| 3385 | if (cmd1 != NUL) |
| 3386 | AppendCharToRedobuff(cmd1); |
| 3387 | if (cmd2 != NUL) |
| 3388 | AppendCharToRedobuff(cmd2); |
| 3389 | if (cmd3 != NUL) |
| 3390 | AppendCharToRedobuff(cmd3); |
| 3391 | if (cmd4 != NUL) |
| 3392 | AppendCharToRedobuff(cmd4); |
| 3393 | if (cmd5 != NUL) |
| 3394 | AppendCharToRedobuff(cmd5); |
| 3395 | } |
| 3396 | |
| 3397 | /* |
| 3398 | * check for operator active and clear it |
| 3399 | * |
| 3400 | * return TRUE if operator was active |
| 3401 | */ |
| 3402 | static int |
| 3403 | checkclearop(oap) |
| 3404 | oparg_T *oap; |
| 3405 | { |
| 3406 | if (oap->op_type == OP_NOP) |
| 3407 | return FALSE; |
| 3408 | clearopbeep(oap); |
| 3409 | return TRUE; |
| 3410 | } |
| 3411 | |
| 3412 | /* |
| 3413 | * check for operator or Visual active and clear it |
| 3414 | * |
| 3415 | * return TRUE if operator was active |
| 3416 | */ |
| 3417 | static int |
| 3418 | checkclearopq(oap) |
| 3419 | oparg_T *oap; |
| 3420 | { |
| 3421 | if (oap->op_type == OP_NOP |
| 3422 | #ifdef FEAT_VISUAL |
| 3423 | && !VIsual_active |
| 3424 | #endif |
| 3425 | ) |
| 3426 | return FALSE; |
| 3427 | clearopbeep(oap); |
| 3428 | return TRUE; |
| 3429 | } |
| 3430 | |
| 3431 | static void |
| 3432 | clearop(oap) |
| 3433 | oparg_T *oap; |
| 3434 | { |
| 3435 | oap->op_type = OP_NOP; |
| 3436 | oap->regname = 0; |
| 3437 | oap->motion_force = NUL; |
| 3438 | oap->use_reg_one = FALSE; |
| 3439 | } |
| 3440 | |
| 3441 | static void |
| 3442 | clearopbeep(oap) |
| 3443 | oparg_T *oap; |
| 3444 | { |
| 3445 | clearop(oap); |
| 3446 | beep_flush(); |
| 3447 | } |
| 3448 | |
| 3449 | #ifdef FEAT_VISUAL |
| 3450 | /* |
| 3451 | * Remove the shift modifier from a special key. |
| 3452 | */ |
| 3453 | static void |
| 3454 | unshift_special(cap) |
| 3455 | cmdarg_T *cap; |
| 3456 | { |
| 3457 | switch (cap->cmdchar) |
| 3458 | { |
| 3459 | case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; |
| 3460 | case K_S_LEFT: cap->cmdchar = K_LEFT; break; |
| 3461 | case K_S_UP: cap->cmdchar = K_UP; break; |
| 3462 | case K_S_DOWN: cap->cmdchar = K_DOWN; break; |
| 3463 | case K_S_HOME: cap->cmdchar = K_HOME; break; |
| 3464 | case K_S_END: cap->cmdchar = K_END; break; |
| 3465 | } |
| 3466 | cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); |
| 3467 | } |
| 3468 | #endif |
| 3469 | |
| 3470 | #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
| 3471 | /* |
| 3472 | * Routines for displaying a partly typed command |
| 3473 | */ |
| 3474 | |
| 3475 | #ifdef FEAT_VISUAL /* need room for size of Visual area */ |
| 3476 | # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
| 3477 | #else |
| 3478 | # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 |
| 3479 | #endif |
| 3480 | static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
| 3481 | static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ |
| 3482 | static int showcmd_is_clear = TRUE; |
| 3483 | static int showcmd_visual = FALSE; |
| 3484 | |
| 3485 | static void display_showcmd __ARGS((void)); |
| 3486 | |
| 3487 | void |
| 3488 | clear_showcmd() |
| 3489 | { |
| 3490 | if (!p_sc) |
| 3491 | return; |
| 3492 | |
| 3493 | #ifdef FEAT_VISUAL |
| 3494 | if (VIsual_active && !char_avail()) |
| 3495 | { |
| 3496 | int i = lt(VIsual, curwin->w_cursor); |
| 3497 | long lines; |
| 3498 | colnr_T leftcol, rightcol; |
| 3499 | linenr_T top, bot; |
| 3500 | |
| 3501 | /* Show the size of the Visual area. */ |
| 3502 | if (i) |
| 3503 | { |
| 3504 | top = VIsual.lnum; |
| 3505 | bot = curwin->w_cursor.lnum; |
| 3506 | } |
| 3507 | else |
| 3508 | { |
| 3509 | top = curwin->w_cursor.lnum; |
| 3510 | bot = VIsual.lnum; |
| 3511 | } |
| 3512 | # ifdef FEAT_FOLDING |
| 3513 | /* Include closed folds as a whole. */ |
| 3514 | hasFolding(top, &top, NULL); |
| 3515 | hasFolding(bot, NULL, &bot); |
| 3516 | # endif |
| 3517 | lines = bot - top + 1; |
| 3518 | |
| 3519 | if (VIsual_mode == Ctrl_V) |
| 3520 | { |
| 3521 | getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); |
| 3522 | sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
| 3523 | (long)(rightcol - leftcol + 1)); |
| 3524 | } |
| 3525 | else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) |
| 3526 | sprintf((char *)showcmd_buf, "%ld", lines); |
| 3527 | else |
| 3528 | sprintf((char *)showcmd_buf, "%ld", (long)(i |
| 3529 | ? curwin->w_cursor.col - VIsual.col |
| 3530 | : VIsual.col - curwin->w_cursor.col) + (*p_sel != 'e')); |
| 3531 | showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
| 3532 | showcmd_visual = TRUE; |
| 3533 | } |
| 3534 | else |
| 3535 | #endif |
| 3536 | { |
| 3537 | showcmd_buf[0] = NUL; |
| 3538 | showcmd_visual = FALSE; |
| 3539 | |
| 3540 | /* Don't actually display something if there is nothing to clear. */ |
| 3541 | if (showcmd_is_clear) |
| 3542 | return; |
| 3543 | } |
| 3544 | |
| 3545 | display_showcmd(); |
| 3546 | } |
| 3547 | |
| 3548 | /* |
| 3549 | * Add 'c' to string of shown command chars. |
| 3550 | * Return TRUE if output has been written (and setcursor() has been called). |
| 3551 | */ |
| 3552 | int |
| 3553 | add_to_showcmd(c) |
| 3554 | int c; |
| 3555 | { |
| 3556 | char_u *p; |
| 3557 | int old_len; |
| 3558 | int extra_len; |
| 3559 | int overflow; |
| 3560 | #if defined(FEAT_MOUSE) |
| 3561 | int i; |
| 3562 | static int ignore[] = |
| 3563 | { |
| 3564 | #ifdef FEAT_GUI |
| 3565 | K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
| 3566 | K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, |
| 3567 | #endif |
| 3568 | K_IGNORE, |
| 3569 | K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, |
| 3570 | K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
| 3571 | K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, |
| 3572 | K_MOUSEDOWN, K_MOUSEUP, |
| 3573 | K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
| 3574 | 0 |
| 3575 | }; |
| 3576 | #endif |
| 3577 | |
| 3578 | if (!p_sc) |
| 3579 | return FALSE; |
| 3580 | |
| 3581 | if (showcmd_visual) |
| 3582 | { |
| 3583 | showcmd_buf[0] = NUL; |
| 3584 | showcmd_visual = FALSE; |
| 3585 | } |
| 3586 | |
| 3587 | #if defined(FEAT_MOUSE) |
| 3588 | /* Ignore keys that are scrollbar updates and mouse clicks */ |
| 3589 | if (IS_SPECIAL(c)) |
| 3590 | for (i = 0; ignore[i] != 0; ++i) |
| 3591 | if (ignore[i] == c) |
| 3592 | return FALSE; |
| 3593 | #endif |
| 3594 | |
| 3595 | p = transchar(c); |
| 3596 | old_len = (int)STRLEN(showcmd_buf); |
| 3597 | extra_len = (int)STRLEN(p); |
| 3598 | overflow = old_len + extra_len - SHOWCMD_COLS; |
| 3599 | if (overflow > 0) |
| 3600 | STRCPY(showcmd_buf, showcmd_buf + overflow); |
| 3601 | STRCAT(showcmd_buf, p); |
| 3602 | |
| 3603 | if (char_avail()) |
| 3604 | return FALSE; |
| 3605 | |
| 3606 | display_showcmd(); |
| 3607 | |
| 3608 | return TRUE; |
| 3609 | } |
| 3610 | |
| 3611 | void |
| 3612 | add_to_showcmd_c(c) |
| 3613 | int c; |
| 3614 | { |
| 3615 | if (!add_to_showcmd(c)) |
| 3616 | setcursor(); |
| 3617 | } |
| 3618 | |
| 3619 | /* |
| 3620 | * Delete 'len' characters from the end of the shown command. |
| 3621 | */ |
| 3622 | static void |
| 3623 | del_from_showcmd(len) |
| 3624 | int len; |
| 3625 | { |
| 3626 | int old_len; |
| 3627 | |
| 3628 | if (!p_sc) |
| 3629 | return; |
| 3630 | |
| 3631 | old_len = (int)STRLEN(showcmd_buf); |
| 3632 | if (len > old_len) |
| 3633 | len = old_len; |
| 3634 | showcmd_buf[old_len - len] = NUL; |
| 3635 | |
| 3636 | if (!char_avail()) |
| 3637 | display_showcmd(); |
| 3638 | } |
| 3639 | |
| 3640 | /* |
| 3641 | * push_showcmd() and pop_showcmd() are used when waiting for the user to type |
| 3642 | * something and there is a partial mapping. |
| 3643 | */ |
| 3644 | void |
| 3645 | push_showcmd() |
| 3646 | { |
| 3647 | if (p_sc) |
| 3648 | STRCPY(old_showcmd_buf, showcmd_buf); |
| 3649 | } |
| 3650 | |
| 3651 | void |
| 3652 | pop_showcmd() |
| 3653 | { |
| 3654 | if (!p_sc) |
| 3655 | return; |
| 3656 | |
| 3657 | STRCPY(showcmd_buf, old_showcmd_buf); |
| 3658 | |
| 3659 | display_showcmd(); |
| 3660 | } |
| 3661 | |
| 3662 | static void |
| 3663 | display_showcmd() |
| 3664 | { |
| 3665 | int len; |
| 3666 | |
| 3667 | cursor_off(); |
| 3668 | |
| 3669 | len = (int)STRLEN(showcmd_buf); |
| 3670 | if (len == 0) |
| 3671 | showcmd_is_clear = TRUE; |
| 3672 | else |
| 3673 | { |
| 3674 | screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); |
| 3675 | showcmd_is_clear = FALSE; |
| 3676 | } |
| 3677 | |
| 3678 | /* |
| 3679 | * clear the rest of an old message by outputing up to SHOWCMD_COLS spaces |
| 3680 | */ |
| 3681 | screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); |
| 3682 | |
| 3683 | setcursor(); /* put cursor back where it belongs */ |
| 3684 | } |
| 3685 | #endif |
| 3686 | |
| 3687 | #ifdef FEAT_SCROLLBIND |
| 3688 | /* |
| 3689 | * When "check" is FALSE, prepare for commands that scroll the window. |
| 3690 | * When "check" is TRUE, take care of scroll-binding after the window has |
| 3691 | * scrolled. Called from normal_cmd() and edit(). |
| 3692 | */ |
| 3693 | void |
| 3694 | do_check_scrollbind(check) |
| 3695 | int check; |
| 3696 | { |
| 3697 | static win_T *old_curwin = NULL; |
| 3698 | static linenr_T old_topline = 0; |
| 3699 | #ifdef FEAT_DIFF |
| 3700 | static int old_topfill = 0; |
| 3701 | #endif |
| 3702 | static buf_T *old_buf = NULL; |
| 3703 | static colnr_T old_leftcol = 0; |
| 3704 | |
| 3705 | if (check && curwin->w_p_scb) |
| 3706 | { |
| 3707 | /* If a ":syncbind" command was just used, don't scroll, only reset |
| 3708 | * the values. */ |
| 3709 | if (did_syncbind) |
| 3710 | did_syncbind = FALSE; |
| 3711 | else if (curwin == old_curwin) |
| 3712 | { |
| 3713 | /* |
| 3714 | * Synchronize other windows, as necessary according to |
| 3715 | * 'scrollbind'. Don't do this after an ":edit" command, except |
| 3716 | * when 'diff' is set. |
| 3717 | */ |
| 3718 | if ((curwin->w_buffer == old_buf |
| 3719 | #ifdef FEAT_DIFF |
| 3720 | || curwin->w_p_diff |
| 3721 | #endif |
| 3722 | ) |
| 3723 | && (curwin->w_topline != old_topline |
| 3724 | #ifdef FEAT_DIFF |
| 3725 | || curwin->w_topfill != old_topfill |
| 3726 | #endif |
| 3727 | || curwin->w_leftcol != old_leftcol)) |
| 3728 | { |
| 3729 | check_scrollbind(curwin->w_topline - old_topline, |
| 3730 | (long)(curwin->w_leftcol - old_leftcol)); |
| 3731 | } |
| 3732 | } |
| 3733 | else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ |
| 3734 | { |
| 3735 | /* |
| 3736 | * When switching between windows, make sure that the relative |
| 3737 | * vertical offset is valid for the new window. The relative |
| 3738 | * offset is invalid whenever another 'scrollbind' window has |
| 3739 | * scrolled to a point that would force the current window to |
| 3740 | * scroll past the beginning or end of its buffer. When the |
| 3741 | * resync is performed, some of the other 'scrollbind' windows may |
| 3742 | * need to jump so that the current window's relative position is |
| 3743 | * visible on-screen. |
| 3744 | */ |
| 3745 | check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); |
| 3746 | } |
| 3747 | curwin->w_scbind_pos = curwin->w_topline; |
| 3748 | } |
| 3749 | |
| 3750 | old_curwin = curwin; |
| 3751 | old_topline = curwin->w_topline; |
| 3752 | #ifdef FEAT_DIFF |
| 3753 | old_topfill = curwin->w_topfill; |
| 3754 | #endif |
| 3755 | old_buf = curwin->w_buffer; |
| 3756 | old_leftcol = curwin->w_leftcol; |
| 3757 | } |
| 3758 | |
| 3759 | /* |
| 3760 | * Synchronize any windows that have "scrollbind" set, based on the |
| 3761 | * number of rows by which the current window has changed |
| 3762 | * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) |
| 3763 | */ |
| 3764 | void |
| 3765 | check_scrollbind(topline_diff, leftcol_diff) |
| 3766 | linenr_T topline_diff; |
| 3767 | long leftcol_diff; |
| 3768 | { |
| 3769 | int want_ver; |
| 3770 | int want_hor; |
| 3771 | win_T *old_curwin = curwin; |
| 3772 | buf_T *old_curbuf = curbuf; |
| 3773 | #ifdef FEAT_VISUAL |
| 3774 | int old_VIsual_select = VIsual_select; |
| 3775 | int old_VIsual_active = VIsual_active; |
| 3776 | #endif |
| 3777 | colnr_T tgt_leftcol = curwin->w_leftcol; |
| 3778 | long topline; |
| 3779 | long y; |
| 3780 | |
| 3781 | /* |
| 3782 | * check 'scrollopt' string for vertical and horizontal scroll options |
| 3783 | */ |
| 3784 | want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); |
| 3785 | #ifdef FEAT_DIFF |
| 3786 | want_ver |= old_curwin->w_p_diff; |
| 3787 | #endif |
| 3788 | want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); |
| 3789 | |
| 3790 | /* |
| 3791 | * loop through the scrollbound windows and scroll accordingly |
| 3792 | */ |
| 3793 | #ifdef FEAT_VISUAL |
| 3794 | VIsual_select = VIsual_active = 0; |
| 3795 | #endif |
| 3796 | for (curwin = firstwin; curwin; curwin = curwin->w_next) |
| 3797 | { |
| 3798 | curbuf = curwin->w_buffer; |
| 3799 | /* skip original window and windows with 'noscrollbind' */ |
| 3800 | if (curwin != old_curwin && curwin->w_p_scb) |
| 3801 | { |
| 3802 | /* |
| 3803 | * do the vertical scroll |
| 3804 | */ |
| 3805 | if (want_ver) |
| 3806 | { |
| 3807 | #ifdef FEAT_DIFF |
| 3808 | if (old_curwin->w_p_diff && curwin->w_p_diff) |
| 3809 | { |
| 3810 | diff_set_topline(old_curwin, curwin); |
| 3811 | } |
| 3812 | else |
| 3813 | #endif |
| 3814 | { |
| 3815 | curwin->w_scbind_pos += topline_diff; |
| 3816 | topline = curwin->w_scbind_pos; |
| 3817 | if (topline > curbuf->b_ml.ml_line_count) |
| 3818 | topline = curbuf->b_ml.ml_line_count; |
| 3819 | if (topline < 1) |
| 3820 | topline = 1; |
| 3821 | |
| 3822 | y = topline - curwin->w_topline; |
| 3823 | if (y > 0) |
| 3824 | scrollup(y, FALSE); |
| 3825 | else |
| 3826 | scrolldown(-y, FALSE); |
| 3827 | } |
| 3828 | |
| 3829 | redraw_later(VALID); |
| 3830 | cursor_correct(); |
| 3831 | #ifdef FEAT_WINDOWS |
| 3832 | curwin->w_redr_status = TRUE; |
| 3833 | #endif |
| 3834 | } |
| 3835 | |
| 3836 | /* |
| 3837 | * do the horizontal scroll |
| 3838 | */ |
| 3839 | if (want_hor && curwin->w_leftcol != tgt_leftcol) |
| 3840 | { |
| 3841 | curwin->w_leftcol = tgt_leftcol; |
| 3842 | leftcol_changed(); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | /* |
| 3848 | * reset current-window |
| 3849 | */ |
| 3850 | #ifdef FEAT_VISUAL |
| 3851 | VIsual_select = old_VIsual_select; |
| 3852 | VIsual_active = old_VIsual_active; |
| 3853 | #endif |
| 3854 | curwin = old_curwin; |
| 3855 | curbuf = old_curbuf; |
| 3856 | } |
| 3857 | #endif /* #ifdef FEAT_SCROLLBIND */ |
| 3858 | |
| 3859 | /* |
| 3860 | * Command character that's ignored. |
| 3861 | * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use |
| 3862 | * xon/xoff |
| 3863 | */ |
| 3864 | /*ARGSUSED */ |
| 3865 | static void |
| 3866 | nv_ignore(cap) |
| 3867 | cmdarg_T *cap; |
| 3868 | { |
Bram Moolenaar | fc73515 | 2005-03-22 22:54:12 +0000 | [diff] [blame] | 3869 | cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | /* |
| 3873 | * Command character doesn't exist. |
| 3874 | */ |
| 3875 | static void |
| 3876 | nv_error(cap) |
| 3877 | cmdarg_T *cap; |
| 3878 | { |
| 3879 | clearopbeep(cap->oap); |
| 3880 | } |
| 3881 | |
| 3882 | /* |
| 3883 | * <Help> and <F1> commands. |
| 3884 | */ |
| 3885 | static void |
| 3886 | nv_help(cap) |
| 3887 | cmdarg_T *cap; |
| 3888 | { |
| 3889 | if (!checkclearopq(cap->oap)) |
| 3890 | ex_help(NULL); |
| 3891 | } |
| 3892 | |
| 3893 | /* |
| 3894 | * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. |
| 3895 | */ |
| 3896 | static void |
| 3897 | nv_addsub(cap) |
| 3898 | cmdarg_T *cap; |
| 3899 | { |
| 3900 | if (!checkclearopq(cap->oap) |
| 3901 | && do_addsub((int)cap->cmdchar, cap->count1) == OK) |
| 3902 | prep_redo_cmd(cap); |
| 3903 | } |
| 3904 | |
| 3905 | /* |
| 3906 | * CTRL-F, CTRL-B, etc: Scroll page up or down. |
| 3907 | */ |
| 3908 | static void |
| 3909 | nv_page(cap) |
| 3910 | cmdarg_T *cap; |
| 3911 | { |
| 3912 | if (!checkclearop(cap->oap)) |
| 3913 | (void)onepage(cap->arg, cap->count1); |
| 3914 | } |
| 3915 | |
| 3916 | /* |
| 3917 | * Implementation of "gd" and "gD" command. |
| 3918 | */ |
| 3919 | static void |
| 3920 | nv_gd(oap, nchar) |
| 3921 | oparg_T *oap; |
| 3922 | int nchar; |
| 3923 | { |
| 3924 | int len; |
| 3925 | char_u *pat; |
| 3926 | pos_T old_pos; |
| 3927 | int t; |
| 3928 | int save_p_ws; |
| 3929 | int save_p_scs; |
| 3930 | char_u *ptr; |
| 3931 | |
| 3932 | if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 || |
| 3933 | (pat = alloc(len + 5)) == NULL) |
| 3934 | { |
| 3935 | clearopbeep(oap); |
| 3936 | return; |
| 3937 | } |
| 3938 | sprintf((char *)pat, vim_iswordp(ptr) ? "\\<%.*s\\>" : "%.*s", len, ptr); |
| 3939 | old_pos = curwin->w_cursor; |
| 3940 | save_p_ws = p_ws; |
| 3941 | save_p_scs = p_scs; |
| 3942 | p_ws = FALSE; /* don't wrap around end of file now */ |
| 3943 | p_scs = FALSE; /* don't switch ignorecase off now */ |
| 3944 | |
| 3945 | /* |
| 3946 | * With "gD" go to line 1. |
| 3947 | * With "gd" Search back for the start of the current function, then go |
| 3948 | * back until a blank line. If this fails go to line 1. |
| 3949 | */ |
| 3950 | if (nchar == 'D' || !findpar(oap, BACKWARD, 1L, '{', FALSE)) |
| 3951 | { |
| 3952 | setpcmark(); /* Set in findpar() otherwise */ |
| 3953 | curwin->w_cursor.lnum = 1; |
| 3954 | } |
| 3955 | else |
| 3956 | { |
| 3957 | while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
| 3958 | --curwin->w_cursor.lnum; |
| 3959 | } |
| 3960 | curwin->w_cursor.col = 0; |
| 3961 | |
| 3962 | /* Search forward for the identifier, ignore comment lines. */ |
| 3963 | while ((t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD, pat, 1L, 0, |
| 3964 | RE_LAST)) != FAIL |
| 3965 | #ifdef FEAT_COMMENTS |
| 3966 | && get_leader_len(ml_get_curline(), NULL, FALSE) > 0 |
| 3967 | #endif |
| 3968 | && old_pos.lnum > curwin->w_cursor.lnum) |
| 3969 | { |
| 3970 | /* Ignore this line, continue at start of next line. */ |
| 3971 | ++curwin->w_cursor.lnum; |
| 3972 | curwin->w_cursor.col = 0; |
| 3973 | } |
| 3974 | if (t == FAIL || old_pos.lnum <= curwin->w_cursor.lnum) |
| 3975 | { |
| 3976 | clearopbeep(oap); |
| 3977 | curwin->w_cursor = old_pos; |
| 3978 | } |
| 3979 | else |
| 3980 | { |
| 3981 | curwin->w_set_curswant = TRUE; |
| 3982 | #ifdef FEAT_FOLDING |
| 3983 | if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) |
| 3984 | foldOpenCursor(); |
| 3985 | #endif |
| 3986 | /* "n" searches forward now */ |
| 3987 | reset_search_dir(); |
| 3988 | } |
| 3989 | |
| 3990 | vim_free(pat); |
| 3991 | p_ws = save_p_ws; |
| 3992 | p_scs = save_p_scs; |
| 3993 | } |
| 3994 | |
| 3995 | /* |
| 3996 | * Move 'dist' lines in direction 'dir', counting lines by *screen* |
| 3997 | * lines rather than lines in the file. |
| 3998 | * 'dist' must be positive. |
| 3999 | * |
| 4000 | * Return OK if able to move cursor, FAIL otherwise. |
| 4001 | */ |
| 4002 | static int |
| 4003 | nv_screengo(oap, dir, dist) |
| 4004 | oparg_T *oap; |
| 4005 | int dir; |
| 4006 | long dist; |
| 4007 | { |
| 4008 | int linelen = linetabsize(ml_get_curline()); |
| 4009 | int retval = OK; |
| 4010 | int atend = FALSE; |
| 4011 | int n; |
| 4012 | int col_off1; /* margin offset for first screen line */ |
| 4013 | int col_off2; /* margin offset for wrapped screen line */ |
| 4014 | int width1; /* text width for first screen line */ |
| 4015 | int width2; /* test width for wrapped screen line */ |
| 4016 | |
| 4017 | oap->motion_type = MCHAR; |
| 4018 | oap->inclusive = FALSE; |
| 4019 | |
| 4020 | col_off1 = curwin_col_off(); |
| 4021 | col_off2 = col_off1 - curwin_col_off2(); |
| 4022 | width1 = W_WIDTH(curwin) - col_off1; |
| 4023 | width2 = W_WIDTH(curwin) - col_off2; |
| 4024 | |
| 4025 | #ifdef FEAT_VERTSPLIT |
| 4026 | if (curwin->w_width != 0) |
| 4027 | { |
| 4028 | #endif |
| 4029 | /* |
| 4030 | * Instead of sticking at the last character of the buffer line we |
| 4031 | * try to stick in the last column of the screen. |
| 4032 | */ |
| 4033 | if (curwin->w_curswant == MAXCOL) |
| 4034 | { |
| 4035 | atend = TRUE; |
| 4036 | validate_virtcol(); |
| 4037 | if (width1 <= 0) |
| 4038 | curwin->w_curswant = 0; |
| 4039 | else |
| 4040 | { |
| 4041 | curwin->w_curswant = width1 - 1; |
| 4042 | if (curwin->w_virtcol > curwin->w_curswant) |
| 4043 | curwin->w_curswant += ((curwin->w_virtcol |
| 4044 | - curwin->w_curswant - 1) / width2 + 1) * width2; |
| 4045 | } |
| 4046 | } |
| 4047 | else |
| 4048 | { |
| 4049 | if (linelen > width1) |
| 4050 | n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; |
| 4051 | else |
| 4052 | n = width1; |
| 4053 | if (curwin->w_curswant > (colnr_T)n + 1) |
| 4054 | curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) |
| 4055 | * width2; |
| 4056 | } |
| 4057 | |
| 4058 | while (dist--) |
| 4059 | { |
| 4060 | if (dir == BACKWARD) |
| 4061 | { |
| 4062 | if ((long)curwin->w_curswant >= width2) |
| 4063 | /* move back within line */ |
| 4064 | curwin->w_curswant -= width2; |
| 4065 | else |
| 4066 | { |
| 4067 | /* to previous line */ |
| 4068 | if (curwin->w_cursor.lnum == 1) |
| 4069 | { |
| 4070 | retval = FAIL; |
| 4071 | break; |
| 4072 | } |
| 4073 | --curwin->w_cursor.lnum; |
| 4074 | #ifdef FEAT_FOLDING |
| 4075 | /* Move to the start of a closed fold. Don't do that when |
| 4076 | * 'foldopen' contains "all": it will open in a moment. */ |
| 4077 | if (!(fdo_flags & FDO_ALL)) |
| 4078 | (void)hasFolding(curwin->w_cursor.lnum, |
| 4079 | &curwin->w_cursor.lnum, NULL); |
| 4080 | #endif |
| 4081 | linelen = linetabsize(ml_get_curline()); |
| 4082 | if (linelen > width1) |
| 4083 | curwin->w_curswant += (((linelen - width1 - 1) / width2) |
| 4084 | + 1) * width2; |
| 4085 | } |
| 4086 | } |
| 4087 | else /* dir == FORWARD */ |
| 4088 | { |
| 4089 | if (linelen > width1) |
| 4090 | n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; |
| 4091 | else |
| 4092 | n = width1; |
| 4093 | if (curwin->w_curswant + width2 < (colnr_T)n) |
| 4094 | /* move forward within line */ |
| 4095 | curwin->w_curswant += width2; |
| 4096 | else |
| 4097 | { |
| 4098 | /* to next line */ |
| 4099 | #ifdef FEAT_FOLDING |
| 4100 | /* Move to the end of a closed fold. */ |
| 4101 | (void)hasFolding(curwin->w_cursor.lnum, NULL, |
| 4102 | &curwin->w_cursor.lnum); |
| 4103 | #endif |
| 4104 | if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) |
| 4105 | { |
| 4106 | retval = FAIL; |
| 4107 | break; |
| 4108 | } |
| 4109 | curwin->w_cursor.lnum++; |
| 4110 | curwin->w_curswant %= width2; |
| 4111 | } |
| 4112 | } |
| 4113 | } |
| 4114 | #ifdef FEAT_VERTSPLIT |
| 4115 | } |
| 4116 | #endif |
| 4117 | |
| 4118 | coladvance(curwin->w_curswant); |
| 4119 | |
| 4120 | #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
| 4121 | if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
| 4122 | { |
| 4123 | /* |
| 4124 | * Check for landing on a character that got split at the end of the |
| 4125 | * last line. We want to advance a screenline, not end up in the same |
| 4126 | * screenline or move two screenlines. |
| 4127 | */ |
| 4128 | validate_virtcol(); |
| 4129 | if (curwin->w_virtcol > curwin->w_curswant |
| 4130 | && (curwin->w_curswant < (colnr_T)width1 |
| 4131 | ? (curwin->w_curswant > (colnr_T)width1 / 2) |
| 4132 | : ((curwin->w_curswant - width1) % width2 |
| 4133 | > (colnr_T)width2 / 2))) |
| 4134 | --curwin->w_cursor.col; |
| 4135 | } |
| 4136 | #endif |
| 4137 | |
| 4138 | if (atend) |
| 4139 | curwin->w_curswant = MAXCOL; /* stick in the last column */ |
| 4140 | |
| 4141 | return retval; |
| 4142 | } |
| 4143 | |
| 4144 | #ifdef FEAT_MOUSE |
| 4145 | /* |
| 4146 | * Mouse scroll wheel: Default action is to scroll three lines, or one page |
| 4147 | * when Shift or Ctrl is used. |
| 4148 | * K_MOUSEUP (cap->arg == TRUE) or K_MOUSEDOWN (cap->arg == FALSE) |
| 4149 | */ |
| 4150 | static void |
| 4151 | nv_mousescroll(cap) |
| 4152 | cmdarg_T *cap; |
| 4153 | { |
| 4154 | # if defined(FEAT_GUI) && defined(FEAT_WINDOWS) |
| 4155 | win_T *old_curwin; |
| 4156 | |
| 4157 | old_curwin = curwin; |
| 4158 | |
| 4159 | /* Currently we only get the mouse coordinates in the GUI. */ |
| 4160 | if (gui.in_use && mouse_row >= 0 && mouse_col >= 0) |
| 4161 | { |
| 4162 | int row, col; |
| 4163 | |
| 4164 | row = mouse_row; |
| 4165 | col = mouse_col; |
| 4166 | |
| 4167 | /* find the window at the pointer coordinates */ |
| 4168 | curwin = mouse_find_win(&row, &col); |
| 4169 | curbuf = curwin->w_buffer; |
| 4170 | } |
| 4171 | # endif |
| 4172 | |
| 4173 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 4174 | { |
| 4175 | (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L); |
| 4176 | } |
| 4177 | else |
| 4178 | { |
| 4179 | cap->count1 = 3; |
| 4180 | cap->count0 = 3; |
| 4181 | nv_scroll_line(cap); |
| 4182 | } |
| 4183 | |
| 4184 | # if defined(FEAT_GUI) && defined(FEAT_WINDOWS) |
| 4185 | curwin->w_redr_status = TRUE; |
| 4186 | |
| 4187 | curwin = old_curwin; |
| 4188 | curbuf = curwin->w_buffer; |
| 4189 | # endif |
| 4190 | } |
| 4191 | |
| 4192 | /* |
| 4193 | * Mouse clicks and drags. |
| 4194 | */ |
| 4195 | static void |
| 4196 | nv_mouse(cap) |
| 4197 | cmdarg_T *cap; |
| 4198 | { |
| 4199 | (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); |
| 4200 | } |
| 4201 | #endif |
| 4202 | |
| 4203 | /* |
| 4204 | * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. |
| 4205 | * cap->arg must be TRUE for CTRL-E. |
| 4206 | */ |
| 4207 | static void |
| 4208 | nv_scroll_line(cap) |
| 4209 | cmdarg_T *cap; |
| 4210 | { |
| 4211 | if (!checkclearop(cap->oap)) |
| 4212 | scroll_redraw(cap->arg, cap->count1); |
| 4213 | } |
| 4214 | |
| 4215 | /* |
| 4216 | * Scroll "count" lines up or down, and redraw. |
| 4217 | */ |
| 4218 | void |
| 4219 | scroll_redraw(up, count) |
| 4220 | int up; |
| 4221 | long count; |
| 4222 | { |
| 4223 | linenr_T prev_topline = curwin->w_topline; |
| 4224 | #ifdef FEAT_DIFF |
| 4225 | int prev_topfill = curwin->w_topfill; |
| 4226 | #endif |
| 4227 | linenr_T prev_lnum = curwin->w_cursor.lnum; |
| 4228 | |
| 4229 | if (up) |
| 4230 | scrollup(count, TRUE); |
| 4231 | else |
| 4232 | scrolldown(count, TRUE); |
| 4233 | if (p_so) |
| 4234 | { |
| 4235 | /* Adjust the cursor position for 'scrolloff'. Mark w_topline as |
| 4236 | * valid, otherwise the screen jumps back at the end of the file. */ |
| 4237 | cursor_correct(); |
| 4238 | check_cursor_moved(curwin); |
| 4239 | curwin->w_valid |= VALID_TOPLINE; |
| 4240 | |
| 4241 | /* If moved back to where we were, at least move the cursor, otherwise |
| 4242 | * we get stuck at one position. Don't move the cursor up if the |
| 4243 | * first line of the buffer is already on the screen */ |
| 4244 | while (curwin->w_topline == prev_topline |
| 4245 | #ifdef FEAT_DIFF |
| 4246 | && curwin->w_topfill == prev_topfill |
| 4247 | #endif |
| 4248 | ) |
| 4249 | { |
| 4250 | if (up) |
| 4251 | { |
| 4252 | if (curwin->w_cursor.lnum > prev_lnum |
| 4253 | || cursor_down(1L, FALSE) == FAIL) |
| 4254 | break; |
| 4255 | } |
| 4256 | else |
| 4257 | { |
| 4258 | if (curwin->w_cursor.lnum < prev_lnum |
| 4259 | || prev_topline == 1L |
| 4260 | || cursor_up(1L, FALSE) == FAIL) |
| 4261 | break; |
| 4262 | } |
| 4263 | /* Mark w_topline as valid, otherwise the screen jumps back at the |
| 4264 | * end of the file. */ |
| 4265 | check_cursor_moved(curwin); |
| 4266 | curwin->w_valid |= VALID_TOPLINE; |
| 4267 | } |
| 4268 | } |
| 4269 | if (curwin->w_cursor.lnum != prev_lnum) |
| 4270 | coladvance(curwin->w_curswant); |
| 4271 | redraw_later(VALID); |
| 4272 | } |
| 4273 | |
| 4274 | /* |
| 4275 | * Commands that start with "z". |
| 4276 | */ |
| 4277 | static void |
| 4278 | nv_zet(cap) |
| 4279 | cmdarg_T *cap; |
| 4280 | { |
| 4281 | long n; |
| 4282 | colnr_T col; |
| 4283 | int nchar = cap->nchar; |
| 4284 | #ifdef FEAT_FOLDING |
| 4285 | long old_fdl = curwin->w_p_fdl; |
| 4286 | int old_fen = curwin->w_p_fen; |
| 4287 | #endif |
| 4288 | |
| 4289 | if (VIM_ISDIGIT(nchar)) |
| 4290 | { |
| 4291 | /* |
| 4292 | * "z123{nchar}": edit the count before obtaining {nchar} |
| 4293 | */ |
| 4294 | if (checkclearop(cap->oap)) |
| 4295 | return; |
| 4296 | n = nchar - '0'; |
| 4297 | for (;;) |
| 4298 | { |
| 4299 | #ifdef USE_ON_FLY_SCROLL |
| 4300 | dont_scroll = TRUE; /* disallow scrolling here */ |
| 4301 | #endif |
| 4302 | ++no_mapping; |
| 4303 | ++allow_keys; /* no mapping for nchar, but allow key codes */ |
| 4304 | nchar = safe_vgetc(); |
| 4305 | #ifdef FEAT_LANGMAP |
| 4306 | LANGMAP_ADJUST(nchar, TRUE); |
| 4307 | #endif |
| 4308 | --no_mapping; |
| 4309 | --allow_keys; |
| 4310 | #ifdef FEAT_CMDL_INFO |
| 4311 | (void)add_to_showcmd(nchar); |
| 4312 | #endif |
| 4313 | if (nchar == K_DEL || nchar == K_KDEL) |
| 4314 | n /= 10; |
| 4315 | else if (VIM_ISDIGIT(nchar)) |
| 4316 | n = n * 10 + (nchar - '0'); |
| 4317 | else if (nchar == CAR) |
| 4318 | { |
| 4319 | #ifdef FEAT_GUI |
| 4320 | need_mouse_correct = TRUE; |
| 4321 | #endif |
| 4322 | win_setheight((int)n); |
| 4323 | break; |
| 4324 | } |
| 4325 | else if (nchar == 'l' |
| 4326 | || nchar == 'h' |
| 4327 | || nchar == K_LEFT |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 4328 | || nchar == K_RIGHT) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4329 | { |
| 4330 | cap->count1 = n ? n * cap->count1 : cap->count1; |
| 4331 | goto dozet; |
| 4332 | } |
| 4333 | else |
| 4334 | { |
| 4335 | clearopbeep(cap->oap); |
| 4336 | break; |
| 4337 | } |
| 4338 | } |
| 4339 | cap->oap->op_type = OP_NOP; |
| 4340 | return; |
| 4341 | } |
| 4342 | |
| 4343 | dozet: |
| 4344 | if ( |
| 4345 | #ifdef FEAT_FOLDING |
| 4346 | /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" |
| 4347 | * and "zC" only in Visual mode. "zj" and "zk" are motion |
| 4348 | * commands. */ |
| 4349 | cap->nchar != 'f' && cap->nchar != 'F' |
| 4350 | && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) |
| 4351 | && cap->nchar != 'j' && cap->nchar != 'k' |
| 4352 | && |
| 4353 | #endif |
| 4354 | checkclearop(cap->oap)) |
| 4355 | return; |
| 4356 | |
| 4357 | /* |
| 4358 | * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": |
| 4359 | * If line number given, set cursor. |
| 4360 | */ |
| 4361 | if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) |
| 4362 | && cap->count0 |
| 4363 | && cap->count0 != curwin->w_cursor.lnum) |
| 4364 | { |
| 4365 | setpcmark(); |
| 4366 | if (cap->count0 > curbuf->b_ml.ml_line_count) |
| 4367 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 4368 | else |
| 4369 | curwin->w_cursor.lnum = cap->count0; |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 4370 | check_cursor_col(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | switch (nchar) |
| 4374 | { |
| 4375 | /* "z+", "z<CR>" and "zt": put cursor at top of screen */ |
| 4376 | case '+': |
| 4377 | if (cap->count0 == 0) |
| 4378 | { |
| 4379 | /* No count given: put cursor at the line below screen */ |
| 4380 | validate_botline(); /* make sure w_botline is valid */ |
| 4381 | if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
| 4382 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 4383 | else |
| 4384 | curwin->w_cursor.lnum = curwin->w_botline; |
| 4385 | } |
| 4386 | /* FALLTHROUGH */ |
| 4387 | case NL: |
| 4388 | case CAR: |
| 4389 | case K_KENTER: |
| 4390 | beginline(BL_WHITE | BL_FIX); |
| 4391 | /* FALLTHROUGH */ |
| 4392 | |
| 4393 | case 't': scroll_cursor_top(0, TRUE); |
| 4394 | redraw_later(VALID); |
| 4395 | break; |
| 4396 | |
| 4397 | /* "z." and "zz": put cursor in middle of screen */ |
| 4398 | case '.': beginline(BL_WHITE | BL_FIX); |
| 4399 | /* FALLTHROUGH */ |
| 4400 | |
| 4401 | case 'z': scroll_cursor_halfway(TRUE); |
| 4402 | redraw_later(VALID); |
| 4403 | break; |
| 4404 | |
| 4405 | /* "z^", "z-" and "zb": put cursor at bottom of screen */ |
| 4406 | case '^': /* Strange Vi behavior: <count>z^ finds line at top of window |
| 4407 | * when <count> is at bottom of window, and puts that one at |
| 4408 | * bottom of window. */ |
| 4409 | if (cap->count0 != 0) |
| 4410 | { |
| 4411 | scroll_cursor_bot(0, TRUE); |
| 4412 | curwin->w_cursor.lnum = curwin->w_topline; |
| 4413 | } |
| 4414 | else if (curwin->w_topline == 1) |
| 4415 | curwin->w_cursor.lnum = 1; |
| 4416 | else |
| 4417 | curwin->w_cursor.lnum = curwin->w_topline - 1; |
| 4418 | /* FALLTHROUGH */ |
| 4419 | case '-': |
| 4420 | beginline(BL_WHITE | BL_FIX); |
| 4421 | /* FALLTHROUGH */ |
| 4422 | |
| 4423 | case 'b': scroll_cursor_bot(0, TRUE); |
| 4424 | redraw_later(VALID); |
| 4425 | break; |
| 4426 | |
| 4427 | /* "zH" - scroll screen right half-page */ |
| 4428 | case 'H': |
| 4429 | cap->count1 *= W_WIDTH(curwin) / 2; |
| 4430 | /* FALLTHROUGH */ |
| 4431 | |
| 4432 | /* "zh" - scroll screen to the right */ |
| 4433 | case 'h': |
| 4434 | case K_LEFT: |
| 4435 | if (!curwin->w_p_wrap) |
| 4436 | { |
| 4437 | if ((colnr_T)cap->count1 > curwin->w_leftcol) |
| 4438 | curwin->w_leftcol = 0; |
| 4439 | else |
| 4440 | curwin->w_leftcol -= (colnr_T)cap->count1; |
| 4441 | leftcol_changed(); |
| 4442 | } |
| 4443 | break; |
| 4444 | |
| 4445 | /* "zL" - scroll screen left half-page */ |
| 4446 | case 'L': cap->count1 *= W_WIDTH(curwin) / 2; |
| 4447 | /* FALLTHROUGH */ |
| 4448 | |
| 4449 | /* "zl" - scroll screen to the left */ |
| 4450 | case 'l': |
| 4451 | case K_RIGHT: |
| 4452 | if (!curwin->w_p_wrap) |
| 4453 | { |
| 4454 | /* scroll the window left */ |
| 4455 | curwin->w_leftcol += (colnr_T)cap->count1; |
| 4456 | leftcol_changed(); |
| 4457 | } |
| 4458 | break; |
| 4459 | |
| 4460 | /* "zs" - scroll screen, cursor at the start */ |
| 4461 | case 's': if (!curwin->w_p_wrap) |
| 4462 | { |
| 4463 | #ifdef FEAT_FOLDING |
| 4464 | if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4465 | col = 0; /* like the cursor is in col 0 */ |
| 4466 | else |
| 4467 | #endif |
| 4468 | getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); |
| 4469 | if ((long)col > p_siso) |
| 4470 | col -= p_siso; |
| 4471 | else |
| 4472 | col = 0; |
| 4473 | if (curwin->w_leftcol != col) |
| 4474 | { |
| 4475 | curwin->w_leftcol = col; |
| 4476 | redraw_later(NOT_VALID); |
| 4477 | } |
| 4478 | } |
| 4479 | break; |
| 4480 | |
| 4481 | /* "ze" - scroll screen, cursor at the end */ |
| 4482 | case 'e': if (!curwin->w_p_wrap) |
| 4483 | { |
| 4484 | #ifdef FEAT_FOLDING |
| 4485 | if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4486 | col = 0; /* like the cursor is in col 0 */ |
| 4487 | else |
| 4488 | #endif |
| 4489 | getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); |
| 4490 | n = W_WIDTH(curwin) - curwin_col_off(); |
| 4491 | if ((long)col + p_siso < n) |
| 4492 | col = 0; |
| 4493 | else |
| 4494 | col = col + p_siso - n + 1; |
| 4495 | if (curwin->w_leftcol != col) |
| 4496 | { |
| 4497 | curwin->w_leftcol = col; |
| 4498 | redraw_later(NOT_VALID); |
| 4499 | } |
| 4500 | } |
| 4501 | break; |
| 4502 | |
| 4503 | #ifdef FEAT_FOLDING |
| 4504 | /* "zF": create fold command */ |
| 4505 | /* "zf": create fold operator */ |
| 4506 | case 'F': |
| 4507 | case 'f': if (foldManualAllowed(TRUE)) |
| 4508 | { |
| 4509 | cap->nchar = 'f'; |
| 4510 | nv_operator(cap); |
| 4511 | curwin->w_p_fen = TRUE; |
| 4512 | |
| 4513 | /* "zF" is like "zfzf" */ |
| 4514 | if (nchar == 'F' && cap->oap->op_type == OP_FOLD) |
| 4515 | { |
| 4516 | nv_operator(cap); |
| 4517 | finish_op = TRUE; |
| 4518 | } |
| 4519 | } |
| 4520 | else |
| 4521 | clearopbeep(cap->oap); |
| 4522 | break; |
| 4523 | |
| 4524 | /* "zd": delete fold at cursor */ |
| 4525 | /* "zD": delete fold at cursor recursively */ |
| 4526 | case 'd': |
| 4527 | case 'D': if (foldManualAllowed(FALSE)) |
| 4528 | { |
| 4529 | if (VIsual_active) |
| 4530 | nv_operator(cap); |
| 4531 | else |
| 4532 | deleteFold(curwin->w_cursor.lnum, |
| 4533 | curwin->w_cursor.lnum, nchar == 'D', FALSE); |
| 4534 | } |
| 4535 | break; |
| 4536 | |
| 4537 | /* "zE": erease all folds */ |
| 4538 | case 'E': if (foldmethodIsManual(curwin)) |
| 4539 | { |
| 4540 | clearFolding(curwin); |
| 4541 | changed_window_setting(); |
| 4542 | } |
| 4543 | else if (foldmethodIsMarker(curwin)) |
| 4544 | deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, |
| 4545 | TRUE, FALSE); |
| 4546 | else |
| 4547 | EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); |
| 4548 | break; |
| 4549 | |
| 4550 | /* "zn": fold none: reset 'foldenable' */ |
| 4551 | case 'n': curwin->w_p_fen = FALSE; |
| 4552 | break; |
| 4553 | |
| 4554 | /* "zN": fold Normal: set 'foldenable' */ |
| 4555 | case 'N': curwin->w_p_fen = TRUE; |
| 4556 | break; |
| 4557 | |
| 4558 | /* "zi": invert folding: toggle 'foldenable' */ |
| 4559 | case 'i': curwin->w_p_fen = !curwin->w_p_fen; |
| 4560 | break; |
| 4561 | |
| 4562 | /* "za": open closed fold or close open fold at cursor */ |
| 4563 | case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4564 | openFold(curwin->w_cursor.lnum, cap->count1); |
| 4565 | else |
| 4566 | { |
| 4567 | closeFold(curwin->w_cursor.lnum, cap->count1); |
| 4568 | curwin->w_p_fen = TRUE; |
| 4569 | } |
| 4570 | break; |
| 4571 | |
| 4572 | /* "zA": open fold at cursor recursively */ |
| 4573 | case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) |
| 4574 | openFoldRecurse(curwin->w_cursor.lnum); |
| 4575 | else |
| 4576 | { |
| 4577 | closeFoldRecurse(curwin->w_cursor.lnum); |
| 4578 | curwin->w_p_fen = TRUE; |
| 4579 | } |
| 4580 | break; |
| 4581 | |
| 4582 | /* "zo": open fold at cursor or Visual area */ |
| 4583 | case 'o': if (VIsual_active) |
| 4584 | nv_operator(cap); |
| 4585 | else |
| 4586 | openFold(curwin->w_cursor.lnum, cap->count1); |
| 4587 | break; |
| 4588 | |
| 4589 | /* "zO": open fold recursively */ |
| 4590 | case 'O': if (VIsual_active) |
| 4591 | nv_operator(cap); |
| 4592 | else |
| 4593 | openFoldRecurse(curwin->w_cursor.lnum); |
| 4594 | break; |
| 4595 | |
| 4596 | /* "zc": close fold at cursor or Visual area */ |
| 4597 | case 'c': if (VIsual_active) |
| 4598 | nv_operator(cap); |
| 4599 | else |
| 4600 | closeFold(curwin->w_cursor.lnum, cap->count1); |
| 4601 | curwin->w_p_fen = TRUE; |
| 4602 | break; |
| 4603 | |
| 4604 | /* "zC": close fold recursively */ |
| 4605 | case 'C': if (VIsual_active) |
| 4606 | nv_operator(cap); |
| 4607 | else |
| 4608 | closeFoldRecurse(curwin->w_cursor.lnum); |
| 4609 | curwin->w_p_fen = TRUE; |
| 4610 | break; |
| 4611 | |
| 4612 | /* "zv": open folds at the cursor */ |
| 4613 | case 'v': foldOpenCursor(); |
| 4614 | break; |
| 4615 | |
| 4616 | /* "zx": re-apply 'foldlevel' and open folds at the cursor */ |
| 4617 | case 'x': curwin->w_p_fen = TRUE; |
| 4618 | newFoldLevel(); /* update right now */ |
| 4619 | foldOpenCursor(); |
| 4620 | break; |
| 4621 | |
| 4622 | /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ |
| 4623 | case 'X': curwin->w_p_fen = TRUE; |
| 4624 | old_fdl = -1; /* force an update */ |
| 4625 | break; |
| 4626 | |
| 4627 | /* "zm": fold more */ |
| 4628 | case 'm': if (curwin->w_p_fdl > 0) |
| 4629 | --curwin->w_p_fdl; |
| 4630 | old_fdl = -1; /* force an update */ |
| 4631 | curwin->w_p_fen = TRUE; |
| 4632 | break; |
| 4633 | |
| 4634 | /* "zM": close all folds */ |
| 4635 | case 'M': curwin->w_p_fdl = 0; |
| 4636 | old_fdl = -1; /* force an update */ |
| 4637 | curwin->w_p_fen = TRUE; |
| 4638 | break; |
| 4639 | |
| 4640 | /* "zr": reduce folding */ |
| 4641 | case 'r': ++curwin->w_p_fdl; |
| 4642 | break; |
| 4643 | |
| 4644 | /* "zR": open all folds */ |
| 4645 | case 'R': curwin->w_p_fdl = getDeepestNesting(); |
| 4646 | old_fdl = -1; /* force an update */ |
| 4647 | break; |
| 4648 | |
| 4649 | case 'j': /* "zj" move to next fold downwards */ |
| 4650 | case 'k': /* "zk" move to next fold upwards */ |
| 4651 | if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, |
| 4652 | cap->count1) == FAIL) |
| 4653 | clearopbeep(cap->oap); |
| 4654 | break; |
| 4655 | |
| 4656 | #endif /* FEAT_FOLDING */ |
| 4657 | |
| 4658 | default: clearopbeep(cap->oap); |
| 4659 | } |
| 4660 | |
| 4661 | #ifdef FEAT_FOLDING |
| 4662 | /* Redraw when 'foldenable' changed */ |
| 4663 | if (old_fen != curwin->w_p_fen) |
| 4664 | { |
| 4665 | # ifdef FEAT_DIFF |
| 4666 | win_T *wp; |
| 4667 | |
| 4668 | if (foldmethodIsDiff(curwin) && curwin->w_p_scb) |
| 4669 | { |
| 4670 | /* Adjust 'foldenable' in diff-synced windows. */ |
| 4671 | FOR_ALL_WINDOWS(wp) |
| 4672 | { |
| 4673 | if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) |
| 4674 | { |
| 4675 | wp->w_p_fen = curwin->w_p_fen; |
| 4676 | changed_window_setting_win(wp); |
| 4677 | } |
| 4678 | } |
| 4679 | } |
| 4680 | # endif |
| 4681 | changed_window_setting(); |
| 4682 | } |
| 4683 | |
| 4684 | /* Redraw when 'foldlevel' changed. */ |
| 4685 | if (old_fdl != curwin->w_p_fdl) |
| 4686 | newFoldLevel(); |
| 4687 | #endif |
| 4688 | } |
| 4689 | |
| 4690 | #ifdef FEAT_GUI |
| 4691 | /* |
| 4692 | * Vertical scrollbar movement. |
| 4693 | */ |
| 4694 | static void |
| 4695 | nv_ver_scrollbar(cap) |
| 4696 | cmdarg_T *cap; |
| 4697 | { |
| 4698 | if (cap->oap->op_type != OP_NOP) |
| 4699 | clearopbeep(cap->oap); |
| 4700 | |
| 4701 | /* Even if an operator was pending, we still want to scroll */ |
| 4702 | gui_do_scroll(); |
| 4703 | } |
| 4704 | |
| 4705 | /* |
| 4706 | * Horizontal scrollbar movement. |
| 4707 | */ |
| 4708 | static void |
| 4709 | nv_hor_scrollbar(cap) |
| 4710 | cmdarg_T *cap; |
| 4711 | { |
| 4712 | if (cap->oap->op_type != OP_NOP) |
| 4713 | clearopbeep(cap->oap); |
| 4714 | |
| 4715 | /* Even if an operator was pending, we still want to scroll */ |
| 4716 | gui_do_horiz_scroll(); |
| 4717 | } |
| 4718 | #endif |
| 4719 | |
| 4720 | /* |
| 4721 | * "Q" command. |
| 4722 | */ |
| 4723 | static void |
| 4724 | nv_exmode(cap) |
| 4725 | cmdarg_T *cap; |
| 4726 | { |
| 4727 | /* |
| 4728 | * Ignore 'Q' in Visual mode, just give a beep. |
| 4729 | */ |
| 4730 | #ifdef FEAT_VISUAL |
| 4731 | if (VIsual_active) |
| 4732 | vim_beep(); |
| 4733 | else |
| 4734 | #endif |
| 4735 | if (!checkclearop(cap->oap)) |
| 4736 | do_exmode(FALSE); |
| 4737 | } |
| 4738 | |
| 4739 | /* |
| 4740 | * Handle a ":" command. |
| 4741 | */ |
| 4742 | static void |
| 4743 | nv_colon(cap) |
| 4744 | cmdarg_T *cap; |
| 4745 | { |
| 4746 | int old_p_im; |
| 4747 | |
| 4748 | #ifdef FEAT_VISUAL |
| 4749 | if (VIsual_active) |
| 4750 | nv_operator(cap); |
| 4751 | else |
| 4752 | #endif |
| 4753 | { |
| 4754 | if (cap->oap->op_type != OP_NOP) |
| 4755 | { |
| 4756 | /* Using ":" as a movement is characterwise exclusive. */ |
| 4757 | cap->oap->motion_type = MCHAR; |
| 4758 | cap->oap->inclusive = FALSE; |
| 4759 | } |
| 4760 | else if (cap->count0) |
| 4761 | { |
| 4762 | /* translate "count:" into ":.,.+(count - 1)" */ |
| 4763 | stuffcharReadbuff('.'); |
| 4764 | if (cap->count0 > 1) |
| 4765 | { |
| 4766 | stuffReadbuff((char_u *)",.+"); |
| 4767 | stuffnumReadbuff((long)cap->count0 - 1L); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | /* When typing, don't type below an old message */ |
| 4772 | if (KeyTyped) |
| 4773 | compute_cmdrow(); |
| 4774 | |
| 4775 | old_p_im = p_im; |
| 4776 | |
| 4777 | /* get a command line and execute it */ |
| 4778 | do_cmdline(NULL, getexline, NULL, |
| 4779 | cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
| 4780 | |
| 4781 | /* If 'insertmode' changed, enter or exit Insert mode */ |
| 4782 | if (p_im != old_p_im) |
| 4783 | { |
| 4784 | if (p_im) |
| 4785 | restart_edit = 'i'; |
| 4786 | else |
| 4787 | restart_edit = 0; |
| 4788 | } |
| 4789 | |
| 4790 | /* The start of the operator may have become invalid by the Ex |
| 4791 | * command. */ |
| 4792 | if (cap->oap->op_type != OP_NOP |
| 4793 | && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
| 4794 | || cap->oap->start.col > |
| 4795 | STRLEN(ml_get(cap->oap->start.lnum)))) |
| 4796 | clearopbeep(cap->oap); |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | /* |
| 4801 | * Handle CTRL-G command. |
| 4802 | */ |
| 4803 | static void |
| 4804 | nv_ctrlg(cap) |
| 4805 | cmdarg_T *cap; |
| 4806 | { |
| 4807 | #ifdef FEAT_VISUAL |
| 4808 | if (VIsual_active) /* toggle Selection/Visual mode */ |
| 4809 | { |
| 4810 | VIsual_select = !VIsual_select; |
| 4811 | showmode(); |
| 4812 | } |
| 4813 | else |
| 4814 | #endif |
| 4815 | if (!checkclearop(cap->oap)) |
| 4816 | /* print full name if count given or :cd used */ |
| 4817 | fileinfo((int)cap->count0, FALSE, TRUE); |
| 4818 | } |
| 4819 | |
| 4820 | /* |
| 4821 | * Handle CTRL-H <Backspace> command. |
| 4822 | */ |
| 4823 | static void |
| 4824 | nv_ctrlh(cap) |
| 4825 | cmdarg_T *cap; |
| 4826 | { |
| 4827 | #ifdef FEAT_VISUAL |
| 4828 | if (VIsual_active && VIsual_select) |
| 4829 | { |
| 4830 | cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ |
| 4831 | v_visop(cap); |
| 4832 | } |
| 4833 | else |
| 4834 | #endif |
| 4835 | nv_left(cap); |
| 4836 | } |
| 4837 | |
| 4838 | /* |
| 4839 | * CTRL-L: clear screen and redraw. |
| 4840 | */ |
| 4841 | static void |
| 4842 | nv_clear(cap) |
| 4843 | cmdarg_T *cap; |
| 4844 | { |
| 4845 | if (!checkclearop(cap->oap)) |
| 4846 | { |
| 4847 | #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT |
| 4848 | /* |
| 4849 | * Right now, the BeBox doesn't seem to have an easy way to detect |
| 4850 | * window resizing, so we cheat and make the user detect it |
| 4851 | * manually with CTRL-L instead |
| 4852 | */ |
| 4853 | ui_get_shellsize(); |
| 4854 | #endif |
| 4855 | #ifdef FEAT_SYN_HL |
| 4856 | /* Clear all syntax states to force resyncing. */ |
| 4857 | syn_stack_free_all(curbuf); |
| 4858 | #endif |
| 4859 | redraw_later(CLEAR); |
| 4860 | } |
| 4861 | } |
| 4862 | |
| 4863 | /* |
| 4864 | * CTRL-O: In Select mode: switch to Visual mode for one command. |
| 4865 | * Otherwise: Go to older pcmark. |
| 4866 | */ |
| 4867 | static void |
| 4868 | nv_ctrlo(cap) |
| 4869 | cmdarg_T *cap; |
| 4870 | { |
| 4871 | #ifdef FEAT_VISUAL |
| 4872 | if (VIsual_active && VIsual_select) |
| 4873 | { |
| 4874 | VIsual_select = FALSE; |
| 4875 | showmode(); |
| 4876 | restart_VIsual_select = 2; /* restart Select mode later */ |
| 4877 | } |
| 4878 | else |
| 4879 | #endif |
| 4880 | { |
| 4881 | cap->count1 = -cap->count1; |
| 4882 | nv_pcmark(cap); |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | /* |
| 4887 | * CTRL-^ command, short for ":e #" |
| 4888 | */ |
| 4889 | static void |
| 4890 | nv_hat(cap) |
| 4891 | cmdarg_T *cap; |
| 4892 | { |
| 4893 | if (!checkclearopq(cap->oap)) |
| 4894 | (void)buflist_getfile((int)cap->count0, (linenr_T)0, |
| 4895 | GETF_SETMARK|GETF_ALT, FALSE); |
| 4896 | } |
| 4897 | |
| 4898 | /* |
| 4899 | * "Z" commands. |
| 4900 | */ |
| 4901 | static void |
| 4902 | nv_Zet(cap) |
| 4903 | cmdarg_T *cap; |
| 4904 | { |
| 4905 | if (!checkclearopq(cap->oap)) |
| 4906 | { |
| 4907 | switch (cap->nchar) |
| 4908 | { |
| 4909 | /* "ZZ": equivalent to ":x". */ |
| 4910 | case 'Z': do_cmdline_cmd((char_u *)"x"); |
| 4911 | break; |
| 4912 | |
| 4913 | /* "ZQ": equivalent to ":q!" (Elvis compatible). */ |
| 4914 | case 'Q': do_cmdline_cmd((char_u *)"q!"); |
| 4915 | break; |
| 4916 | |
| 4917 | default: clearopbeep(cap->oap); |
| 4918 | } |
| 4919 | } |
| 4920 | } |
| 4921 | |
| 4922 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 4923 | /* |
| 4924 | * Call nv_ident() as if "c1" was used, with "c2" as next character. |
| 4925 | */ |
| 4926 | void |
| 4927 | do_nv_ident(c1, c2) |
| 4928 | int c1; |
| 4929 | int c2; |
| 4930 | { |
| 4931 | oparg_T oa; |
| 4932 | cmdarg_T ca; |
| 4933 | |
| 4934 | clear_oparg(&oa); |
| 4935 | vim_memset(&ca, 0, sizeof(ca)); |
| 4936 | ca.oap = &oa; |
| 4937 | ca.cmdchar = c1; |
| 4938 | ca.nchar = c2; |
| 4939 | nv_ident(&ca); |
| 4940 | } |
| 4941 | #endif |
| 4942 | |
| 4943 | /* |
| 4944 | * Handle the commands that use the word under the cursor. |
| 4945 | * [g] CTRL-] :ta to current identifier |
| 4946 | * [g] 'K' run program for current identifier |
| 4947 | * [g] '*' / to current identifier or string |
| 4948 | * [g] '#' ? to current identifier or string |
| 4949 | * g ']' :tselect for current identifier |
| 4950 | */ |
| 4951 | static void |
| 4952 | nv_ident(cap) |
| 4953 | cmdarg_T *cap; |
| 4954 | { |
| 4955 | char_u *ptr = NULL; |
| 4956 | char_u *buf; |
| 4957 | char_u *p; |
| 4958 | char_u *kp; /* value of 'keywordprg' */ |
| 4959 | int kp_help; /* 'keywordprg' is ":help" */ |
| 4960 | int n = 0; /* init for GCC */ |
| 4961 | int cmdchar; |
| 4962 | int g_cmd; /* "g" command */ |
| 4963 | char_u *aux_ptr; |
| 4964 | int isman; |
| 4965 | int isman_s; |
| 4966 | |
| 4967 | if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ |
| 4968 | { |
| 4969 | cmdchar = cap->nchar; |
| 4970 | g_cmd = TRUE; |
| 4971 | } |
| 4972 | else |
| 4973 | { |
| 4974 | cmdchar = cap->cmdchar; |
| 4975 | g_cmd = FALSE; |
| 4976 | } |
| 4977 | |
| 4978 | if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ |
| 4979 | cmdchar = '#'; |
| 4980 | |
| 4981 | /* |
| 4982 | * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. |
| 4983 | */ |
| 4984 | if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') |
| 4985 | { |
| 4986 | #ifdef FEAT_VISUAL |
| 4987 | if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) |
| 4988 | return; |
| 4989 | #endif |
| 4990 | if (checkclearopq(cap->oap)) |
| 4991 | return; |
| 4992 | } |
| 4993 | |
| 4994 | if (ptr == NULL && (n = find_ident_under_cursor(&ptr, |
| 4995 | (cmdchar == '*' || cmdchar == '#') |
| 4996 | ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) |
| 4997 | { |
| 4998 | clearop(cap->oap); |
| 4999 | return; |
| 5000 | } |
| 5001 | |
| 5002 | /* Allocate buffer to put the command in. Inserting backslashes can |
| 5003 | * double the length of the word. p_kp / curbuf->b_p_kp could be added |
| 5004 | * and some numbers. */ |
| 5005 | kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); |
| 5006 | kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 |
| 5007 | || STRCMP(kp, ":help") == 0); |
| 5008 | buf = alloc((unsigned)(n * 2 + 30 + STRLEN(kp))); |
| 5009 | if (buf == NULL) |
| 5010 | return; |
| 5011 | buf[0] = NUL; |
| 5012 | |
| 5013 | switch (cmdchar) |
| 5014 | { |
| 5015 | case '*': |
| 5016 | case '#': |
| 5017 | /* |
| 5018 | * Put cursor at start of word, makes search skip the word |
| 5019 | * under the cursor. |
| 5020 | * Call setpcmark() first, so "*``" puts the cursor back where |
| 5021 | * it was. |
| 5022 | */ |
| 5023 | setpcmark(); |
| 5024 | curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); |
| 5025 | |
| 5026 | if (!g_cmd && vim_iswordp(ptr)) |
| 5027 | STRCPY(buf, "\\<"); |
| 5028 | no_smartcase = TRUE; /* don't use 'smartcase' now */ |
| 5029 | break; |
| 5030 | |
| 5031 | case 'K': |
| 5032 | if (kp_help) |
| 5033 | STRCPY(buf, "he! "); |
| 5034 | else |
| 5035 | { |
| 5036 | /* When a count is given, turn it into a range. Is this |
| 5037 | * really what we want? */ |
| 5038 | isman = (STRCMP(kp, "man") == 0); |
| 5039 | isman_s = (STRCMP(kp, "man -s") == 0); |
| 5040 | if (cap->count0 != 0 && !(isman || isman_s)) |
| 5041 | sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); |
| 5042 | |
| 5043 | STRCAT(buf, "! "); |
| 5044 | if (cap->count0 == 0 && isman_s) |
| 5045 | STRCAT(buf, "man"); |
| 5046 | else |
| 5047 | STRCAT(buf, kp); |
| 5048 | STRCAT(buf, " "); |
| 5049 | if (cap->count0 != 0 && (isman || isman_s)) |
| 5050 | { |
| 5051 | sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); |
| 5052 | STRCAT(buf, " "); |
| 5053 | } |
| 5054 | } |
| 5055 | break; |
| 5056 | |
| 5057 | case ']': |
| 5058 | #ifdef FEAT_CSCOPE |
| 5059 | if (p_cst) |
| 5060 | STRCPY(buf, "cstag "); |
| 5061 | else |
| 5062 | #endif |
| 5063 | STRCPY(buf, "ts "); |
| 5064 | break; |
| 5065 | |
| 5066 | default: |
| 5067 | if (curbuf->b_help) |
| 5068 | STRCPY(buf, "he! "); |
| 5069 | else if (g_cmd) |
| 5070 | STRCPY(buf, "tj "); |
| 5071 | else |
| 5072 | STRCPY(buf, "ta "); |
| 5073 | } |
| 5074 | |
| 5075 | /* |
| 5076 | * Now grab the chars in the identifier |
| 5077 | */ |
| 5078 | if (cmdchar == '*') |
| 5079 | aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); |
| 5080 | else if (cmdchar == '#') |
| 5081 | aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); |
| 5082 | else if (cmdchar == 'K' && !kp_help) |
| 5083 | aux_ptr = (char_u *)" \t\\\"|!"; |
| 5084 | else |
| 5085 | /* Don't escape spaces and Tabs in a tag with a backslash */ |
| 5086 | aux_ptr = (char_u *)"\\|\""; |
| 5087 | |
| 5088 | p = buf + STRLEN(buf); |
| 5089 | while (n-- > 0) |
| 5090 | { |
| 5091 | /* put a backslash before \ and some others */ |
| 5092 | if (vim_strchr(aux_ptr, *ptr) != NULL) |
| 5093 | *p++ = '\\'; |
| 5094 | #ifdef FEAT_MBYTE |
| 5095 | /* When current byte is a part of multibyte character, copy all bytes |
| 5096 | * of that character. */ |
| 5097 | if (has_mbyte) |
| 5098 | { |
| 5099 | int i; |
| 5100 | int len = (*mb_ptr2len_check)(ptr) - 1; |
| 5101 | |
| 5102 | for (i = 0; i < len && n >= 1; ++i, --n) |
| 5103 | *p++ = *ptr++; |
| 5104 | } |
| 5105 | #endif |
| 5106 | *p++ = *ptr++; |
| 5107 | } |
| 5108 | *p = NUL; |
| 5109 | |
| 5110 | /* |
| 5111 | * Execute the command. |
| 5112 | */ |
| 5113 | if (cmdchar == '*' || cmdchar == '#') |
| 5114 | { |
| 5115 | if (!g_cmd && ( |
| 5116 | #ifdef FEAT_MBYTE |
| 5117 | has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : |
| 5118 | #endif |
| 5119 | vim_iswordc(ptr[-1]))) |
| 5120 | STRCAT(buf, "\\>"); |
| 5121 | #ifdef FEAT_CMDHIST |
| 5122 | /* put pattern in search history */ |
| 5123 | add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
| 5124 | #endif |
| 5125 | normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
| 5126 | } |
| 5127 | else |
| 5128 | do_cmdline_cmd(buf); |
| 5129 | |
| 5130 | vim_free(buf); |
| 5131 | } |
| 5132 | |
| 5133 | #ifdef FEAT_VISUAL |
| 5134 | /* |
| 5135 | * Get visually selected text, within one line only. |
| 5136 | * Returns FAIL if more than one line selected. |
| 5137 | */ |
| 5138 | static int |
| 5139 | get_visual_text(cap, pp, lenp) |
| 5140 | cmdarg_T *cap; |
| 5141 | char_u **pp; /* return: start of selected text */ |
| 5142 | int *lenp; /* return: length of selected text */ |
| 5143 | { |
| 5144 | if (VIsual_mode != 'V') |
| 5145 | unadjust_for_sel(); |
| 5146 | if (VIsual.lnum != curwin->w_cursor.lnum) |
| 5147 | { |
| 5148 | clearopbeep(cap->oap); |
| 5149 | return FAIL; |
| 5150 | } |
| 5151 | if (VIsual_mode == 'V') |
| 5152 | { |
| 5153 | *pp = ml_get_curline(); |
| 5154 | *lenp = (int)STRLEN(*pp); |
| 5155 | } |
| 5156 | else |
| 5157 | { |
| 5158 | if (lt(curwin->w_cursor, VIsual)) |
| 5159 | { |
| 5160 | *pp = ml_get_pos(&curwin->w_cursor); |
| 5161 | *lenp = VIsual.col - curwin->w_cursor.col + 1; |
| 5162 | } |
| 5163 | else |
| 5164 | { |
| 5165 | *pp = ml_get_pos(&VIsual); |
| 5166 | *lenp = curwin->w_cursor.col - VIsual.col + 1; |
| 5167 | } |
| 5168 | #ifdef FEAT_MBYTE |
| 5169 | if (has_mbyte) |
| 5170 | /* Correct the length to include the whole last character. */ |
| 5171 | *lenp += (*mb_ptr2len_check)(*pp + (*lenp - 1)) - 1; |
| 5172 | #endif |
| 5173 | } |
| 5174 | reset_VIsual_and_resel(); |
| 5175 | return OK; |
| 5176 | } |
| 5177 | #endif |
| 5178 | |
| 5179 | /* |
| 5180 | * CTRL-T: backwards in tag stack |
| 5181 | */ |
| 5182 | static void |
| 5183 | nv_tagpop(cap) |
| 5184 | cmdarg_T *cap; |
| 5185 | { |
| 5186 | if (!checkclearopq(cap->oap)) |
| 5187 | do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); |
| 5188 | } |
| 5189 | |
| 5190 | /* |
| 5191 | * Handle scrolling command 'H', 'L' and 'M'. |
| 5192 | */ |
| 5193 | static void |
| 5194 | nv_scroll(cap) |
| 5195 | cmdarg_T *cap; |
| 5196 | { |
| 5197 | int used = 0; |
| 5198 | long n; |
| 5199 | #ifdef FEAT_FOLDING |
| 5200 | linenr_T lnum; |
| 5201 | #endif |
| 5202 | int half; |
| 5203 | |
| 5204 | cap->oap->motion_type = MLINE; |
| 5205 | setpcmark(); |
| 5206 | |
| 5207 | if (cap->cmdchar == 'L') |
| 5208 | { |
| 5209 | validate_botline(); /* make sure curwin->w_botline is valid */ |
| 5210 | curwin->w_cursor.lnum = curwin->w_botline - 1; |
| 5211 | if (cap->count1 - 1 >= curwin->w_cursor.lnum) |
| 5212 | curwin->w_cursor.lnum = 1; |
| 5213 | else |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5214 | { |
| 5215 | #ifdef FEAT_FOLDING |
| 5216 | if (hasAnyFolding(curwin)) |
| 5217 | { |
| 5218 | /* Count a fold for one screen line. */ |
| 5219 | for (n = cap->count1 - 1; n > 0 |
| 5220 | && curwin->w_cursor.lnum > curwin->w_topline; --n) |
| 5221 | { |
| 5222 | (void)hasFolding(curwin->w_cursor.lnum, |
| 5223 | &curwin->w_cursor.lnum, NULL); |
| 5224 | --curwin->w_cursor.lnum; |
| 5225 | } |
| 5226 | } |
| 5227 | else |
| 5228 | #endif |
| 5229 | curwin->w_cursor.lnum -= cap->count1 - 1; |
| 5230 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5231 | } |
| 5232 | else |
| 5233 | { |
| 5234 | if (cap->cmdchar == 'M') |
| 5235 | { |
| 5236 | #ifdef FEAT_DIFF |
| 5237 | /* Don't count filler lines above the window. */ |
| 5238 | used -= diff_check_fill(curwin, curwin->w_topline) |
| 5239 | - curwin->w_topfill; |
| 5240 | #endif |
| 5241 | validate_botline(); /* make sure w_empty_rows is valid */ |
| 5242 | half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; |
| 5243 | for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) |
| 5244 | { |
| 5245 | #ifdef FEAT_DIFF |
| 5246 | /* Count half he number of filler lines to be "below this |
| 5247 | * line" and half to be "above the next line". */ |
| 5248 | if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline |
| 5249 | + n) / 2 >= half) |
| 5250 | { |
| 5251 | --n; |
| 5252 | break; |
| 5253 | } |
| 5254 | #endif |
| 5255 | used += plines(curwin->w_topline + n); |
| 5256 | if (used >= half) |
| 5257 | break; |
| 5258 | #ifdef FEAT_FOLDING |
| 5259 | if (hasFolding(curwin->w_topline + n, NULL, &lnum)) |
| 5260 | n = lnum - curwin->w_topline; |
| 5261 | #endif |
| 5262 | } |
| 5263 | if (n > 0 && used > curwin->w_height) |
| 5264 | --n; |
| 5265 | } |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5266 | else /* (cap->cmdchar == 'H') */ |
| 5267 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5268 | n = cap->count1 - 1; |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5269 | #ifdef FEAT_FOLDING |
| 5270 | if (hasAnyFolding(curwin)) |
| 5271 | { |
| 5272 | /* Count a fold for one screen line. */ |
| 5273 | lnum = curwin->w_topline; |
| 5274 | while (n-- > 0 && lnum < curwin->w_botline - 1) |
| 5275 | { |
| 5276 | hasFolding(lnum, NULL, &lnum); |
| 5277 | ++lnum; |
| 5278 | } |
| 5279 | n = lnum - curwin->w_topline; |
| 5280 | } |
| 5281 | #endif |
| 5282 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5283 | curwin->w_cursor.lnum = curwin->w_topline + n; |
| 5284 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 5285 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 5286 | } |
| 5287 | |
| 5288 | cursor_correct(); /* correct for 'so' */ |
| 5289 | beginline(BL_SOL | BL_FIX); |
| 5290 | } |
| 5291 | |
| 5292 | /* |
| 5293 | * Cursor right commands. |
| 5294 | */ |
| 5295 | static void |
| 5296 | nv_right(cap) |
| 5297 | cmdarg_T *cap; |
| 5298 | { |
| 5299 | long n; |
| 5300 | #ifdef FEAT_VISUAL |
| 5301 | int PAST_LINE; |
| 5302 | #else |
| 5303 | # define PAST_LINE 0 |
| 5304 | #endif |
| 5305 | |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5306 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 5307 | { |
| 5308 | /* <C-Right> and <S-Right> move a word or WORD right */ |
| 5309 | if (mod_mask & MOD_MASK_CTRL) |
| 5310 | cap->arg = TRUE; |
| 5311 | nv_wordcmd(cap); |
| 5312 | return; |
| 5313 | } |
| 5314 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5315 | cap->oap->motion_type = MCHAR; |
| 5316 | cap->oap->inclusive = FALSE; |
| 5317 | #ifdef FEAT_VISUAL |
| 5318 | PAST_LINE = (VIsual_active && *p_sel != 'o'); |
| 5319 | |
| 5320 | # ifdef FEAT_VIRTUALEDIT |
| 5321 | /* |
| 5322 | * In virtual mode, there's no such thing as "PAST_LINE", as lines are |
| 5323 | * (theoretically) infinitly long. |
| 5324 | */ |
| 5325 | if (virtual_active()) |
| 5326 | PAST_LINE = 0; |
| 5327 | # endif |
| 5328 | #endif |
| 5329 | |
| 5330 | for (n = cap->count1; n > 0; --n) |
| 5331 | { |
| 5332 | if ((!PAST_LINE && oneright() == FAIL) |
| 5333 | || (PAST_LINE && *ml_get_cursor() == NUL)) |
| 5334 | { |
| 5335 | /* |
| 5336 | * <Space> wraps to next line if 'whichwrap' bit 1 set. |
| 5337 | * 'l' wraps to next line if 'whichwrap' bit 2 set. |
| 5338 | * CURS_RIGHT wraps to next line if 'whichwrap' bit 3 set |
| 5339 | */ |
| 5340 | if ( ((cap->cmdchar == ' ' |
| 5341 | && vim_strchr(p_ww, 's') != NULL) |
| 5342 | || (cap->cmdchar == 'l' |
| 5343 | && vim_strchr(p_ww, 'l') != NULL) |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 5344 | || (cap->cmdchar == K_RIGHT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5345 | && vim_strchr(p_ww, '>') != NULL)) |
| 5346 | && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
| 5347 | { |
| 5348 | /* When deleting we also count the NL as a character. |
| 5349 | * Set cap->oap->inclusive when last char in the line is |
| 5350 | * included, move to next line after that */ |
| 5351 | if ( (cap->oap->op_type == OP_DELETE |
| 5352 | || cap->oap->op_type == OP_CHANGE) |
| 5353 | && !cap->oap->inclusive |
| 5354 | && !lineempty(curwin->w_cursor.lnum)) |
| 5355 | cap->oap->inclusive = TRUE; |
| 5356 | else |
| 5357 | { |
| 5358 | ++curwin->w_cursor.lnum; |
| 5359 | curwin->w_cursor.col = 0; |
| 5360 | #ifdef FEAT_VIRTUALEDIT |
| 5361 | curwin->w_cursor.coladd = 0; |
| 5362 | #endif |
| 5363 | curwin->w_set_curswant = TRUE; |
| 5364 | cap->oap->inclusive = FALSE; |
| 5365 | } |
| 5366 | continue; |
| 5367 | } |
| 5368 | if (cap->oap->op_type == OP_NOP) |
| 5369 | { |
| 5370 | /* Only beep and flush if not moved at all */ |
| 5371 | if (n == cap->count1) |
| 5372 | beep_flush(); |
| 5373 | } |
| 5374 | else |
| 5375 | { |
| 5376 | if (!lineempty(curwin->w_cursor.lnum)) |
| 5377 | cap->oap->inclusive = TRUE; |
| 5378 | } |
| 5379 | break; |
| 5380 | } |
| 5381 | #ifdef FEAT_VISUAL |
| 5382 | else if (PAST_LINE) |
| 5383 | { |
| 5384 | curwin->w_set_curswant = TRUE; |
| 5385 | # ifdef FEAT_VIRTUALEDIT |
| 5386 | if (virtual_active()) |
| 5387 | oneright(); |
| 5388 | else |
| 5389 | # endif |
| 5390 | { |
| 5391 | # ifdef FEAT_MBYTE |
| 5392 | if (has_mbyte) |
| 5393 | curwin->w_cursor.col += |
| 5394 | (*mb_ptr2len_check)(ml_get_cursor()); |
| 5395 | else |
| 5396 | # endif |
| 5397 | ++curwin->w_cursor.col; |
| 5398 | } |
| 5399 | } |
| 5400 | #endif |
| 5401 | } |
| 5402 | #ifdef FEAT_FOLDING |
| 5403 | if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped |
| 5404 | && cap->oap->op_type == OP_NOP) |
| 5405 | foldOpenCursor(); |
| 5406 | #endif |
| 5407 | } |
| 5408 | |
| 5409 | /* |
| 5410 | * Cursor left commands. |
| 5411 | * |
| 5412 | * Returns TRUE when operator end should not be adjusted. |
| 5413 | */ |
| 5414 | static void |
| 5415 | nv_left(cap) |
| 5416 | cmdarg_T *cap; |
| 5417 | { |
| 5418 | long n; |
| 5419 | |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5420 | if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
| 5421 | { |
| 5422 | /* <C-Left> and <S-Left> move a word or WORD left */ |
| 5423 | if (mod_mask & MOD_MASK_CTRL) |
| 5424 | cap->arg = 1; |
| 5425 | nv_bck_word(cap); |
| 5426 | return; |
| 5427 | } |
| 5428 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5429 | cap->oap->motion_type = MCHAR; |
| 5430 | cap->oap->inclusive = FALSE; |
| 5431 | for (n = cap->count1; n > 0; --n) |
| 5432 | { |
| 5433 | if (oneleft() == FAIL) |
| 5434 | { |
| 5435 | /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. |
| 5436 | * 'h' wraps to previous line if 'whichwrap' has 'h'. |
| 5437 | * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. |
| 5438 | */ |
| 5439 | if ( (((cap->cmdchar == K_BS |
| 5440 | || cap->cmdchar == Ctrl_H) |
| 5441 | && vim_strchr(p_ww, 'b') != NULL) |
| 5442 | || (cap->cmdchar == 'h' |
| 5443 | && vim_strchr(p_ww, 'h') != NULL) |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 5444 | || (cap->cmdchar == K_LEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5445 | && vim_strchr(p_ww, '<') != NULL)) |
| 5446 | && curwin->w_cursor.lnum > 1) |
| 5447 | { |
| 5448 | --(curwin->w_cursor.lnum); |
| 5449 | coladvance((colnr_T)MAXCOL); |
| 5450 | curwin->w_set_curswant = TRUE; |
| 5451 | |
| 5452 | /* When the NL before the first char has to be deleted we |
| 5453 | * put the cursor on the NUL after the previous line. |
| 5454 | * This is a very special case, be careful! |
| 5455 | * don't adjust op_end now, otherwise it won't work */ |
| 5456 | if ( (cap->oap->op_type == OP_DELETE |
| 5457 | || cap->oap->op_type == OP_CHANGE) |
| 5458 | && !lineempty(curwin->w_cursor.lnum)) |
| 5459 | { |
| 5460 | ++curwin->w_cursor.col; |
| 5461 | cap->retval |= CA_NO_ADJ_OP_END; |
| 5462 | } |
| 5463 | continue; |
| 5464 | } |
| 5465 | /* Only beep and flush if not moved at all */ |
| 5466 | else if (cap->oap->op_type == OP_NOP && n == cap->count1) |
| 5467 | beep_flush(); |
| 5468 | break; |
| 5469 | } |
| 5470 | } |
| 5471 | #ifdef FEAT_FOLDING |
| 5472 | if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped |
| 5473 | && cap->oap->op_type == OP_NOP) |
| 5474 | foldOpenCursor(); |
| 5475 | #endif |
| 5476 | } |
| 5477 | |
| 5478 | /* |
| 5479 | * Cursor up commands. |
| 5480 | * cap->arg is TRUE for "-": Move cursor to first non-blank. |
| 5481 | */ |
| 5482 | static void |
| 5483 | nv_up(cap) |
| 5484 | cmdarg_T *cap; |
| 5485 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5486 | if (mod_mask & MOD_MASK_SHIFT) |
| 5487 | { |
| 5488 | /* <S-Up> is page up */ |
| 5489 | cap->arg = BACKWARD; |
| 5490 | nv_page(cap); |
| 5491 | } |
| 5492 | else |
| 5493 | { |
| 5494 | cap->oap->motion_type = MLINE; |
| 5495 | if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) |
| 5496 | clearopbeep(cap->oap); |
| 5497 | else if (cap->arg) |
| 5498 | beginline(BL_WHITE | BL_FIX); |
| 5499 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | /* |
| 5503 | * Cursor down commands. |
| 5504 | * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. |
| 5505 | */ |
| 5506 | static void |
| 5507 | nv_down(cap) |
| 5508 | cmdarg_T *cap; |
| 5509 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5510 | if (mod_mask & MOD_MASK_SHIFT) |
| 5511 | { |
| 5512 | /* <S-Down> is page down */ |
| 5513 | cap->arg = FORWARD; |
| 5514 | nv_page(cap); |
| 5515 | } |
| 5516 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5517 | #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
| 5518 | /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 5519 | if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5520 | do_cmdline_cmd((char_u *)".cc"); |
| 5521 | else |
| 5522 | #endif |
| 5523 | { |
| 5524 | #ifdef FEAT_CMDWIN |
| 5525 | /* In the cmdline window a <CR> executes the command. */ |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 5526 | if (cmdwin_type != 0 && cap->cmdchar == CAR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5527 | cmdwin_result = CAR; |
| 5528 | else |
| 5529 | #endif |
| 5530 | { |
| 5531 | cap->oap->motion_type = MLINE; |
| 5532 | if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) |
| 5533 | clearopbeep(cap->oap); |
| 5534 | else if (cap->arg) |
| 5535 | beginline(BL_WHITE | BL_FIX); |
| 5536 | } |
| 5537 | } |
| 5538 | } |
| 5539 | |
| 5540 | #ifdef FEAT_SEARCHPATH |
| 5541 | /* |
| 5542 | * Grab the file name under the cursor and edit it. |
| 5543 | */ |
| 5544 | static void |
| 5545 | nv_gotofile(cap) |
| 5546 | cmdarg_T *cap; |
| 5547 | { |
| 5548 | char_u *ptr; |
| 5549 | |
| 5550 | #ifdef FEAT_CMDWIN |
| 5551 | if (cmdwin_type != 0) |
| 5552 | { |
| 5553 | clearopbeep(cap->oap); |
| 5554 | return; |
| 5555 | } |
| 5556 | #endif |
| 5557 | |
| 5558 | # ifdef FEAT_VISUAL |
| 5559 | /* |
| 5560 | * In Visual mode, use the selected text as a file name. |
| 5561 | * Don't allow selection across multiple lines. |
| 5562 | */ |
| 5563 | if (VIsual_active) |
| 5564 | { |
| 5565 | int len; |
| 5566 | |
| 5567 | if (get_visual_text(cap, &ptr, &len) == FAIL) |
| 5568 | return; |
| 5569 | ptr = find_file_name_in_path(ptr, len, |
| 5570 | FNAME_MESS|FNAME_EXP|FNAME_REL, cap->count1, curbuf->b_ffname); |
| 5571 | } |
| 5572 | else |
| 5573 | # endif |
| 5574 | ptr = file_name_at_cursor(FNAME_MESS|FNAME_HYP|FNAME_EXP|FNAME_REL, |
| 5575 | cap->count1); |
| 5576 | |
| 5577 | if (ptr != NULL) |
| 5578 | { |
| 5579 | /* do autowrite if necessary */ |
| 5580 | if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !P_HID(curbuf)) |
| 5581 | autowrite(curbuf, FALSE); |
| 5582 | setpcmark(); |
| 5583 | (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, |
| 5584 | P_HID(curbuf) ? ECMD_HIDE : 0); |
| 5585 | vim_free(ptr); |
| 5586 | } |
| 5587 | else |
| 5588 | clearop(cap->oap); |
| 5589 | } |
| 5590 | #endif |
| 5591 | |
| 5592 | /* |
| 5593 | * <End> command: to end of current line or last line. |
| 5594 | */ |
| 5595 | static void |
| 5596 | nv_end(cap) |
| 5597 | cmdarg_T *cap; |
| 5598 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5599 | if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5600 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 5601 | cap->arg = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5602 | nv_goto(cap); |
| 5603 | cap->count1 = 1; /* to end of current line */ |
| 5604 | } |
| 5605 | nv_dollar(cap); |
| 5606 | } |
| 5607 | |
| 5608 | /* |
| 5609 | * Handle the "$" command. |
| 5610 | */ |
| 5611 | static void |
| 5612 | nv_dollar(cap) |
| 5613 | cmdarg_T *cap; |
| 5614 | { |
| 5615 | cap->oap->motion_type = MCHAR; |
| 5616 | cap->oap->inclusive = TRUE; |
| 5617 | #ifdef FEAT_VIRTUALEDIT |
| 5618 | /* In virtual mode when off the edge of a line and an operator |
| 5619 | * is pending (whew!) keep the cursor where it is. |
| 5620 | * Otherwise, send it to the end of the line. */ |
| 5621 | if (!virtual_active() || gchar_cursor() != NUL |
| 5622 | || cap->oap->op_type == OP_NOP) |
| 5623 | #endif |
| 5624 | curwin->w_curswant = MAXCOL; /* so we stay at the end */ |
| 5625 | if (cursor_down((long)(cap->count1 - 1), |
| 5626 | cap->oap->op_type == OP_NOP) == FAIL) |
| 5627 | clearopbeep(cap->oap); |
| 5628 | #ifdef FEAT_FOLDING |
| 5629 | else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 5630 | foldOpenCursor(); |
| 5631 | #endif |
| 5632 | } |
| 5633 | |
| 5634 | /* |
| 5635 | * Implementation of '?' and '/' commands. |
| 5636 | * If cap->arg is TRUE don't set PC mark. |
| 5637 | */ |
| 5638 | static void |
| 5639 | nv_search(cap) |
| 5640 | cmdarg_T *cap; |
| 5641 | { |
| 5642 | oparg_T *oap = cap->oap; |
| 5643 | |
| 5644 | if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) |
| 5645 | { |
| 5646 | /* Translate "g??" to "g?g?" */ |
| 5647 | cap->cmdchar = 'g'; |
| 5648 | cap->nchar = '?'; |
| 5649 | nv_operator(cap); |
| 5650 | return; |
| 5651 | } |
| 5652 | |
| 5653 | cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
| 5654 | |
| 5655 | if (cap->searchbuf == NULL) |
| 5656 | { |
| 5657 | clearop(oap); |
| 5658 | return; |
| 5659 | } |
| 5660 | |
| 5661 | normal_search(cap, cap->cmdchar, cap->searchbuf, |
| 5662 | (cap->arg ? 0 : SEARCH_MARK)); |
| 5663 | } |
| 5664 | |
| 5665 | /* |
| 5666 | * Handle "N" and "n" commands. |
| 5667 | * cap->arg is SEARCH_REV for "N", 0 for "n". |
| 5668 | */ |
| 5669 | static void |
| 5670 | nv_next(cap) |
| 5671 | cmdarg_T *cap; |
| 5672 | { |
| 5673 | normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); |
| 5674 | } |
| 5675 | |
| 5676 | /* |
| 5677 | * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). |
| 5678 | * Uses only cap->count1 and cap->oap from "cap". |
| 5679 | */ |
| 5680 | static void |
| 5681 | normal_search(cap, dir, pat, opt) |
| 5682 | cmdarg_T *cap; |
| 5683 | int dir; |
| 5684 | char_u *pat; |
| 5685 | int opt; /* extra flags for do_search() */ |
| 5686 | { |
| 5687 | int i; |
| 5688 | |
| 5689 | cap->oap->motion_type = MCHAR; |
| 5690 | cap->oap->inclusive = FALSE; |
| 5691 | cap->oap->use_reg_one = TRUE; |
| 5692 | curwin->w_set_curswant = TRUE; |
| 5693 | |
| 5694 | i = do_search(cap->oap, dir, pat, cap->count1, |
| 5695 | opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG); |
| 5696 | if (i == 0) |
| 5697 | clearop(cap->oap); |
| 5698 | else |
| 5699 | { |
| 5700 | if (i == 2) |
| 5701 | cap->oap->motion_type = MLINE; |
| 5702 | #ifdef FEAT_VIRTUALEDIT |
| 5703 | curwin->w_cursor.coladd = 0; |
| 5704 | #endif |
| 5705 | #ifdef FEAT_FOLDING |
| 5706 | if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) |
| 5707 | foldOpenCursor(); |
| 5708 | #endif |
| 5709 | } |
| 5710 | |
| 5711 | /* "/$" will put the cursor after the end of the line, may need to |
| 5712 | * correct that here */ |
| 5713 | check_cursor(); |
| 5714 | } |
| 5715 | |
| 5716 | /* |
| 5717 | * Character search commands. |
| 5718 | * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for |
| 5719 | * ',' and FALSE for ';'. |
| 5720 | * cap->nchar is NUL for ',' and ';' (repeat the search) |
| 5721 | */ |
| 5722 | static void |
| 5723 | nv_csearch(cap) |
| 5724 | cmdarg_T *cap; |
| 5725 | { |
| 5726 | int t_cmd; |
| 5727 | |
| 5728 | if (cap->cmdchar == 't' || cap->cmdchar == 'T') |
| 5729 | t_cmd = TRUE; |
| 5730 | else |
| 5731 | t_cmd = FALSE; |
| 5732 | |
| 5733 | cap->oap->motion_type = MCHAR; |
| 5734 | if (cap->arg == BACKWARD) |
| 5735 | cap->oap->inclusive = FALSE; |
| 5736 | else |
| 5737 | cap->oap->inclusive = TRUE; |
| 5738 | if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) |
| 5739 | clearopbeep(cap->oap); |
| 5740 | else |
| 5741 | { |
| 5742 | curwin->w_set_curswant = TRUE; |
| 5743 | #ifdef FEAT_VIRTUALEDIT |
| 5744 | /* Include a Tab for "tx" and for "dfx". */ |
| 5745 | if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD |
| 5746 | && (t_cmd || cap->oap->op_type != OP_NOP)) |
| 5747 | { |
| 5748 | colnr_T scol, ecol; |
| 5749 | |
| 5750 | getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); |
| 5751 | curwin->w_cursor.coladd = ecol - scol; |
| 5752 | } |
| 5753 | else |
| 5754 | curwin->w_cursor.coladd = 0; |
| 5755 | #endif |
| 5756 | #ifdef FEAT_VISUAL |
| 5757 | adjust_for_sel(cap); |
| 5758 | #endif |
| 5759 | #ifdef FEAT_FOLDING |
| 5760 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 5761 | foldOpenCursor(); |
| 5762 | #endif |
| 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | /* |
| 5767 | * "[" and "]" commands. |
| 5768 | * cap->arg is BACKWARD for "[" and FORWARD for "]". |
| 5769 | */ |
| 5770 | static void |
| 5771 | nv_brackets(cap) |
| 5772 | cmdarg_T *cap; |
| 5773 | { |
| 5774 | pos_T new_pos; |
| 5775 | pos_T prev_pos; |
| 5776 | pos_T *pos = NULL; /* init for GCC */ |
| 5777 | pos_T old_pos; /* cursor position before command */ |
| 5778 | int flag; |
| 5779 | long n; |
| 5780 | int findc; |
| 5781 | int c; |
| 5782 | |
| 5783 | cap->oap->motion_type = MCHAR; |
| 5784 | cap->oap->inclusive = FALSE; |
| 5785 | old_pos = curwin->w_cursor; |
| 5786 | #ifdef FEAT_VIRTUALEDIT |
| 5787 | curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ |
| 5788 | #endif |
| 5789 | |
| 5790 | #ifdef FEAT_SEARCHPATH |
| 5791 | /* |
| 5792 | * "[f" or "]f" : Edit file under the cursor (same as "gf") |
| 5793 | */ |
| 5794 | if (cap->nchar == 'f') |
| 5795 | nv_gotofile(cap); |
| 5796 | else |
| 5797 | #endif |
| 5798 | |
| 5799 | #ifdef FEAT_FIND_ID |
| 5800 | /* |
| 5801 | * Find the occurence(s) of the identifier or define under cursor |
| 5802 | * in current and included files or jump to the first occurence. |
| 5803 | * |
| 5804 | * search list jump |
| 5805 | * fwd bwd fwd bwd fwd bwd |
| 5806 | * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" |
| 5807 | * define "]d" "[d" "]D" "[D" "]^D" "[^D" |
| 5808 | */ |
| 5809 | if (vim_strchr((char_u *) |
| 5810 | #ifdef EBCDIC |
| 5811 | "iI\005dD\067", |
| 5812 | #else |
| 5813 | "iI\011dD\004", |
| 5814 | #endif |
| 5815 | cap->nchar) != NULL) |
| 5816 | { |
| 5817 | char_u *ptr; |
| 5818 | int len; |
| 5819 | |
| 5820 | if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) |
| 5821 | clearop(cap->oap); |
| 5822 | else |
| 5823 | { |
| 5824 | find_pattern_in_path(ptr, 0, len, TRUE, |
| 5825 | cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, |
| 5826 | ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, |
| 5827 | cap->count1, |
| 5828 | isupper(cap->nchar) ? ACTION_SHOW_ALL : |
| 5829 | islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, |
| 5830 | cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, |
| 5831 | (linenr_T)MAXLNUM); |
| 5832 | curwin->w_set_curswant = TRUE; |
| 5833 | } |
| 5834 | } |
| 5835 | else |
| 5836 | #endif |
| 5837 | |
| 5838 | /* |
| 5839 | * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' |
| 5840 | * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. |
| 5841 | * "[/", "[*", "]/", "]*": go to Nth comment start/end. |
| 5842 | * "[m" or "]m" search for prev/next start of (Java) method. |
| 5843 | * "[M" or "]M" search for prev/next end of (Java) method. |
| 5844 | */ |
| 5845 | if ( (cap->cmdchar == '[' |
| 5846 | && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) |
| 5847 | || (cap->cmdchar == ']' |
| 5848 | && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) |
| 5849 | { |
| 5850 | if (cap->nchar == '*') |
| 5851 | cap->nchar = '/'; |
| 5852 | new_pos.lnum = 0; |
| 5853 | prev_pos.lnum = 0; |
| 5854 | if (cap->nchar == 'm' || cap->nchar == 'M') |
| 5855 | { |
| 5856 | if (cap->cmdchar == '[') |
| 5857 | findc = '{'; |
| 5858 | else |
| 5859 | findc = '}'; |
| 5860 | n = 9999; |
| 5861 | } |
| 5862 | else |
| 5863 | { |
| 5864 | findc = cap->nchar; |
| 5865 | n = cap->count1; |
| 5866 | } |
| 5867 | for ( ; n > 0; --n) |
| 5868 | { |
| 5869 | if ((pos = findmatchlimit(cap->oap, findc, |
| 5870 | (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) |
| 5871 | { |
| 5872 | if (new_pos.lnum == 0) /* nothing found */ |
| 5873 | { |
| 5874 | if (cap->nchar != 'm' && cap->nchar != 'M') |
| 5875 | clearopbeep(cap->oap); |
| 5876 | } |
| 5877 | else |
| 5878 | pos = &new_pos; /* use last one found */ |
| 5879 | break; |
| 5880 | } |
| 5881 | prev_pos = new_pos; |
| 5882 | curwin->w_cursor = *pos; |
| 5883 | new_pos = *pos; |
| 5884 | } |
| 5885 | curwin->w_cursor = old_pos; |
| 5886 | |
| 5887 | /* |
| 5888 | * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only |
| 5889 | * brought us to the match for "[m" and "]M" when inside a method. |
| 5890 | * Try finding the '{' or '}' we want to be at. |
| 5891 | * Also repeat for the given count. |
| 5892 | */ |
| 5893 | if (cap->nchar == 'm' || cap->nchar == 'M') |
| 5894 | { |
| 5895 | /* norm is TRUE for "]M" and "[m" */ |
| 5896 | int norm = ((findc == '{') == (cap->nchar == 'm')); |
| 5897 | |
| 5898 | n = cap->count1; |
| 5899 | /* found a match: we were inside a method */ |
| 5900 | if (prev_pos.lnum != 0) |
| 5901 | { |
| 5902 | pos = &prev_pos; |
| 5903 | curwin->w_cursor = prev_pos; |
| 5904 | if (norm) |
| 5905 | --n; |
| 5906 | } |
| 5907 | else |
| 5908 | pos = NULL; |
| 5909 | while (n > 0) |
| 5910 | { |
| 5911 | for (;;) |
| 5912 | { |
| 5913 | if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) |
| 5914 | { |
| 5915 | /* if not found anything, that's an error */ |
| 5916 | if (pos == NULL) |
| 5917 | clearopbeep(cap->oap); |
| 5918 | n = 0; |
| 5919 | break; |
| 5920 | } |
| 5921 | c = gchar_cursor(); |
| 5922 | if (c == '{' || c == '}') |
| 5923 | { |
| 5924 | /* Must have found end/start of class: use it. |
| 5925 | * Or found the place to be at. */ |
| 5926 | if ((c == findc && norm) || (n == 1 && !norm)) |
| 5927 | { |
| 5928 | new_pos = curwin->w_cursor; |
| 5929 | pos = &new_pos; |
| 5930 | n = 0; |
| 5931 | } |
| 5932 | /* if no match found at all, we started outside of the |
| 5933 | * class and we're inside now. Just go on. */ |
| 5934 | else if (new_pos.lnum == 0) |
| 5935 | { |
| 5936 | new_pos = curwin->w_cursor; |
| 5937 | pos = &new_pos; |
| 5938 | } |
| 5939 | /* found start/end of other method: go to match */ |
| 5940 | else if ((pos = findmatchlimit(cap->oap, findc, |
| 5941 | (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, |
| 5942 | 0)) == NULL) |
| 5943 | n = 0; |
| 5944 | else |
| 5945 | curwin->w_cursor = *pos; |
| 5946 | break; |
| 5947 | } |
| 5948 | } |
| 5949 | --n; |
| 5950 | } |
| 5951 | curwin->w_cursor = old_pos; |
| 5952 | if (pos == NULL && new_pos.lnum != 0) |
| 5953 | clearopbeep(cap->oap); |
| 5954 | } |
| 5955 | if (pos != NULL) |
| 5956 | { |
| 5957 | setpcmark(); |
| 5958 | curwin->w_cursor = *pos; |
| 5959 | curwin->w_set_curswant = TRUE; |
| 5960 | #ifdef FEAT_FOLDING |
| 5961 | if ((fdo_flags & FDO_BLOCK) && KeyTyped |
| 5962 | && cap->oap->op_type == OP_NOP) |
| 5963 | foldOpenCursor(); |
| 5964 | #endif |
| 5965 | } |
| 5966 | } |
| 5967 | |
| 5968 | /* |
| 5969 | * "[[", "[]", "]]" and "][": move to start or end of function |
| 5970 | */ |
| 5971 | else if (cap->nchar == '[' || cap->nchar == ']') |
| 5972 | { |
| 5973 | if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ |
| 5974 | flag = '{'; |
| 5975 | else |
| 5976 | flag = '}'; /* "][" or "[]" */ |
| 5977 | |
| 5978 | curwin->w_set_curswant = TRUE; |
| 5979 | /* |
| 5980 | * Imitate strange Vi behaviour: When using "]]" with an operator |
| 5981 | * we also stop at '}'. |
| 5982 | */ |
| 5983 | if (!findpar(cap->oap, cap->arg, cap->count1, flag, |
| 5984 | (cap->oap->op_type != OP_NOP |
| 5985 | && cap->arg == FORWARD && flag == '{'))) |
| 5986 | clearopbeep(cap->oap); |
| 5987 | else |
| 5988 | { |
| 5989 | if (cap->oap->op_type == OP_NOP) |
| 5990 | beginline(BL_WHITE | BL_FIX); |
| 5991 | #ifdef FEAT_FOLDING |
| 5992 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 5993 | foldOpenCursor(); |
| 5994 | #endif |
| 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | /* |
| 5999 | * "[p", "[P", "]P" and "]p": put with indent adjustment |
| 6000 | */ |
| 6001 | else if (cap->nchar == 'p' || cap->nchar == 'P') |
| 6002 | { |
| 6003 | if (!checkclearopq(cap->oap)) |
| 6004 | { |
| 6005 | prep_redo_cmd(cap); |
| 6006 | do_put(cap->oap->regname, |
| 6007 | (cap->cmdchar == ']' && cap->nchar == 'p') ? FORWARD : BACKWARD, |
| 6008 | cap->count1, PUT_FIXINDENT); |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | /* |
| 6013 | * "['", "[`", "]'" and "]`": jump to next mark |
| 6014 | */ |
| 6015 | else if (cap->nchar == '\'' || cap->nchar == '`') |
| 6016 | { |
| 6017 | pos = &curwin->w_cursor; |
| 6018 | for (n = cap->count1; n > 0; --n) |
| 6019 | { |
| 6020 | prev_pos = *pos; |
| 6021 | pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, |
| 6022 | cap->nchar == '\''); |
| 6023 | if (pos == NULL) |
| 6024 | break; |
| 6025 | } |
| 6026 | if (pos == NULL) |
| 6027 | pos = &prev_pos; |
| 6028 | nv_cursormark(cap, cap->nchar == '\'', pos); |
| 6029 | } |
| 6030 | |
| 6031 | #ifdef FEAT_MOUSE |
| 6032 | /* |
| 6033 | * [ or ] followed by a middle mouse click: put selected text with |
| 6034 | * indent adjustment. Any other button just does as usual. |
| 6035 | */ |
| 6036 | else if (cap->nchar >= K_LEFTMOUSE && cap->nchar <= K_RIGHTRELEASE) |
| 6037 | { |
| 6038 | (void)do_mouse(cap->oap, cap->nchar, |
| 6039 | (cap->cmdchar == ']') ? FORWARD : BACKWARD, |
| 6040 | cap->count1, PUT_FIXINDENT); |
| 6041 | } |
| 6042 | #endif /* FEAT_MOUSE */ |
| 6043 | |
| 6044 | #ifdef FEAT_FOLDING |
| 6045 | /* |
| 6046 | * "[z" and "]z": move to start or end of open fold. |
| 6047 | */ |
| 6048 | else if (cap->nchar == 'z') |
| 6049 | { |
| 6050 | if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
| 6051 | cap->count1) == FAIL) |
| 6052 | clearopbeep(cap->oap); |
| 6053 | } |
| 6054 | #endif |
| 6055 | |
| 6056 | #ifdef FEAT_DIFF |
| 6057 | /* |
| 6058 | * "[c" and "]c": move to next or previous diff-change. |
| 6059 | */ |
| 6060 | else if (cap->nchar == 'c') |
| 6061 | { |
| 6062 | if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, |
| 6063 | cap->count1) == FAIL) |
| 6064 | clearopbeep(cap->oap); |
| 6065 | } |
| 6066 | #endif |
| 6067 | |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6068 | #ifdef FEAT_SYN_HL |
| 6069 | /* |
| 6070 | * "[s", "[S", "]s" and "]S": move to next spell error. |
| 6071 | */ |
| 6072 | else if (cap->nchar == 's' || cap->nchar == 'S') |
| 6073 | { |
Bram Moolenaar | 2cf8b30 | 2005-04-20 19:37:22 +0000 | [diff] [blame] | 6074 | setpcmark(); |
| 6075 | for (n = 0; n < cap->count1; ++n) |
| 6076 | if (spell_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6077 | cap->nchar == 's' ? TRUE : FALSE) == FAIL) |
Bram Moolenaar | 2cf8b30 | 2005-04-20 19:37:22 +0000 | [diff] [blame] | 6078 | { |
| 6079 | clearopbeep(cap->oap); |
| 6080 | break; |
| 6081 | } |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6082 | } |
| 6083 | #endif |
| 6084 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6085 | /* Not a valid cap->nchar. */ |
| 6086 | else |
| 6087 | clearopbeep(cap->oap); |
| 6088 | } |
| 6089 | |
| 6090 | /* |
| 6091 | * Handle Normal mode "%" command. |
| 6092 | */ |
| 6093 | static void |
| 6094 | nv_percent(cap) |
| 6095 | cmdarg_T *cap; |
| 6096 | { |
| 6097 | pos_T *pos; |
| 6098 | #ifdef FEAT_FOLDING |
| 6099 | linenr_T lnum = curwin->w_cursor.lnum; |
| 6100 | #endif |
| 6101 | |
| 6102 | cap->oap->inclusive = TRUE; |
| 6103 | if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ |
| 6104 | { |
| 6105 | if (cap->count0 > 100) |
| 6106 | clearopbeep(cap->oap); |
| 6107 | else |
| 6108 | { |
| 6109 | cap->oap->motion_type = MLINE; |
| 6110 | setpcmark(); |
| 6111 | /* Round up, so CTRL-G will give same value. Watch out for a |
| 6112 | * large line count, the line number must not go negative! */ |
| 6113 | if (curbuf->b_ml.ml_line_count > 1000000) |
| 6114 | curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) |
| 6115 | / 100L * cap->count0; |
| 6116 | else |
| 6117 | curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * |
| 6118 | cap->count0 + 99L) / 100L; |
| 6119 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 6120 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 6121 | beginline(BL_SOL | BL_FIX); |
| 6122 | } |
| 6123 | } |
| 6124 | else /* "%" : go to matching paren */ |
| 6125 | { |
| 6126 | cap->oap->motion_type = MCHAR; |
| 6127 | cap->oap->use_reg_one = TRUE; |
| 6128 | if ((pos = findmatch(cap->oap, NUL)) == NULL) |
| 6129 | clearopbeep(cap->oap); |
| 6130 | else |
| 6131 | { |
| 6132 | setpcmark(); |
| 6133 | curwin->w_cursor = *pos; |
| 6134 | curwin->w_set_curswant = TRUE; |
| 6135 | #ifdef FEAT_VIRTUALEDIT |
| 6136 | curwin->w_cursor.coladd = 0; |
| 6137 | #endif |
| 6138 | #ifdef FEAT_VISUAL |
| 6139 | adjust_for_sel(cap); |
| 6140 | #endif |
| 6141 | } |
| 6142 | } |
| 6143 | #ifdef FEAT_FOLDING |
| 6144 | if (cap->oap->op_type == OP_NOP |
| 6145 | && lnum != curwin->w_cursor.lnum |
| 6146 | && (fdo_flags & FDO_PERCENT) |
| 6147 | && KeyTyped) |
| 6148 | foldOpenCursor(); |
| 6149 | #endif |
| 6150 | } |
| 6151 | |
| 6152 | /* |
| 6153 | * Handle "(" and ")" commands. |
| 6154 | * cap->arg is BACKWARD for "(" and FORWARD for ")". |
| 6155 | */ |
| 6156 | static void |
| 6157 | nv_brace(cap) |
| 6158 | cmdarg_T *cap; |
| 6159 | { |
| 6160 | cap->oap->motion_type = MCHAR; |
| 6161 | cap->oap->use_reg_one = TRUE; |
| 6162 | if (cap->cmdchar == ')') |
| 6163 | cap->oap->inclusive = FALSE; |
| 6164 | else |
| 6165 | cap->oap->inclusive = TRUE; |
| 6166 | curwin->w_set_curswant = TRUE; |
| 6167 | |
| 6168 | if (findsent(cap->arg, cap->count1) == FAIL) |
| 6169 | clearopbeep(cap->oap); |
| 6170 | else |
| 6171 | { |
| 6172 | #ifdef FEAT_VIRTUALEDIT |
| 6173 | curwin->w_cursor.coladd = 0; |
| 6174 | #endif |
| 6175 | #ifdef FEAT_FOLDING |
| 6176 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6177 | foldOpenCursor(); |
| 6178 | #endif |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | /* |
| 6183 | * "m" command: Mark a position. |
| 6184 | */ |
| 6185 | static void |
| 6186 | nv_mark(cap) |
| 6187 | cmdarg_T *cap; |
| 6188 | { |
| 6189 | if (!checkclearop(cap->oap)) |
| 6190 | { |
| 6191 | if (setmark(cap->nchar) == FAIL) |
| 6192 | clearopbeep(cap->oap); |
| 6193 | } |
| 6194 | } |
| 6195 | |
| 6196 | /* |
| 6197 | * "{" and "}" commands. |
| 6198 | * cmd->arg is BACKWARD for "{" and FORWARD for "}". |
| 6199 | */ |
| 6200 | static void |
| 6201 | nv_findpar(cap) |
| 6202 | cmdarg_T *cap; |
| 6203 | { |
| 6204 | cap->oap->motion_type = MCHAR; |
| 6205 | cap->oap->inclusive = FALSE; |
| 6206 | cap->oap->use_reg_one = TRUE; |
| 6207 | curwin->w_set_curswant = TRUE; |
| 6208 | if (!findpar(cap->oap, cap->arg, cap->count1, NUL, FALSE)) |
| 6209 | clearopbeep(cap->oap); |
| 6210 | else |
| 6211 | { |
| 6212 | #ifdef FEAT_VIRTUALEDIT |
| 6213 | curwin->w_cursor.coladd = 0; |
| 6214 | #endif |
| 6215 | #ifdef FEAT_FOLDING |
| 6216 | if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 6217 | foldOpenCursor(); |
| 6218 | #endif |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | /* |
| 6223 | * "u" command: Undo or make lower case. |
| 6224 | */ |
| 6225 | static void |
| 6226 | nv_undo(cap) |
| 6227 | cmdarg_T *cap; |
| 6228 | { |
| 6229 | if (cap->oap->op_type == OP_LOWER |
| 6230 | #ifdef FEAT_VISUAL |
| 6231 | || VIsual_active |
| 6232 | #endif |
| 6233 | ) |
| 6234 | { |
| 6235 | /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ |
| 6236 | cap->cmdchar = 'g'; |
| 6237 | cap->nchar = 'u'; |
| 6238 | nv_operator(cap); |
| 6239 | } |
| 6240 | else |
| 6241 | nv_kundo(cap); |
| 6242 | } |
| 6243 | |
| 6244 | /* |
| 6245 | * <Undo> command. |
| 6246 | */ |
| 6247 | static void |
| 6248 | nv_kundo(cap) |
| 6249 | cmdarg_T *cap; |
| 6250 | { |
| 6251 | if (!checkclearopq(cap->oap)) |
| 6252 | { |
| 6253 | u_undo((int)cap->count1); |
| 6254 | curwin->w_set_curswant = TRUE; |
| 6255 | } |
| 6256 | } |
| 6257 | |
| 6258 | /* |
| 6259 | * Handle the "r" command. |
| 6260 | */ |
| 6261 | static void |
| 6262 | nv_replace(cap) |
| 6263 | cmdarg_T *cap; |
| 6264 | { |
| 6265 | char_u *ptr; |
| 6266 | int had_ctrl_v; |
| 6267 | long n; |
| 6268 | |
| 6269 | if (checkclearop(cap->oap)) |
| 6270 | return; |
| 6271 | |
| 6272 | /* get another character */ |
| 6273 | if (cap->nchar == Ctrl_V) |
| 6274 | { |
| 6275 | had_ctrl_v = Ctrl_V; |
| 6276 | cap->nchar = get_literal(); |
| 6277 | /* Don't redo a multibyte character with CTRL-V. */ |
| 6278 | if (cap->nchar > DEL) |
| 6279 | had_ctrl_v = NUL; |
| 6280 | } |
| 6281 | else |
| 6282 | had_ctrl_v = NUL; |
| 6283 | |
| 6284 | #ifdef FEAT_VISUAL |
| 6285 | /* Visual mode "r" */ |
| 6286 | if (VIsual_active) |
| 6287 | { |
| 6288 | nv_operator(cap); |
| 6289 | return; |
| 6290 | } |
| 6291 | #endif |
| 6292 | |
| 6293 | #ifdef FEAT_VIRTUALEDIT |
| 6294 | /* Break tabs, etc. */ |
| 6295 | if (virtual_active()) |
| 6296 | { |
| 6297 | if (u_save_cursor() == FAIL) |
| 6298 | return; |
| 6299 | if (gchar_cursor() == NUL) |
| 6300 | { |
| 6301 | /* Add extra space and put the cursor on the first one. */ |
| 6302 | coladvance_force((colnr_T)(getviscol() + cap->count1)); |
| 6303 | curwin->w_cursor.col -= cap->count1; |
| 6304 | } |
| 6305 | else if (gchar_cursor() == TAB) |
| 6306 | coladvance_force(getviscol()); |
| 6307 | } |
| 6308 | #endif |
| 6309 | |
| 6310 | /* |
| 6311 | * Check for a special key or not enough characters to replace. |
| 6312 | */ |
| 6313 | ptr = ml_get_cursor(); |
| 6314 | if (IS_SPECIAL(cap->nchar) || STRLEN(ptr) < (unsigned)cap->count1 |
| 6315 | #ifdef FEAT_MBYTE |
| 6316 | || (has_mbyte && mb_charlen(ptr) < cap->count1) |
| 6317 | #endif |
| 6318 | ) |
| 6319 | { |
| 6320 | clearopbeep(cap->oap); |
| 6321 | return; |
| 6322 | } |
| 6323 | |
| 6324 | /* |
| 6325 | * Replacing with a TAB is done by edit() when it is complicated because |
| 6326 | * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. |
| 6327 | * Other characters are done below to avoid problems with things like |
| 6328 | * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). |
| 6329 | */ |
| 6330 | if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) |
| 6331 | { |
| 6332 | stuffnumReadbuff(cap->count1); |
| 6333 | stuffcharReadbuff('R'); |
| 6334 | stuffcharReadbuff('\t'); |
| 6335 | stuffcharReadbuff(ESC); |
| 6336 | return; |
| 6337 | } |
| 6338 | |
| 6339 | /* save line for undo */ |
| 6340 | if (u_save_cursor() == FAIL) |
| 6341 | return; |
| 6342 | |
| 6343 | if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) |
| 6344 | { |
| 6345 | /* |
| 6346 | * Replace character(s) by a single newline. |
| 6347 | * Strange vi behaviour: Only one newline is inserted. |
| 6348 | * Delete the characters here. |
| 6349 | * Insert the newline with an insert command, takes care of |
| 6350 | * autoindent. The insert command depends on being on the last |
| 6351 | * character of a line or not. |
| 6352 | */ |
| 6353 | #ifdef FEAT_MBYTE |
| 6354 | (void)del_chars(cap->count1, FALSE); /* delete the characters */ |
| 6355 | #else |
| 6356 | (void)del_bytes(cap->count1, FALSE); /* delete the characters */ |
| 6357 | #endif |
| 6358 | stuffcharReadbuff('\r'); |
| 6359 | stuffcharReadbuff(ESC); |
| 6360 | |
| 6361 | /* Give 'r' to edit(), to get the redo command right. */ |
| 6362 | invoke_edit(cap, TRUE, 'r', FALSE); |
| 6363 | } |
| 6364 | else |
| 6365 | { |
| 6366 | prep_redo(cap->oap->regname, cap->count1, |
| 6367 | NUL, 'r', NUL, had_ctrl_v, cap->nchar); |
| 6368 | |
| 6369 | curbuf->b_op_start = curwin->w_cursor; |
| 6370 | #ifdef FEAT_MBYTE |
| 6371 | if (has_mbyte) |
| 6372 | { |
| 6373 | int old_State = State; |
| 6374 | |
| 6375 | if (cap->ncharC1 != 0) |
| 6376 | AppendCharToRedobuff(cap->ncharC1); |
| 6377 | if (cap->ncharC2 != 0) |
| 6378 | AppendCharToRedobuff(cap->ncharC2); |
| 6379 | |
| 6380 | /* This is slow, but it handles replacing a single-byte with a |
| 6381 | * multi-byte and the other way around. Also handles adding |
| 6382 | * composing characters for utf-8. */ |
| 6383 | for (n = cap->count1; n > 0; --n) |
| 6384 | { |
| 6385 | State = REPLACE; |
| 6386 | ins_char(cap->nchar); |
| 6387 | State = old_State; |
| 6388 | if (cap->ncharC1 != 0) |
| 6389 | ins_char(cap->ncharC1); |
| 6390 | if (cap->ncharC2 != 0) |
| 6391 | ins_char(cap->ncharC2); |
| 6392 | } |
| 6393 | } |
| 6394 | else |
| 6395 | #endif |
| 6396 | { |
| 6397 | /* |
| 6398 | * Replace the characters within one line. |
| 6399 | */ |
| 6400 | for (n = cap->count1; n > 0; --n) |
| 6401 | { |
| 6402 | /* |
| 6403 | * Get ptr again, because u_save and/or showmatch() will have |
| 6404 | * released the line. At the same time we let know that the |
| 6405 | * line will be changed. |
| 6406 | */ |
| 6407 | ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
| 6408 | ptr[curwin->w_cursor.col] = cap->nchar; |
| 6409 | if (p_sm && msg_silent == 0) |
| 6410 | showmatch(cap->nchar); |
| 6411 | ++curwin->w_cursor.col; |
| 6412 | } |
| 6413 | #ifdef FEAT_NETBEANS_INTG |
| 6414 | if (usingNetbeans) |
| 6415 | { |
| 6416 | colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
| 6417 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 6418 | netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
| 6419 | (long)cap->count1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6420 | netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 6421 | &ptr[start], (int)cap->count1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6422 | } |
| 6423 | #endif |
| 6424 | |
| 6425 | /* mark the buffer as changed and prepare for displaying */ |
| 6426 | changed_bytes(curwin->w_cursor.lnum, |
| 6427 | (colnr_T)(curwin->w_cursor.col - cap->count1)); |
| 6428 | } |
| 6429 | --curwin->w_cursor.col; /* cursor on the last replaced char */ |
| 6430 | #ifdef FEAT_MBYTE |
| 6431 | /* if the character on the left of the current cursor is a multi-byte |
| 6432 | * character, move two characters left */ |
| 6433 | if (has_mbyte) |
| 6434 | mb_adjust_cursor(); |
| 6435 | #endif |
| 6436 | curbuf->b_op_end = curwin->w_cursor; |
| 6437 | curwin->w_set_curswant = TRUE; |
| 6438 | set_last_insert(cap->nchar); |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | #ifdef FEAT_VISUAL |
| 6443 | /* |
| 6444 | * 'o': Exchange start and end of Visual area. |
| 6445 | * 'O': same, but in block mode exchange left and right corners. |
| 6446 | */ |
| 6447 | static void |
| 6448 | v_swap_corners(cmdchar) |
| 6449 | int cmdchar; |
| 6450 | { |
| 6451 | pos_T old_cursor; |
| 6452 | colnr_T left, right; |
| 6453 | |
| 6454 | if (cmdchar == 'O' && VIsual_mode == Ctrl_V) |
| 6455 | { |
| 6456 | old_cursor = curwin->w_cursor; |
| 6457 | getvcols(curwin, &old_cursor, &VIsual, &left, &right); |
| 6458 | curwin->w_cursor.lnum = VIsual.lnum; |
| 6459 | coladvance(left); |
| 6460 | VIsual = curwin->w_cursor; |
| 6461 | |
| 6462 | curwin->w_cursor.lnum = old_cursor.lnum; |
| 6463 | curwin->w_curswant = right; |
| 6464 | /* 'selection "exclusive" and cursor at right-bottom corner: move it |
| 6465 | * right one column */ |
| 6466 | if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') |
| 6467 | ++curwin->w_curswant; |
| 6468 | coladvance(curwin->w_curswant); |
| 6469 | if (curwin->w_cursor.col == old_cursor.col |
| 6470 | #ifdef FEAT_VIRTUALEDIT |
| 6471 | && (!virtual_active() |
| 6472 | || curwin->w_cursor.coladd == old_cursor.coladd) |
| 6473 | #endif |
| 6474 | ) |
| 6475 | { |
| 6476 | curwin->w_cursor.lnum = VIsual.lnum; |
| 6477 | if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') |
| 6478 | ++right; |
| 6479 | coladvance(right); |
| 6480 | VIsual = curwin->w_cursor; |
| 6481 | |
| 6482 | curwin->w_cursor.lnum = old_cursor.lnum; |
| 6483 | coladvance(left); |
| 6484 | curwin->w_curswant = left; |
| 6485 | } |
| 6486 | } |
| 6487 | else |
| 6488 | { |
| 6489 | old_cursor = curwin->w_cursor; |
| 6490 | curwin->w_cursor = VIsual; |
| 6491 | VIsual = old_cursor; |
| 6492 | curwin->w_set_curswant = TRUE; |
| 6493 | } |
| 6494 | } |
| 6495 | #endif /* FEAT_VISUAL */ |
| 6496 | |
| 6497 | /* |
| 6498 | * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). |
| 6499 | */ |
| 6500 | static void |
| 6501 | nv_Replace(cap) |
| 6502 | cmdarg_T *cap; |
| 6503 | { |
| 6504 | #ifdef FEAT_VISUAL |
| 6505 | if (VIsual_active) /* "R" is replace lines */ |
| 6506 | { |
| 6507 | cap->cmdchar = 'c'; |
| 6508 | cap->nchar = NUL; |
| 6509 | VIsual_mode = 'V'; |
| 6510 | nv_operator(cap); |
| 6511 | } |
| 6512 | else |
| 6513 | #endif |
| 6514 | if (!checkclearopq(cap->oap)) |
| 6515 | { |
| 6516 | if (!curbuf->b_p_ma) |
| 6517 | EMSG(_(e_modifiable)); |
| 6518 | else |
| 6519 | { |
| 6520 | #ifdef FEAT_VIRTUALEDIT |
| 6521 | if (virtual_active()) |
| 6522 | coladvance(getviscol()); |
| 6523 | #endif |
| 6524 | invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); |
| 6525 | } |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | #ifdef FEAT_VREPLACE |
| 6530 | /* |
| 6531 | * "gr". |
| 6532 | */ |
| 6533 | static void |
| 6534 | nv_vreplace(cap) |
| 6535 | cmdarg_T *cap; |
| 6536 | { |
| 6537 | # ifdef FEAT_VISUAL |
| 6538 | if (VIsual_active) |
| 6539 | { |
| 6540 | cap->cmdchar = 'r'; |
| 6541 | cap->nchar = cap->extra_char; |
| 6542 | nv_replace(cap); /* Do same as "r" in Visual mode for now */ |
| 6543 | } |
| 6544 | else |
| 6545 | # endif |
| 6546 | if (!checkclearopq(cap->oap)) |
| 6547 | { |
| 6548 | if (!curbuf->b_p_ma) |
| 6549 | EMSG(_(e_modifiable)); |
| 6550 | else |
| 6551 | { |
| 6552 | if (cap->extra_char == Ctrl_V) /* get another character */ |
| 6553 | cap->extra_char = get_literal(); |
| 6554 | stuffcharReadbuff(cap->extra_char); |
| 6555 | stuffcharReadbuff(ESC); |
| 6556 | # ifdef FEAT_VIRTUALEDIT |
| 6557 | if (virtual_active()) |
| 6558 | coladvance(getviscol()); |
| 6559 | # endif |
| 6560 | invoke_edit(cap, TRUE, 'v', FALSE); |
| 6561 | } |
| 6562 | } |
| 6563 | } |
| 6564 | #endif |
| 6565 | |
| 6566 | /* |
| 6567 | * Swap case for "~" command, when it does not work like an operator. |
| 6568 | */ |
| 6569 | static void |
| 6570 | n_swapchar(cap) |
| 6571 | cmdarg_T *cap; |
| 6572 | { |
| 6573 | long n; |
| 6574 | pos_T startpos; |
| 6575 | int did_change = 0; |
| 6576 | #ifdef FEAT_NETBEANS_INTG |
| 6577 | pos_T pos; |
| 6578 | char_u *ptr; |
| 6579 | int count; |
| 6580 | #endif |
| 6581 | |
| 6582 | if (checkclearopq(cap->oap)) |
| 6583 | return; |
| 6584 | |
| 6585 | if (lineempty(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
| 6586 | { |
| 6587 | clearopbeep(cap->oap); |
| 6588 | return; |
| 6589 | } |
| 6590 | |
| 6591 | prep_redo_cmd(cap); |
| 6592 | |
| 6593 | if (u_save_cursor() == FAIL) |
| 6594 | return; |
| 6595 | |
| 6596 | startpos = curwin->w_cursor; |
| 6597 | #ifdef FEAT_NETBEANS_INTG |
| 6598 | pos = startpos; |
| 6599 | #endif |
| 6600 | for (n = cap->count1; n > 0; --n) |
| 6601 | { |
| 6602 | did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); |
| 6603 | inc_cursor(); |
| 6604 | if (gchar_cursor() == NUL) |
| 6605 | { |
| 6606 | if (vim_strchr(p_ww, '~') != NULL |
| 6607 | && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
| 6608 | { |
| 6609 | #ifdef FEAT_NETBEANS_INTG |
| 6610 | if (usingNetbeans) |
| 6611 | { |
| 6612 | if (did_change) |
| 6613 | { |
| 6614 | ptr = ml_get(pos.lnum); |
| 6615 | count = STRLEN(ptr) - pos.col; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 6616 | netbeans_removed(curbuf, pos.lnum, pos.col, |
| 6617 | (long)count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6618 | netbeans_inserted(curbuf, pos.lnum, pos.col, |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 6619 | &ptr[pos.col], count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6620 | } |
| 6621 | pos.col = 0; |
| 6622 | pos.lnum++; |
| 6623 | } |
| 6624 | #endif |
| 6625 | ++curwin->w_cursor.lnum; |
| 6626 | curwin->w_cursor.col = 0; |
| 6627 | if (n > 1) |
| 6628 | { |
| 6629 | if (u_savesub(curwin->w_cursor.lnum) == FAIL) |
| 6630 | break; |
| 6631 | u_clearline(); |
| 6632 | } |
| 6633 | } |
| 6634 | else |
| 6635 | break; |
| 6636 | } |
| 6637 | } |
| 6638 | #ifdef FEAT_NETBEANS_INTG |
| 6639 | if (did_change && usingNetbeans) |
| 6640 | { |
| 6641 | ptr = ml_get(pos.lnum); |
| 6642 | count = curwin->w_cursor.col - pos.col; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 6643 | netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
| 6644 | netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6645 | } |
| 6646 | #endif |
| 6647 | |
| 6648 | |
| 6649 | check_cursor(); |
| 6650 | curwin->w_set_curswant = TRUE; |
| 6651 | if (did_change) |
| 6652 | { |
| 6653 | changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, |
| 6654 | 0L); |
| 6655 | curbuf->b_op_start = startpos; |
| 6656 | curbuf->b_op_end = curwin->w_cursor; |
| 6657 | if (curbuf->b_op_end.col > 0) |
| 6658 | --curbuf->b_op_end.col; |
| 6659 | } |
| 6660 | } |
| 6661 | |
| 6662 | /* |
| 6663 | * Move cursor to mark. |
| 6664 | */ |
| 6665 | static void |
| 6666 | nv_cursormark(cap, flag, pos) |
| 6667 | cmdarg_T *cap; |
| 6668 | int flag; |
| 6669 | pos_T *pos; |
| 6670 | { |
| 6671 | if (check_mark(pos) == FAIL) |
| 6672 | clearop(cap->oap); |
| 6673 | else |
| 6674 | { |
| 6675 | if (cap->cmdchar == '\'' |
| 6676 | || cap->cmdchar == '`' |
| 6677 | || cap->cmdchar == '[' |
| 6678 | || cap->cmdchar == ']') |
| 6679 | setpcmark(); |
| 6680 | curwin->w_cursor = *pos; |
| 6681 | if (flag) |
| 6682 | beginline(BL_WHITE | BL_FIX); |
| 6683 | else |
| 6684 | check_cursor(); |
| 6685 | } |
| 6686 | cap->oap->motion_type = flag ? MLINE : MCHAR; |
| 6687 | if (cap->cmdchar == '`') |
| 6688 | cap->oap->use_reg_one = TRUE; |
| 6689 | cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ |
| 6690 | curwin->w_set_curswant = TRUE; |
| 6691 | } |
| 6692 | |
| 6693 | #ifdef FEAT_VISUAL |
| 6694 | /* |
| 6695 | * Handle commands that are operators in Visual mode. |
| 6696 | */ |
| 6697 | static void |
| 6698 | v_visop(cap) |
| 6699 | cmdarg_T *cap; |
| 6700 | { |
| 6701 | static char_u trans[] = "YyDdCcxdXdAAIIrr"; |
| 6702 | |
| 6703 | /* Uppercase means linewise, except in block mode, then "D" deletes till |
| 6704 | * the end of the line, and "C" replaces til EOL */ |
| 6705 | if (isupper(cap->cmdchar)) |
| 6706 | { |
| 6707 | if (VIsual_mode != Ctrl_V) |
| 6708 | VIsual_mode = 'V'; |
| 6709 | else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
| 6710 | curwin->w_curswant = MAXCOL; |
| 6711 | } |
| 6712 | cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); |
| 6713 | nv_operator(cap); |
| 6714 | } |
| 6715 | #endif |
| 6716 | |
| 6717 | /* |
| 6718 | * "s" and "S" commands. |
| 6719 | */ |
| 6720 | static void |
| 6721 | nv_subst(cap) |
| 6722 | cmdarg_T *cap; |
| 6723 | { |
| 6724 | #ifdef FEAT_VISUAL |
| 6725 | if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
| 6726 | { |
| 6727 | if (cap->cmdchar == 'S') |
| 6728 | VIsual_mode = 'V'; |
| 6729 | cap->cmdchar = 'c'; |
| 6730 | nv_operator(cap); |
| 6731 | } |
| 6732 | else |
| 6733 | #endif |
| 6734 | nv_optrans(cap); |
| 6735 | } |
| 6736 | |
| 6737 | /* |
| 6738 | * Abbreviated commands. |
| 6739 | */ |
| 6740 | static void |
| 6741 | nv_abbrev(cap) |
| 6742 | cmdarg_T *cap; |
| 6743 | { |
| 6744 | if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) |
| 6745 | cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ |
| 6746 | |
| 6747 | #ifdef FEAT_VISUAL |
| 6748 | /* in Visual mode these commands are operators */ |
| 6749 | if (VIsual_active) |
| 6750 | v_visop(cap); |
| 6751 | else |
| 6752 | #endif |
| 6753 | nv_optrans(cap); |
| 6754 | } |
| 6755 | |
| 6756 | /* |
| 6757 | * Translate a command into another command. |
| 6758 | */ |
| 6759 | static void |
| 6760 | nv_optrans(cap) |
| 6761 | cmdarg_T *cap; |
| 6762 | { |
| 6763 | static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", |
| 6764 | (char_u *)"d$", (char_u *)"c$", |
| 6765 | (char_u *)"cl", (char_u *)"cc", |
| 6766 | (char_u *)"yy", (char_u *)":s\r"}; |
| 6767 | static char_u *str = (char_u *)"xXDCsSY&"; |
| 6768 | |
| 6769 | if (!checkclearopq(cap->oap)) |
| 6770 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 6771 | /* In Vi "2D" doesn't delete the next line. Can't translate it |
| 6772 | * either, because "2." should also not use the count. */ |
| 6773 | if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
| 6774 | { |
| 6775 | cap->oap->start = curwin->w_cursor; |
| 6776 | cap->oap->op_type = OP_DELETE; |
| 6777 | cap->count1 = 1; |
| 6778 | nv_dollar(cap); |
| 6779 | finish_op = TRUE; |
| 6780 | ResetRedobuff(); |
| 6781 | AppendCharToRedobuff('D'); |
| 6782 | } |
| 6783 | else |
| 6784 | { |
| 6785 | if (cap->count0) |
| 6786 | stuffnumReadbuff(cap->count0); |
| 6787 | stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
| 6788 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6789 | } |
| 6790 | cap->opcount = 0; |
| 6791 | } |
| 6792 | |
| 6793 | /* |
| 6794 | * "'" and "`" commands. Also for "g'" and "g`". |
| 6795 | * cap->arg is TRUE for "'" and "g'". |
| 6796 | */ |
| 6797 | static void |
| 6798 | nv_gomark(cap) |
| 6799 | cmdarg_T *cap; |
| 6800 | { |
| 6801 | pos_T *pos; |
| 6802 | int c; |
| 6803 | #ifdef FEAT_FOLDING |
| 6804 | linenr_T lnum = curwin->w_cursor.lnum; |
| 6805 | int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
| 6806 | #endif |
| 6807 | |
| 6808 | if (cap->cmdchar == 'g') |
| 6809 | c = cap->extra_char; |
| 6810 | else |
| 6811 | c = cap->nchar; |
| 6812 | pos = getmark(c, (cap->oap->op_type == OP_NOP)); |
| 6813 | if (pos == (pos_T *)-1) /* jumped to other file */ |
| 6814 | { |
| 6815 | if (cap->arg) |
| 6816 | { |
| 6817 | check_cursor_lnum(); |
| 6818 | beginline(BL_WHITE | BL_FIX); |
| 6819 | } |
| 6820 | else |
| 6821 | check_cursor(); |
| 6822 | } |
| 6823 | else |
| 6824 | nv_cursormark(cap, cap->arg, pos); |
| 6825 | |
| 6826 | #ifdef FEAT_VIRTUALEDIT |
| 6827 | /* May need to clear the coladd that a mark includes. */ |
| 6828 | if (!virtual_active()) |
| 6829 | curwin->w_cursor.coladd = 0; |
| 6830 | #endif |
| 6831 | #ifdef FEAT_FOLDING |
| 6832 | if (cap->oap->op_type == OP_NOP |
| 6833 | && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) |
| 6834 | && (fdo_flags & FDO_MARK) |
| 6835 | && old_KeyTyped) |
| 6836 | foldOpenCursor(); |
| 6837 | #endif |
| 6838 | } |
| 6839 | |
| 6840 | /* |
| 6841 | * Handle CTRL-O, CTRL-I, "g;" and "g," commands. |
| 6842 | */ |
| 6843 | static void |
| 6844 | nv_pcmark(cap) |
| 6845 | cmdarg_T *cap; |
| 6846 | { |
| 6847 | #ifdef FEAT_JUMPLIST |
| 6848 | pos_T *pos; |
| 6849 | # ifdef FEAT_FOLDING |
| 6850 | linenr_T lnum = curwin->w_cursor.lnum; |
| 6851 | int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
| 6852 | # endif |
| 6853 | |
| 6854 | if (!checkclearopq(cap->oap)) |
| 6855 | { |
| 6856 | if (cap->cmdchar == 'g') |
| 6857 | pos = movechangelist((int)cap->count1); |
| 6858 | else |
| 6859 | pos = movemark((int)cap->count1); |
| 6860 | if (pos == (pos_T *)-1) /* jump to other file */ |
| 6861 | { |
| 6862 | curwin->w_set_curswant = TRUE; |
| 6863 | check_cursor(); |
| 6864 | } |
| 6865 | else if (pos != NULL) /* can jump */ |
| 6866 | nv_cursormark(cap, FALSE, pos); |
| 6867 | else if (cap->cmdchar == 'g') |
| 6868 | { |
| 6869 | if (curbuf->b_changelistlen == 0) |
| 6870 | EMSG(_("E664: changelist is empty")); |
| 6871 | else if (cap->count1 < 0) |
| 6872 | EMSG(_("E662: At start of changelist")); |
| 6873 | else |
| 6874 | EMSG(_("E663: At end of changelist")); |
| 6875 | } |
| 6876 | else |
| 6877 | clearopbeep(cap->oap); |
| 6878 | # ifdef FEAT_FOLDING |
| 6879 | if (cap->oap->op_type == OP_NOP |
| 6880 | && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) |
| 6881 | && (fdo_flags & FDO_MARK) |
| 6882 | && old_KeyTyped) |
| 6883 | foldOpenCursor(); |
| 6884 | # endif |
| 6885 | } |
| 6886 | #else |
| 6887 | clearopbeep(cap->oap); |
| 6888 | #endif |
| 6889 | } |
| 6890 | |
| 6891 | /* |
| 6892 | * Handle '"' command. |
| 6893 | */ |
| 6894 | static void |
| 6895 | nv_regname(cap) |
| 6896 | cmdarg_T *cap; |
| 6897 | { |
| 6898 | if (checkclearop(cap->oap)) |
| 6899 | return; |
| 6900 | #ifdef FEAT_EVAL |
| 6901 | if (cap->nchar == '=') |
| 6902 | cap->nchar = get_expr_register(); |
| 6903 | #endif |
| 6904 | if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) |
| 6905 | { |
| 6906 | cap->oap->regname = cap->nchar; |
| 6907 | cap->opcount = cap->count0; /* remember count before '"' */ |
| 6908 | #ifdef FEAT_EVAL |
| 6909 | set_reg_var(cap->oap->regname); |
| 6910 | #endif |
| 6911 | } |
| 6912 | else |
| 6913 | clearopbeep(cap->oap); |
| 6914 | } |
| 6915 | |
| 6916 | #ifdef FEAT_VISUAL |
| 6917 | /* |
| 6918 | * Handle "v", "V" and "CTRL-V" commands. |
| 6919 | * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg |
| 6920 | * is TRUE. |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 6921 | * Handle CTRL-Q just like CTRL-V. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6922 | */ |
| 6923 | static void |
| 6924 | nv_visual(cap) |
| 6925 | cmdarg_T *cap; |
| 6926 | { |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 6927 | if (cap->cmdchar == Ctrl_Q) |
| 6928 | cap->cmdchar = Ctrl_V; |
| 6929 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6930 | /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
| 6931 | * characterwise, linewise, or blockwise. */ |
| 6932 | if (cap->oap->op_type != OP_NOP) |
| 6933 | { |
| 6934 | cap->oap->motion_force = cap->cmdchar; |
| 6935 | finish_op = FALSE; /* operator doesn't finish now but later */ |
| 6936 | return; |
| 6937 | } |
| 6938 | |
| 6939 | VIsual_select = cap->arg; |
| 6940 | if (VIsual_active) /* change Visual mode */ |
| 6941 | { |
| 6942 | if (VIsual_mode == cap->cmdchar) /* stop visual mode */ |
| 6943 | end_visual_mode(); |
| 6944 | else /* toggle char/block mode */ |
| 6945 | { /* or char/line mode */ |
| 6946 | VIsual_mode = cap->cmdchar; |
| 6947 | showmode(); |
| 6948 | } |
| 6949 | redraw_curbuf_later(INVERTED); /* update the inversion */ |
| 6950 | } |
| 6951 | else /* start Visual mode */ |
| 6952 | { |
| 6953 | check_visual_highlight(); |
| 6954 | if (cap->count0) /* use previously selected part */ |
| 6955 | { |
| 6956 | if (resel_VIsual_mode == NUL) /* there is none */ |
| 6957 | { |
| 6958 | beep_flush(); |
| 6959 | return; |
| 6960 | } |
| 6961 | VIsual = curwin->w_cursor; |
| 6962 | |
| 6963 | VIsual_active = TRUE; |
| 6964 | VIsual_reselect = TRUE; |
| 6965 | if (!cap->arg) |
| 6966 | /* start Select mode when 'selectmode' contains "cmd" */ |
| 6967 | may_start_select('c'); |
| 6968 | #ifdef FEAT_MOUSE |
| 6969 | setmouse(); |
| 6970 | #endif |
| 6971 | if (p_smd) |
| 6972 | redraw_cmdline = TRUE; /* show visual mode later */ |
| 6973 | /* |
| 6974 | * For V and ^V, we multiply the number of lines even if there |
| 6975 | * was only one -- webb |
| 6976 | */ |
| 6977 | if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) |
| 6978 | { |
| 6979 | curwin->w_cursor.lnum += |
| 6980 | resel_VIsual_line_count * cap->count0 - 1; |
| 6981 | if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
| 6982 | curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
| 6983 | } |
| 6984 | VIsual_mode = resel_VIsual_mode; |
| 6985 | if (VIsual_mode == 'v') |
| 6986 | { |
| 6987 | if (resel_VIsual_line_count <= 1) |
| 6988 | curwin->w_cursor.col += resel_VIsual_col * cap->count0 - 1; |
| 6989 | else |
| 6990 | curwin->w_cursor.col = resel_VIsual_col; |
| 6991 | check_cursor_col(); |
| 6992 | } |
| 6993 | if (resel_VIsual_col == MAXCOL) |
| 6994 | { |
| 6995 | curwin->w_curswant = MAXCOL; |
| 6996 | coladvance((colnr_T)MAXCOL); |
| 6997 | } |
| 6998 | else if (VIsual_mode == Ctrl_V) |
| 6999 | { |
| 7000 | validate_virtcol(); |
| 7001 | curwin->w_curswant = curwin->w_virtcol |
| 7002 | + resel_VIsual_col * cap->count0 - 1; |
| 7003 | coladvance(curwin->w_curswant); |
| 7004 | } |
| 7005 | else |
| 7006 | curwin->w_set_curswant = TRUE; |
| 7007 | redraw_curbuf_later(INVERTED); /* show the inversion */ |
| 7008 | } |
| 7009 | else |
| 7010 | { |
| 7011 | if (!cap->arg) |
| 7012 | /* start Select mode when 'selectmode' contains "cmd" */ |
| 7013 | may_start_select('c'); |
| 7014 | n_start_visual_mode(cap->cmdchar); |
| 7015 | } |
| 7016 | } |
| 7017 | } |
| 7018 | |
| 7019 | /* |
| 7020 | * Start selection for Shift-movement keys. |
| 7021 | */ |
| 7022 | void |
| 7023 | start_selection() |
| 7024 | { |
| 7025 | /* if 'selectmode' contains "key", start Select mode */ |
| 7026 | may_start_select('k'); |
| 7027 | n_start_visual_mode('v'); |
| 7028 | } |
| 7029 | |
| 7030 | /* |
| 7031 | * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. |
| 7032 | */ |
| 7033 | void |
| 7034 | may_start_select(c) |
| 7035 | int c; |
| 7036 | { |
| 7037 | VIsual_select = (stuff_empty() && typebuf_typed() |
| 7038 | && (vim_strchr(p_slm, c) != NULL)); |
| 7039 | } |
| 7040 | |
| 7041 | /* |
| 7042 | * Start Visual mode "c". |
| 7043 | * Should set VIsual_select before calling this. |
| 7044 | */ |
| 7045 | static void |
| 7046 | n_start_visual_mode(c) |
| 7047 | int c; |
| 7048 | { |
| 7049 | VIsual_mode = c; |
| 7050 | VIsual_active = TRUE; |
| 7051 | VIsual_reselect = TRUE; |
| 7052 | #ifdef FEAT_VIRTUALEDIT |
| 7053 | /* Corner case: the 0 position in a tab may change when going into |
| 7054 | * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
| 7055 | */ |
| 7056 | if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
| 7057 | coladvance(curwin->w_virtcol); |
| 7058 | #endif |
| 7059 | VIsual = curwin->w_cursor; |
| 7060 | |
| 7061 | #ifdef FEAT_FOLDING |
| 7062 | foldAdjustVisual(); |
| 7063 | #endif |
| 7064 | |
| 7065 | #ifdef FEAT_MOUSE |
| 7066 | setmouse(); |
| 7067 | #endif |
| 7068 | if (p_smd) |
| 7069 | redraw_cmdline = TRUE; /* show visual mode later */ |
| 7070 | #ifdef FEAT_CLIPBOARD |
| 7071 | /* Make sure the clipboard gets updated. Needed because start and |
| 7072 | * end may still be the same, and the selection needs to be owned */ |
| 7073 | clip_star.vmode = NUL; |
| 7074 | #endif |
| 7075 | |
| 7076 | /* Only need to redraw this line, unless still need to redraw an old |
| 7077 | * Visual area (when 'lazyredraw' is set). */ |
| 7078 | if (curwin->w_redr_type < INVERTED) |
| 7079 | { |
| 7080 | curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 7081 | curwin->w_old_visual_lnum = curwin->w_cursor.lnum; |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | #endif /* FEAT_VISUAL */ |
| 7086 | |
| 7087 | /* |
| 7088 | * CTRL-W: Window commands |
| 7089 | */ |
| 7090 | static void |
| 7091 | nv_window(cap) |
| 7092 | cmdarg_T *cap; |
| 7093 | { |
| 7094 | #ifdef FEAT_WINDOWS |
| 7095 | if (!checkclearop(cap->oap)) |
| 7096 | do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
| 7097 | #else |
| 7098 | (void)checkclearop(cap->oap); |
| 7099 | #endif |
| 7100 | } |
| 7101 | |
| 7102 | /* |
| 7103 | * CTRL-Z: Suspend |
| 7104 | */ |
| 7105 | static void |
| 7106 | nv_suspend(cap) |
| 7107 | cmdarg_T *cap; |
| 7108 | { |
| 7109 | clearop(cap->oap); |
| 7110 | #ifdef FEAT_VISUAL |
| 7111 | if (VIsual_active) |
| 7112 | end_visual_mode(); /* stop Visual mode */ |
| 7113 | #endif |
| 7114 | do_cmdline_cmd((char_u *)"st"); |
| 7115 | } |
| 7116 | |
| 7117 | /* |
| 7118 | * Commands starting with "g". |
| 7119 | */ |
| 7120 | static void |
| 7121 | nv_g_cmd(cap) |
| 7122 | cmdarg_T *cap; |
| 7123 | { |
| 7124 | oparg_T *oap = cap->oap; |
| 7125 | #ifdef FEAT_VISUAL |
| 7126 | pos_T tpos; |
| 7127 | #endif |
| 7128 | int i; |
| 7129 | int flag = FALSE; |
| 7130 | |
| 7131 | switch (cap->nchar) |
| 7132 | { |
| 7133 | #ifdef MEM_PROFILE |
| 7134 | /* |
| 7135 | * "g^A": dump log of used memory. |
| 7136 | */ |
| 7137 | case Ctrl_A: |
| 7138 | vim_mem_profile_dump(); |
| 7139 | break; |
| 7140 | #endif |
| 7141 | |
| 7142 | #ifdef FEAT_VREPLACE |
| 7143 | /* |
| 7144 | * "gR": Enter virtual replace mode. |
| 7145 | */ |
| 7146 | case 'R': |
| 7147 | cap->arg = TRUE; |
| 7148 | nv_Replace(cap); |
| 7149 | break; |
| 7150 | |
| 7151 | case 'r': |
| 7152 | nv_vreplace(cap); |
| 7153 | break; |
| 7154 | #endif |
| 7155 | |
| 7156 | case '&': |
| 7157 | do_cmdline_cmd((char_u *)"%s//~/&"); |
| 7158 | break; |
| 7159 | |
| 7160 | #ifdef FEAT_VISUAL |
| 7161 | /* |
| 7162 | * "gv": Reselect the previous Visual area. If Visual already active, |
| 7163 | * exchange previous and current Visual area. |
| 7164 | */ |
| 7165 | case 'v': |
| 7166 | if (checkclearop(oap)) |
| 7167 | break; |
| 7168 | |
| 7169 | if ( curbuf->b_visual_start.lnum == 0 |
| 7170 | || curbuf->b_visual_start.lnum > curbuf->b_ml.ml_line_count |
| 7171 | || curbuf->b_visual_end.lnum == 0) |
| 7172 | beep_flush(); |
| 7173 | else |
| 7174 | { |
| 7175 | /* set w_cursor to the start of the Visual area, tpos to the end */ |
| 7176 | if (VIsual_active) |
| 7177 | { |
| 7178 | i = VIsual_mode; |
| 7179 | VIsual_mode = curbuf->b_visual_mode; |
| 7180 | curbuf->b_visual_mode = i; |
| 7181 | # ifdef FEAT_EVAL |
| 7182 | curbuf->b_visual_mode_eval = i; |
| 7183 | # endif |
| 7184 | i = curwin->w_curswant; |
| 7185 | curwin->w_curswant = curbuf->b_visual_curswant; |
| 7186 | curbuf->b_visual_curswant = i; |
| 7187 | |
| 7188 | tpos = curbuf->b_visual_end; |
| 7189 | curbuf->b_visual_end = curwin->w_cursor; |
| 7190 | curwin->w_cursor = curbuf->b_visual_start; |
| 7191 | curbuf->b_visual_start = VIsual; |
| 7192 | } |
| 7193 | else |
| 7194 | { |
| 7195 | VIsual_mode = curbuf->b_visual_mode; |
| 7196 | curwin->w_curswant = curbuf->b_visual_curswant; |
| 7197 | tpos = curbuf->b_visual_end; |
| 7198 | curwin->w_cursor = curbuf->b_visual_start; |
| 7199 | } |
| 7200 | |
| 7201 | VIsual_active = TRUE; |
| 7202 | VIsual_reselect = TRUE; |
| 7203 | |
| 7204 | /* Set Visual to the start and w_cursor to the end of the Visual |
| 7205 | * area. Make sure they are on an existing character. */ |
| 7206 | check_cursor(); |
| 7207 | VIsual = curwin->w_cursor; |
| 7208 | curwin->w_cursor = tpos; |
| 7209 | check_cursor(); |
| 7210 | update_topline(); |
| 7211 | /* |
| 7212 | * When called from normal "g" command: start Select mode when |
| 7213 | * 'selectmode' contains "cmd". When called for K_SELECT, always |
| 7214 | * start Select mode. |
| 7215 | */ |
| 7216 | if (cap->arg) |
| 7217 | VIsual_select = TRUE; |
| 7218 | else |
| 7219 | may_start_select('c'); |
| 7220 | #ifdef FEAT_MOUSE |
| 7221 | setmouse(); |
| 7222 | #endif |
| 7223 | #ifdef FEAT_CLIPBOARD |
| 7224 | /* Make sure the clipboard gets updated. Needed because start and |
| 7225 | * end are still the same, and the selection needs to be owned */ |
| 7226 | clip_star.vmode = NUL; |
| 7227 | #endif |
| 7228 | redraw_curbuf_later(INVERTED); |
| 7229 | showmode(); |
| 7230 | } |
| 7231 | break; |
| 7232 | /* |
| 7233 | * "gV": Don't reselect the previous Visual area after a Select mode |
| 7234 | * mapping of menu. |
| 7235 | */ |
| 7236 | case 'V': |
| 7237 | VIsual_reselect = FALSE; |
| 7238 | break; |
| 7239 | |
| 7240 | /* |
| 7241 | * "gh": start Select mode. |
| 7242 | * "gH": start Select line mode. |
| 7243 | * "g^H": start Select block mode. |
| 7244 | */ |
| 7245 | case K_BS: |
| 7246 | cap->nchar = Ctrl_H; |
| 7247 | /* FALLTHROUGH */ |
| 7248 | case 'h': |
| 7249 | case 'H': |
| 7250 | case Ctrl_H: |
| 7251 | # ifdef EBCDIC |
| 7252 | /* EBCDIC: 'v'-'h' != '^v'-'^h' */ |
| 7253 | if (cap->nchar == Ctrl_H) |
| 7254 | cap->cmdchar = Ctrl_V; |
| 7255 | else |
| 7256 | # endif |
| 7257 | cap->cmdchar = cap->nchar + ('v' - 'h'); |
| 7258 | cap->arg = TRUE; |
| 7259 | nv_visual(cap); |
| 7260 | break; |
| 7261 | #endif /* FEAT_VISUAL */ |
| 7262 | |
| 7263 | /* |
| 7264 | * "gj" and "gk" two new funny movement keys -- up and down |
| 7265 | * movement based on *screen* line rather than *file* line. |
| 7266 | */ |
| 7267 | case 'j': |
| 7268 | case K_DOWN: |
| 7269 | /* with 'nowrap' it works just like the normal "j" command; also when |
| 7270 | * in a closed fold */ |
| 7271 | if (!curwin->w_p_wrap |
| 7272 | #ifdef FEAT_FOLDING |
| 7273 | || hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
| 7274 | #endif |
| 7275 | ) |
| 7276 | { |
| 7277 | oap->motion_type = MLINE; |
| 7278 | i = cursor_down(cap->count1, oap->op_type == OP_NOP); |
| 7279 | } |
| 7280 | else |
| 7281 | i = nv_screengo(oap, FORWARD, cap->count1); |
| 7282 | if (i == FAIL) |
| 7283 | clearopbeep(oap); |
| 7284 | break; |
| 7285 | |
| 7286 | case 'k': |
| 7287 | case K_UP: |
| 7288 | /* with 'nowrap' it works just like the normal "k" command; also when |
| 7289 | * in a closed fold */ |
| 7290 | if (!curwin->w_p_wrap |
| 7291 | #ifdef FEAT_FOLDING |
| 7292 | || hasFolding(curwin->w_cursor.lnum, NULL, NULL) |
| 7293 | #endif |
| 7294 | ) |
| 7295 | { |
| 7296 | oap->motion_type = MLINE; |
| 7297 | i = cursor_up(cap->count1, oap->op_type == OP_NOP); |
| 7298 | } |
| 7299 | else |
| 7300 | i = nv_screengo(oap, BACKWARD, cap->count1); |
| 7301 | if (i == FAIL) |
| 7302 | clearopbeep(oap); |
| 7303 | break; |
| 7304 | |
| 7305 | /* |
| 7306 | * "gJ": join two lines without inserting a space. |
| 7307 | */ |
| 7308 | case 'J': |
| 7309 | nv_join(cap); |
| 7310 | break; |
| 7311 | |
| 7312 | /* |
| 7313 | * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. |
| 7314 | * "gm": middle of "g0" and "g$". |
| 7315 | */ |
| 7316 | case '^': |
| 7317 | flag = TRUE; |
| 7318 | /* FALLTHROUGH */ |
| 7319 | |
| 7320 | case '0': |
| 7321 | case 'm': |
| 7322 | case K_HOME: |
| 7323 | case K_KHOME: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7324 | oap->motion_type = MCHAR; |
| 7325 | oap->inclusive = FALSE; |
| 7326 | if (curwin->w_p_wrap |
| 7327 | #ifdef FEAT_VERTSPLIT |
| 7328 | && curwin->w_width != 0 |
| 7329 | #endif |
| 7330 | ) |
| 7331 | { |
| 7332 | int width1 = W_WIDTH(curwin) - curwin_col_off(); |
| 7333 | int width2 = width1 + curwin_col_off2(); |
| 7334 | |
| 7335 | validate_virtcol(); |
| 7336 | i = 0; |
| 7337 | if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) |
| 7338 | i = (curwin->w_virtcol - width1) / width2 * width2 + width1; |
| 7339 | } |
| 7340 | else |
| 7341 | i = curwin->w_leftcol; |
| 7342 | /* Go to the middle of the screen line. When 'number' is on and lines |
| 7343 | * are wrapping the middle can be more to the left.*/ |
| 7344 | if (cap->nchar == 'm') |
| 7345 | i += (W_WIDTH(curwin) - curwin_col_off() |
| 7346 | + ((curwin->w_p_wrap && i > 0) |
| 7347 | ? curwin_col_off2() : 0)) / 2; |
| 7348 | coladvance((colnr_T)i); |
| 7349 | if (flag) |
| 7350 | { |
| 7351 | do |
| 7352 | i = gchar_cursor(); |
| 7353 | while (vim_iswhite(i) && oneright() == OK); |
| 7354 | } |
| 7355 | curwin->w_set_curswant = TRUE; |
| 7356 | break; |
| 7357 | |
| 7358 | case '_': |
| 7359 | /* "g_": to the last non-blank character in the line or <count> lines |
| 7360 | * downward. */ |
| 7361 | cap->oap->motion_type = MCHAR; |
| 7362 | cap->oap->inclusive = TRUE; |
| 7363 | curwin->w_curswant = MAXCOL; |
| 7364 | if (cursor_down((long)(cap->count1 - 1), |
| 7365 | cap->oap->op_type == OP_NOP) == FAIL) |
| 7366 | clearopbeep(cap->oap); |
| 7367 | else |
| 7368 | { |
| 7369 | char_u *ptr = ml_get_curline(); |
| 7370 | |
| 7371 | /* In Visual mode we may end up after the line. */ |
| 7372 | if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) |
| 7373 | --curwin->w_cursor.col; |
| 7374 | |
| 7375 | /* Decrease the cursor column until it's on a non-blank. */ |
| 7376 | while (curwin->w_cursor.col > 0 |
| 7377 | && vim_iswhite(ptr[curwin->w_cursor.col])) |
| 7378 | --curwin->w_cursor.col; |
| 7379 | curwin->w_set_curswant = TRUE; |
| 7380 | } |
| 7381 | break; |
| 7382 | |
| 7383 | case '$': |
| 7384 | case K_END: |
| 7385 | case K_KEND: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7386 | { |
| 7387 | int col_off = curwin_col_off(); |
| 7388 | |
| 7389 | oap->motion_type = MCHAR; |
| 7390 | oap->inclusive = TRUE; |
| 7391 | if (curwin->w_p_wrap |
| 7392 | #ifdef FEAT_VERTSPLIT |
| 7393 | && curwin->w_width != 0 |
| 7394 | #endif |
| 7395 | ) |
| 7396 | { |
| 7397 | curwin->w_curswant = MAXCOL; /* so we stay at the end */ |
| 7398 | if (cap->count1 == 1) |
| 7399 | { |
| 7400 | int width1 = W_WIDTH(curwin) - col_off; |
| 7401 | int width2 = width1 + curwin_col_off2(); |
| 7402 | |
| 7403 | validate_virtcol(); |
| 7404 | i = width1 - 1; |
| 7405 | if (curwin->w_virtcol >= (colnr_T)width1) |
| 7406 | i += ((curwin->w_virtcol - width1) / width2 + 1) |
| 7407 | * width2; |
| 7408 | coladvance((colnr_T)i); |
| 7409 | #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
| 7410 | if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
| 7411 | { |
| 7412 | /* |
| 7413 | * Check for landing on a character that got split at |
| 7414 | * the end of the line. We do not want to advance to |
| 7415 | * the next screen line. |
| 7416 | */ |
| 7417 | validate_virtcol(); |
| 7418 | if (curwin->w_virtcol > (colnr_T)i) |
| 7419 | --curwin->w_cursor.col; |
| 7420 | } |
| 7421 | #endif |
| 7422 | } |
| 7423 | else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) |
| 7424 | clearopbeep(oap); |
| 7425 | } |
| 7426 | else |
| 7427 | { |
| 7428 | i = curwin->w_leftcol + W_WIDTH(curwin) - col_off - 1; |
| 7429 | coladvance((colnr_T)i); |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 7430 | |
| 7431 | /* Make sure we stick in this column. */ |
| 7432 | validate_virtcol(); |
| 7433 | curwin->w_curswant = curwin->w_virtcol; |
| 7434 | curwin->w_set_curswant = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7435 | } |
| 7436 | } |
| 7437 | break; |
| 7438 | |
| 7439 | /* |
| 7440 | * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" |
| 7441 | */ |
| 7442 | case '*': |
| 7443 | case '#': |
| 7444 | #if POUND != '#' |
| 7445 | case POUND: /* pound sign (sometimes equal to '#') */ |
| 7446 | #endif |
| 7447 | case Ctrl_RSB: /* :tag or :tselect for current identifier */ |
| 7448 | case ']': /* :tselect for current identifier */ |
| 7449 | nv_ident(cap); |
| 7450 | break; |
| 7451 | |
| 7452 | /* |
| 7453 | * ge and gE: go back to end of word |
| 7454 | */ |
| 7455 | case 'e': |
| 7456 | case 'E': |
| 7457 | oap->motion_type = MCHAR; |
| 7458 | curwin->w_set_curswant = TRUE; |
| 7459 | oap->inclusive = TRUE; |
| 7460 | if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) |
| 7461 | clearopbeep(oap); |
| 7462 | break; |
| 7463 | |
| 7464 | /* |
| 7465 | * "g CTRL-G": display info about cursor position |
| 7466 | */ |
| 7467 | case Ctrl_G: |
| 7468 | cursor_pos_info(); |
| 7469 | break; |
| 7470 | |
| 7471 | /* |
| 7472 | * "gi": start Insert at the last position. |
| 7473 | */ |
| 7474 | case 'i': |
| 7475 | if (curbuf->b_last_insert.lnum != 0) |
| 7476 | { |
| 7477 | curwin->w_cursor = curbuf->b_last_insert; |
| 7478 | check_cursor_lnum(); |
| 7479 | i = (int)STRLEN(ml_get_curline()); |
| 7480 | if (curwin->w_cursor.col > (colnr_T)i) |
| 7481 | { |
| 7482 | #ifdef FEAT_VIRTUALEDIT |
| 7483 | if (virtual_active()) |
| 7484 | curwin->w_cursor.coladd += curwin->w_cursor.col - i; |
| 7485 | #endif |
| 7486 | curwin->w_cursor.col = i; |
| 7487 | } |
| 7488 | } |
| 7489 | cap->cmdchar = 'i'; |
| 7490 | nv_edit(cap); |
| 7491 | break; |
| 7492 | |
| 7493 | /* |
| 7494 | * "gI": Start insert in column 1. |
| 7495 | */ |
| 7496 | case 'I': |
| 7497 | beginline(0); |
| 7498 | if (!checkclearopq(oap)) |
| 7499 | invoke_edit(cap, FALSE, 'g', FALSE); |
| 7500 | break; |
| 7501 | |
| 7502 | #ifdef FEAT_SEARCHPATH |
| 7503 | /* |
| 7504 | * "gf": goto file, edit file under cursor |
| 7505 | * "]f" and "[f": can also be used. |
| 7506 | */ |
| 7507 | case 'f': |
| 7508 | nv_gotofile(cap); |
| 7509 | break; |
| 7510 | #endif |
| 7511 | |
| 7512 | /* "g'm" and "g`m": jump to mark without setting pcmark */ |
| 7513 | case '\'': |
| 7514 | cap->arg = TRUE; |
| 7515 | /*FALLTHROUGH*/ |
| 7516 | case '`': |
| 7517 | nv_gomark(cap); |
| 7518 | break; |
| 7519 | |
| 7520 | /* |
| 7521 | * "gs": Goto sleep. |
| 7522 | */ |
| 7523 | case 's': |
| 7524 | do_sleep(cap->count1 * 1000L); |
| 7525 | break; |
| 7526 | |
| 7527 | /* |
| 7528 | * "ga": Display the ascii value of the character under the |
| 7529 | * cursor. It is displayed in decimal, hex, and octal. -- webb |
| 7530 | */ |
| 7531 | case 'a': |
| 7532 | do_ascii(NULL); |
| 7533 | break; |
| 7534 | |
| 7535 | #ifdef FEAT_MBYTE |
| 7536 | /* |
| 7537 | * "g8": Display the bytes used for the UTF-8 character under the |
| 7538 | * cursor. It is displayed in hex. |
| 7539 | */ |
| 7540 | case '8': |
| 7541 | show_utf8(); |
| 7542 | break; |
| 7543 | #endif |
| 7544 | |
| 7545 | /* |
| 7546 | * "gg": Goto the first line in file. With a count it goes to |
| 7547 | * that line number like for "G". -- webb |
| 7548 | */ |
| 7549 | case 'g': |
| 7550 | cap->arg = FALSE; |
| 7551 | nv_goto(cap); |
| 7552 | break; |
| 7553 | |
| 7554 | /* |
| 7555 | * Two-character operators: |
| 7556 | * "gq" Format text |
| 7557 | * "gw" Format text and keep cursor position |
| 7558 | * "g~" Toggle the case of the text. |
| 7559 | * "gu" Change text to lower case. |
| 7560 | * "gU" Change text to upper case. |
| 7561 | * "g?" rot13 encoding |
| 7562 | */ |
| 7563 | case 'q': |
| 7564 | case 'w': |
| 7565 | oap->cursor_start = curwin->w_cursor; |
| 7566 | /*FALLTHROUGH*/ |
| 7567 | case '~': |
| 7568 | case 'u': |
| 7569 | case 'U': |
| 7570 | case '?': |
| 7571 | nv_operator(cap); |
| 7572 | break; |
| 7573 | |
| 7574 | /* |
| 7575 | * "gd": Find first occurence of pattern under the cursor in the |
| 7576 | * current function |
| 7577 | * "gD": idem, but in the current file. |
| 7578 | */ |
| 7579 | case 'd': |
| 7580 | case 'D': |
| 7581 | nv_gd(oap, cap->nchar); |
| 7582 | break; |
| 7583 | |
| 7584 | #ifdef FEAT_MOUSE |
| 7585 | /* |
| 7586 | * g<*Mouse> : <C-*mouse> |
| 7587 | */ |
| 7588 | case K_MIDDLEMOUSE: |
| 7589 | case K_MIDDLEDRAG: |
| 7590 | case K_MIDDLERELEASE: |
| 7591 | case K_LEFTMOUSE: |
| 7592 | case K_LEFTDRAG: |
| 7593 | case K_LEFTRELEASE: |
| 7594 | case K_RIGHTMOUSE: |
| 7595 | case K_RIGHTDRAG: |
| 7596 | case K_RIGHTRELEASE: |
| 7597 | case K_X1MOUSE: |
| 7598 | case K_X1DRAG: |
| 7599 | case K_X1RELEASE: |
| 7600 | case K_X2MOUSE: |
| 7601 | case K_X2DRAG: |
| 7602 | case K_X2RELEASE: |
| 7603 | mod_mask = MOD_MASK_CTRL; |
| 7604 | (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); |
| 7605 | break; |
| 7606 | #endif |
| 7607 | |
| 7608 | case K_IGNORE: |
| 7609 | break; |
| 7610 | |
| 7611 | /* |
| 7612 | * "gP" and "gp": same as "P" and "p" but leave cursor just after new text |
| 7613 | */ |
| 7614 | case 'p': |
| 7615 | case 'P': |
| 7616 | nv_put(cap); |
| 7617 | break; |
| 7618 | |
| 7619 | #ifdef FEAT_BYTEOFF |
| 7620 | /* "go": goto byte count from start of buffer */ |
| 7621 | case 'o': |
| 7622 | goto_byte(cap->count0); |
| 7623 | break; |
| 7624 | #endif |
| 7625 | |
| 7626 | /* "gQ": improved Ex mode */ |
| 7627 | case 'Q': |
| 7628 | #ifdef FEAT_CMDWIN |
| 7629 | if (cmdwin_type != 0) |
| 7630 | { |
| 7631 | clearopbeep(cap->oap); |
| 7632 | break; |
| 7633 | } |
| 7634 | #endif |
| 7635 | if (!checkclearopq(oap)) |
| 7636 | do_exmode(TRUE); |
| 7637 | break; |
| 7638 | |
| 7639 | #ifdef FEAT_JUMPLIST |
| 7640 | case ',': |
| 7641 | nv_pcmark(cap); |
| 7642 | break; |
| 7643 | |
| 7644 | case ';': |
| 7645 | cap->count1 = -cap->count1; |
| 7646 | nv_pcmark(cap); |
| 7647 | break; |
| 7648 | #endif |
| 7649 | |
| 7650 | default: |
| 7651 | clearopbeep(oap); |
| 7652 | break; |
| 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | /* |
| 7657 | * Handle "o" and "O" commands. |
| 7658 | */ |
| 7659 | static void |
| 7660 | n_opencmd(cap) |
| 7661 | cmdarg_T *cap; |
| 7662 | { |
| 7663 | if (!checkclearopq(cap->oap)) |
| 7664 | { |
| 7665 | #ifdef FEAT_FOLDING |
| 7666 | if (cap->cmdchar == 'O') |
| 7667 | /* Open above the first line of a folded sequence of lines */ |
| 7668 | (void)hasFolding(curwin->w_cursor.lnum, |
| 7669 | &curwin->w_cursor.lnum, NULL); |
| 7670 | else |
| 7671 | /* Open below the last line of a folded sequence of lines */ |
| 7672 | (void)hasFolding(curwin->w_cursor.lnum, |
| 7673 | NULL, &curwin->w_cursor.lnum); |
| 7674 | #endif |
| 7675 | if (u_save((linenr_T)(curwin->w_cursor.lnum - |
| 7676 | (cap->cmdchar == 'O' ? 1 : 0)), |
| 7677 | (linenr_T)(curwin->w_cursor.lnum + |
| 7678 | (cap->cmdchar == 'o' ? 1 : 0)) |
| 7679 | ) == OK |
| 7680 | && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, |
| 7681 | #ifdef FEAT_COMMENTS |
| 7682 | has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : |
| 7683 | #endif |
| 7684 | 0, 0)) |
| 7685 | { |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 7686 | /* When '#' is in 'cpoptions' ignore the count. */ |
| 7687 | if (vim_strchr(p_cpo, CPO_HASH) != NULL) |
| 7688 | cap->count1 = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7689 | invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
| 7690 | } |
| 7691 | } |
| 7692 | } |
| 7693 | |
| 7694 | /* |
| 7695 | * "." command: redo last change. |
| 7696 | */ |
| 7697 | static void |
| 7698 | nv_dot(cap) |
| 7699 | cmdarg_T *cap; |
| 7700 | { |
| 7701 | if (!checkclearopq(cap->oap)) |
| 7702 | { |
| 7703 | /* |
| 7704 | * If "restart_edit" is TRUE, the last but one command is repeated |
| 7705 | * instead of the last command (inserting text). This is used for |
| 7706 | * CTRL-O <.> in insert mode. |
| 7707 | */ |
| 7708 | if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) |
| 7709 | clearopbeep(cap->oap); |
| 7710 | } |
| 7711 | } |
| 7712 | |
| 7713 | /* |
| 7714 | * CTRL-R: undo undo |
| 7715 | */ |
| 7716 | static void |
| 7717 | nv_redo(cap) |
| 7718 | cmdarg_T *cap; |
| 7719 | { |
| 7720 | if (!checkclearopq(cap->oap)) |
| 7721 | { |
| 7722 | u_redo((int)cap->count1); |
| 7723 | curwin->w_set_curswant = TRUE; |
| 7724 | } |
| 7725 | } |
| 7726 | |
| 7727 | /* |
| 7728 | * Handle "U" command. |
| 7729 | */ |
| 7730 | static void |
| 7731 | nv_Undo(cap) |
| 7732 | cmdarg_T *cap; |
| 7733 | { |
| 7734 | /* In Visual mode and typing "gUU" triggers an operator */ |
| 7735 | if (cap->oap->op_type == OP_UPPER |
| 7736 | #ifdef FEAT_VISUAL |
| 7737 | || VIsual_active |
| 7738 | #endif |
| 7739 | ) |
| 7740 | { |
| 7741 | /* translate "gUU" to "gUgU" */ |
| 7742 | cap->cmdchar = 'g'; |
| 7743 | cap->nchar = 'U'; |
| 7744 | nv_operator(cap); |
| 7745 | } |
| 7746 | else if (!checkclearopq(cap->oap)) |
| 7747 | { |
| 7748 | u_undoline(); |
| 7749 | curwin->w_set_curswant = TRUE; |
| 7750 | } |
| 7751 | } |
| 7752 | |
| 7753 | /* |
| 7754 | * '~' command: If tilde is not an operator and Visual is off: swap case of a |
| 7755 | * single character. |
| 7756 | */ |
| 7757 | static void |
| 7758 | nv_tilde(cap) |
| 7759 | cmdarg_T *cap; |
| 7760 | { |
| 7761 | if (!p_to |
| 7762 | #ifdef FEAT_VISUAL |
| 7763 | && !VIsual_active |
| 7764 | #endif |
| 7765 | && cap->oap->op_type != OP_TILDE) |
| 7766 | n_swapchar(cap); |
| 7767 | else |
| 7768 | nv_operator(cap); |
| 7769 | } |
| 7770 | |
| 7771 | /* |
| 7772 | * Handle an operator command. |
| 7773 | * The actual work is done by do_pending_operator(). |
| 7774 | */ |
| 7775 | static void |
| 7776 | nv_operator(cap) |
| 7777 | cmdarg_T *cap; |
| 7778 | { |
| 7779 | int op_type; |
| 7780 | |
| 7781 | op_type = get_op_type(cap->cmdchar, cap->nchar); |
| 7782 | |
| 7783 | if (op_type == cap->oap->op_type) /* double operator works on lines */ |
| 7784 | nv_lineop(cap); |
| 7785 | else if (!checkclearop(cap->oap)) |
| 7786 | { |
| 7787 | cap->oap->start = curwin->w_cursor; |
| 7788 | cap->oap->op_type = op_type; |
| 7789 | } |
| 7790 | } |
| 7791 | |
| 7792 | /* |
| 7793 | * Handle linewise operator "dd", "yy", etc. |
| 7794 | * |
| 7795 | * "_" is is a strange motion command that helps make operators more logical. |
| 7796 | * It is actually implemented, but not documented in the real Vi. This motion |
| 7797 | * command actually refers to "the current line". Commands like "dd" and "yy" |
| 7798 | * are really an alternate form of "d_" and "y_". It does accept a count, so |
| 7799 | * "d3_" works to delete 3 lines. |
| 7800 | */ |
| 7801 | static void |
| 7802 | nv_lineop(cap) |
| 7803 | cmdarg_T *cap; |
| 7804 | { |
| 7805 | cap->oap->motion_type = MLINE; |
| 7806 | if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) |
| 7807 | clearopbeep(cap->oap); |
| 7808 | else if ( cap->oap->op_type == OP_DELETE |
| 7809 | || cap->oap->op_type == OP_LSHIFT |
| 7810 | || cap->oap->op_type == OP_RSHIFT) |
| 7811 | beginline(BL_SOL | BL_FIX); |
| 7812 | else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ |
| 7813 | beginline(BL_WHITE | BL_FIX); |
| 7814 | } |
| 7815 | |
| 7816 | /* |
| 7817 | * <Home> command. |
| 7818 | */ |
| 7819 | static void |
| 7820 | nv_home(cap) |
| 7821 | cmdarg_T *cap; |
| 7822 | { |
Bram Moolenaar | bc7aa85 | 2005-03-06 23:38:09 +0000 | [diff] [blame] | 7823 | /* CTRL-HOME is like "gg" */ |
| 7824 | if (mod_mask & MOD_MASK_CTRL) |
| 7825 | nv_goto(cap); |
| 7826 | else |
| 7827 | { |
| 7828 | cap->count0 = 1; |
| 7829 | nv_pipe(cap); |
| 7830 | } |
Bram Moolenaar | a88d968 | 2005-03-25 21:45:43 +0000 | [diff] [blame] | 7831 | ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
| 7832 | one-character line). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | /* |
| 7836 | * "|" command. |
| 7837 | */ |
| 7838 | static void |
| 7839 | nv_pipe(cap) |
| 7840 | cmdarg_T *cap; |
| 7841 | { |
| 7842 | cap->oap->motion_type = MCHAR; |
| 7843 | cap->oap->inclusive = FALSE; |
| 7844 | beginline(0); |
| 7845 | if (cap->count0 > 0) |
| 7846 | { |
| 7847 | coladvance((colnr_T)(cap->count0 - 1)); |
| 7848 | curwin->w_curswant = (colnr_T)(cap->count0 - 1); |
| 7849 | } |
| 7850 | else |
| 7851 | curwin->w_curswant = 0; |
| 7852 | /* keep curswant at the column where we wanted to go, not where |
| 7853 | we ended; differs if line is too short */ |
| 7854 | curwin->w_set_curswant = FALSE; |
| 7855 | } |
| 7856 | |
| 7857 | /* |
| 7858 | * Handle back-word command "b" and "B". |
| 7859 | * cap->arg is 1 for "B" |
| 7860 | */ |
| 7861 | static void |
| 7862 | nv_bck_word(cap) |
| 7863 | cmdarg_T *cap; |
| 7864 | { |
| 7865 | cap->oap->motion_type = MCHAR; |
| 7866 | cap->oap->inclusive = FALSE; |
| 7867 | curwin->w_set_curswant = TRUE; |
| 7868 | if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) |
| 7869 | clearopbeep(cap->oap); |
| 7870 | #ifdef FEAT_FOLDING |
| 7871 | else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 7872 | foldOpenCursor(); |
| 7873 | #endif |
| 7874 | } |
| 7875 | |
| 7876 | /* |
| 7877 | * Handle word motion commands "e", "E", "w" and "W". |
| 7878 | * cap->arg is TRUE for "E" and "W". |
| 7879 | */ |
| 7880 | static void |
| 7881 | nv_wordcmd(cap) |
| 7882 | cmdarg_T *cap; |
| 7883 | { |
| 7884 | int n; |
| 7885 | int word_end; |
| 7886 | int flag = FALSE; |
| 7887 | |
| 7888 | /* |
| 7889 | * Set inclusive for the "E" and "e" command. |
| 7890 | */ |
| 7891 | if (cap->cmdchar == 'e' || cap->cmdchar == 'E') |
| 7892 | word_end = TRUE; |
| 7893 | else |
| 7894 | word_end = FALSE; |
| 7895 | cap->oap->inclusive = word_end; |
| 7896 | |
| 7897 | /* |
| 7898 | * "cw" and "cW" are a special case. |
| 7899 | */ |
| 7900 | if (!word_end && cap->oap->op_type == OP_CHANGE) |
| 7901 | { |
| 7902 | n = gchar_cursor(); |
| 7903 | if (n != NUL) /* not an empty line */ |
| 7904 | { |
| 7905 | if (vim_iswhite(n)) |
| 7906 | { |
| 7907 | /* |
| 7908 | * Reproduce a funny Vi behaviour: "cw" on a blank only |
| 7909 | * changes one character, not all blanks until the start of |
| 7910 | * the next word. Only do this when the 'w' flag is included |
| 7911 | * in 'cpoptions'. |
| 7912 | */ |
| 7913 | if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) |
| 7914 | { |
| 7915 | cap->oap->inclusive = TRUE; |
| 7916 | cap->oap->motion_type = MCHAR; |
| 7917 | return; |
| 7918 | } |
| 7919 | } |
| 7920 | else |
| 7921 | { |
| 7922 | /* |
| 7923 | * This is a little strange. To match what the real Vi does, |
| 7924 | * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided |
| 7925 | * that we are not on a space or a TAB. This seems impolite |
| 7926 | * at first, but it's really more what we mean when we say |
| 7927 | * 'cw'. |
| 7928 | * Another strangeness: When standing on the end of a word |
| 7929 | * "ce" will change until the end of the next wordt, but "cw" |
| 7930 | * will change only one character! This is done by setting |
| 7931 | * flag. |
| 7932 | */ |
| 7933 | cap->oap->inclusive = TRUE; |
| 7934 | word_end = TRUE; |
| 7935 | flag = TRUE; |
| 7936 | } |
| 7937 | } |
| 7938 | } |
| 7939 | |
| 7940 | cap->oap->motion_type = MCHAR; |
| 7941 | curwin->w_set_curswant = TRUE; |
| 7942 | if (word_end) |
| 7943 | n = end_word(cap->count1, cap->arg, flag, FALSE); |
| 7944 | else |
| 7945 | n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); |
| 7946 | |
| 7947 | /* Don't leave the cursor on the NUL past a line */ |
| 7948 | if (curwin->w_cursor.col && gchar_cursor() == NUL) |
| 7949 | { |
| 7950 | --curwin->w_cursor.col; |
| 7951 | cap->oap->inclusive = TRUE; |
| 7952 | } |
| 7953 | |
| 7954 | if (n == FAIL && cap->oap->op_type == OP_NOP) |
| 7955 | clearopbeep(cap->oap); |
| 7956 | else |
| 7957 | { |
| 7958 | #ifdef FEAT_VISUAL |
| 7959 | adjust_for_sel(cap); |
| 7960 | #endif |
| 7961 | #ifdef FEAT_FOLDING |
| 7962 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 7963 | foldOpenCursor(); |
| 7964 | #endif |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | /* |
| 7969 | * "0" and "^" commands. |
| 7970 | * cap->arg is the argument for beginline(). |
| 7971 | */ |
| 7972 | static void |
| 7973 | nv_beginline(cap) |
| 7974 | cmdarg_T *cap; |
| 7975 | { |
| 7976 | cap->oap->motion_type = MCHAR; |
| 7977 | cap->oap->inclusive = FALSE; |
| 7978 | beginline(cap->arg); |
| 7979 | #ifdef FEAT_FOLDING |
| 7980 | if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 7981 | foldOpenCursor(); |
| 7982 | #endif |
| 7983 | } |
| 7984 | |
| 7985 | #ifdef FEAT_VISUAL |
| 7986 | /* |
| 7987 | * In exclusive Visual mode, may include the last character. |
| 7988 | */ |
| 7989 | static void |
| 7990 | adjust_for_sel(cap) |
| 7991 | cmdarg_T *cap; |
| 7992 | { |
| 7993 | if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' |
| 7994 | && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) |
| 7995 | { |
| 7996 | # ifdef FEAT_MBYTE |
| 7997 | if (has_mbyte) |
| 7998 | inc_cursor(); |
| 7999 | else |
| 8000 | # endif |
| 8001 | ++curwin->w_cursor.col; |
| 8002 | cap->oap->inclusive = FALSE; |
| 8003 | } |
| 8004 | } |
| 8005 | |
| 8006 | /* |
| 8007 | * Exclude last character at end of Visual area for 'selection' == "exclusive". |
| 8008 | * Should check VIsual_mode before calling this. |
| 8009 | * Returns TRUE when backed up to the previous line. |
| 8010 | */ |
| 8011 | static int |
| 8012 | unadjust_for_sel() |
| 8013 | { |
| 8014 | pos_T *pp; |
| 8015 | |
| 8016 | if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor)) |
| 8017 | { |
| 8018 | if (lt(VIsual, curwin->w_cursor)) |
| 8019 | pp = &curwin->w_cursor; |
| 8020 | else |
| 8021 | pp = &VIsual; |
| 8022 | #ifdef FEAT_VIRTUALEDIT |
| 8023 | if (pp->coladd > 0) |
| 8024 | --pp->coladd; |
| 8025 | else |
| 8026 | #endif |
| 8027 | if (pp->col > 0) |
| 8028 | { |
| 8029 | --pp->col; |
| 8030 | #ifdef FEAT_MBYTE |
| 8031 | mb_adjustpos(pp); |
| 8032 | #endif |
| 8033 | } |
| 8034 | else if (pp->lnum > 1) |
| 8035 | { |
| 8036 | --pp->lnum; |
| 8037 | pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); |
| 8038 | return TRUE; |
| 8039 | } |
| 8040 | } |
| 8041 | return FALSE; |
| 8042 | } |
| 8043 | |
| 8044 | /* |
| 8045 | * SELECT key in Normal or Visual mode: end of Select mode mapping. |
| 8046 | */ |
| 8047 | static void |
| 8048 | nv_select(cap) |
| 8049 | cmdarg_T *cap; |
| 8050 | { |
| 8051 | if (VIsual_active) |
| 8052 | VIsual_select = TRUE; |
| 8053 | else if (VIsual_reselect) |
| 8054 | { |
| 8055 | cap->nchar = 'v'; /* fake "gv" command */ |
| 8056 | cap->arg = TRUE; |
| 8057 | nv_g_cmd(cap); |
| 8058 | } |
| 8059 | } |
| 8060 | |
| 8061 | #endif |
| 8062 | |
| 8063 | /* |
| 8064 | * "G", "gg", CTRL-END, CTRL-HOME. |
| 8065 | * cap->arg is TRUE for "G". |
| 8066 | */ |
| 8067 | static void |
| 8068 | nv_goto(cap) |
| 8069 | cmdarg_T *cap; |
| 8070 | { |
| 8071 | linenr_T lnum; |
| 8072 | |
| 8073 | if (cap->arg) |
| 8074 | lnum = curbuf->b_ml.ml_line_count; |
| 8075 | else |
| 8076 | lnum = 1L; |
| 8077 | cap->oap->motion_type = MLINE; |
| 8078 | setpcmark(); |
| 8079 | |
| 8080 | /* When a count is given, use it instead of the default lnum */ |
| 8081 | if (cap->count0 != 0) |
| 8082 | lnum = cap->count0; |
| 8083 | if (lnum < 1L) |
| 8084 | lnum = 1L; |
| 8085 | else if (lnum > curbuf->b_ml.ml_line_count) |
| 8086 | lnum = curbuf->b_ml.ml_line_count; |
| 8087 | curwin->w_cursor.lnum = lnum; |
| 8088 | beginline(BL_SOL | BL_FIX); |
| 8089 | #ifdef FEAT_FOLDING |
| 8090 | if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) |
| 8091 | foldOpenCursor(); |
| 8092 | #endif |
| 8093 | } |
| 8094 | |
| 8095 | /* |
| 8096 | * CTRL-\ in Normal mode. |
| 8097 | */ |
| 8098 | static void |
| 8099 | nv_normal(cap) |
| 8100 | cmdarg_T *cap; |
| 8101 | { |
| 8102 | if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) |
| 8103 | { |
| 8104 | clearop(cap->oap); |
| 8105 | if (restart_edit != 0 && p_smd) |
| 8106 | clear_cmdline = TRUE; /* unshow mode later */ |
| 8107 | restart_edit = 0; |
| 8108 | #ifdef FEAT_CMDWIN |
| 8109 | if (cmdwin_type != 0) |
| 8110 | cmdwin_result = Ctrl_C; |
| 8111 | #endif |
| 8112 | #ifdef FEAT_VISUAL |
| 8113 | if (VIsual_active) |
| 8114 | { |
| 8115 | end_visual_mode(); /* stop Visual */ |
| 8116 | redraw_curbuf_later(INVERTED); |
| 8117 | } |
| 8118 | #endif |
| 8119 | /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ |
| 8120 | if (cap->nchar == Ctrl_G && p_im) |
| 8121 | restart_edit = 'a'; |
| 8122 | } |
| 8123 | else |
| 8124 | clearopbeep(cap->oap); |
| 8125 | } |
| 8126 | |
| 8127 | /* |
| 8128 | * ESC in Normal mode: beep, but don't flush buffers. |
| 8129 | * Don't even beep if we are canceling a command. |
| 8130 | */ |
| 8131 | static void |
| 8132 | nv_esc(cap) |
| 8133 | cmdarg_T *cap; |
| 8134 | { |
| 8135 | int no_reason; |
| 8136 | |
| 8137 | no_reason = (cap->oap->op_type == OP_NOP |
| 8138 | && cap->opcount == 0 |
| 8139 | && cap->count0 == 0 |
| 8140 | && cap->oap->regname == 0 |
| 8141 | && !p_im); |
| 8142 | |
| 8143 | if (cap->arg) /* TRUE for CTRL-C */ |
| 8144 | { |
| 8145 | if (restart_edit == 0 |
| 8146 | #ifdef FEAT_CMDWIN |
| 8147 | && cmdwin_type == 0 |
| 8148 | #endif |
| 8149 | #ifdef FEAT_VISUAL |
| 8150 | && !VIsual_active |
| 8151 | #endif |
| 8152 | && no_reason) |
| 8153 | MSG(_("Type :quit<Enter> to exit Vim")); |
| 8154 | |
| 8155 | /* Don't reset "restart_edit" when 'insertmode' is set, it won't be |
| 8156 | * set again below when halfway a mapping. */ |
| 8157 | if (!p_im) |
| 8158 | restart_edit = 0; |
| 8159 | #ifdef FEAT_CMDWIN |
| 8160 | if (cmdwin_type != 0) |
| 8161 | { |
| 8162 | cmdwin_result = K_IGNORE; |
| 8163 | got_int = FALSE; /* don't stop executing autocommands et al. */ |
| 8164 | return; |
| 8165 | } |
| 8166 | #endif |
| 8167 | } |
| 8168 | |
| 8169 | #ifdef FEAT_VISUAL |
| 8170 | if (VIsual_active) |
| 8171 | { |
| 8172 | end_visual_mode(); /* stop Visual */ |
| 8173 | check_cursor_col(); /* make sure cursor is not beyond EOL */ |
| 8174 | curwin->w_set_curswant = TRUE; |
| 8175 | redraw_curbuf_later(INVERTED); |
| 8176 | } |
| 8177 | else |
| 8178 | #endif |
| 8179 | if (no_reason) |
| 8180 | vim_beep(); |
| 8181 | clearop(cap->oap); |
| 8182 | |
| 8183 | /* A CTRL-C is often used at the start of a menu. When 'insertmode' is |
| 8184 | * set return to Insert mode afterwards. */ |
| 8185 | if (restart_edit == 0 && goto_im() |
| 8186 | #ifdef FEAT_EX_EXTRA |
| 8187 | && ex_normal_busy == 0 |
| 8188 | #endif |
| 8189 | ) |
| 8190 | restart_edit = 'a'; |
| 8191 | } |
| 8192 | |
| 8193 | /* |
| 8194 | * Handle "A", "a", "I", "i" and <Insert> commands. |
| 8195 | */ |
| 8196 | static void |
| 8197 | nv_edit(cap) |
| 8198 | cmdarg_T *cap; |
| 8199 | { |
| 8200 | /* <Insert> is equal to "i" */ |
| 8201 | if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) |
| 8202 | cap->cmdchar = 'i'; |
| 8203 | |
| 8204 | #ifdef FEAT_VISUAL |
| 8205 | /* in Visual mode "A" and "I" are an operator */ |
| 8206 | if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) |
| 8207 | v_visop(cap); |
| 8208 | |
| 8209 | /* in Visual mode and after an operator "a" and "i" are for text objects */ |
| 8210 | else |
| 8211 | #endif |
| 8212 | if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
| 8213 | && (cap->oap->op_type != OP_NOP |
| 8214 | #ifdef FEAT_VISUAL |
| 8215 | || VIsual_active |
| 8216 | #endif |
| 8217 | )) |
| 8218 | { |
| 8219 | #ifdef FEAT_TEXTOBJ |
| 8220 | nv_object(cap); |
| 8221 | #else |
| 8222 | clearopbeep(cap->oap); |
| 8223 | #endif |
| 8224 | } |
| 8225 | else if (!curbuf->b_p_ma && !p_im) |
| 8226 | { |
| 8227 | /* Only give this error when 'insertmode' is off. */ |
| 8228 | EMSG(_(e_modifiable)); |
| 8229 | clearop(cap->oap); |
| 8230 | } |
| 8231 | else if (!checkclearopq(cap->oap)) |
| 8232 | { |
| 8233 | switch (cap->cmdchar) |
| 8234 | { |
| 8235 | case 'A': /* "A"ppend after the line */ |
| 8236 | curwin->w_set_curswant = TRUE; |
| 8237 | #ifdef FEAT_VIRTUALEDIT |
| 8238 | if (ve_flags == VE_ALL) |
| 8239 | { |
| 8240 | int save_State = State; |
| 8241 | |
| 8242 | /* Pretent Insert mode here to allow the cursor on the |
| 8243 | * character past the end of the line */ |
| 8244 | State = INSERT; |
| 8245 | coladvance((colnr_T)MAXCOL); |
| 8246 | State = save_State; |
| 8247 | } |
| 8248 | else |
| 8249 | #endif |
| 8250 | curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); |
| 8251 | break; |
| 8252 | |
| 8253 | case 'I': /* "I"nsert before the first non-blank */ |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 8254 | if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
| 8255 | beginline(BL_WHITE); |
| 8256 | else |
| 8257 | beginline(BL_WHITE|BL_FIX); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8258 | break; |
| 8259 | |
| 8260 | case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
| 8261 | #ifdef FEAT_VIRTUALEDIT |
| 8262 | /* increment coladd when in virtual space, increment the |
| 8263 | * column otherwise, also to append after an unprintable char */ |
| 8264 | if (virtual_active() |
| 8265 | && (curwin->w_cursor.coladd > 0 |
| 8266 | || *ml_get_cursor() == NUL |
| 8267 | || *ml_get_cursor() == TAB)) |
| 8268 | curwin->w_cursor.coladd++; |
| 8269 | else |
| 8270 | #endif |
| 8271 | if (*ml_get_cursor() != NUL) |
| 8272 | inc_cursor(); |
| 8273 | break; |
| 8274 | } |
| 8275 | |
| 8276 | #ifdef FEAT_VIRTUALEDIT |
| 8277 | if (curwin->w_cursor.coladd && cap->cmdchar != 'A') |
| 8278 | { |
| 8279 | int save_State = State; |
| 8280 | |
| 8281 | /* Pretent Insert mode here to allow the cursor on the |
| 8282 | * character past the end of the line */ |
| 8283 | State = INSERT; |
| 8284 | coladvance(getviscol()); |
| 8285 | State = save_State; |
| 8286 | } |
| 8287 | #endif |
| 8288 | |
| 8289 | invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |
| 8290 | } |
| 8291 | } |
| 8292 | |
| 8293 | /* |
| 8294 | * Invoke edit() and take care of "restart_edit" and the return value. |
| 8295 | */ |
| 8296 | static void |
| 8297 | invoke_edit(cap, repl, cmd, startln) |
| 8298 | cmdarg_T *cap; |
| 8299 | int repl; /* "r" or "gr" command */ |
| 8300 | int cmd; |
| 8301 | int startln; |
| 8302 | { |
| 8303 | int restart_edit_save = 0; |
| 8304 | |
| 8305 | /* Complicated: When the user types "a<C-O>a" we don't want to do Insert |
| 8306 | * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow |
| 8307 | * it. */ |
| 8308 | if (repl || !stuff_empty()) |
| 8309 | restart_edit_save = restart_edit; |
| 8310 | else |
| 8311 | restart_edit_save = 0; |
| 8312 | |
| 8313 | /* Always reset "restart_edit", this is not a restarted edit. */ |
| 8314 | restart_edit = 0; |
| 8315 | |
| 8316 | if (edit(cmd, startln, cap->count1)) |
| 8317 | cap->retval |= CA_COMMAND_BUSY; |
| 8318 | |
| 8319 | if (restart_edit == 0) |
| 8320 | restart_edit = restart_edit_save; |
| 8321 | } |
| 8322 | |
| 8323 | #ifdef FEAT_TEXTOBJ |
| 8324 | /* |
| 8325 | * "a" or "i" while an operator is pending or in Visual mode: object motion. |
| 8326 | */ |
| 8327 | static void |
| 8328 | nv_object(cap) |
| 8329 | cmdarg_T *cap; |
| 8330 | { |
| 8331 | int flag; |
| 8332 | int include; |
| 8333 | char_u *mps_save; |
| 8334 | |
| 8335 | if (cap->cmdchar == 'i') |
| 8336 | include = FALSE; /* "ix" = inner object: exclude white space */ |
| 8337 | else |
| 8338 | include = TRUE; /* "ax" = an object: include white space */ |
| 8339 | |
| 8340 | /* Make sure (), [], {} and <> are in 'matchpairs' */ |
| 8341 | mps_save = curbuf->b_p_mps; |
| 8342 | curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; |
| 8343 | |
| 8344 | switch (cap->nchar) |
| 8345 | { |
| 8346 | case 'w': /* "aw" = a word */ |
| 8347 | flag = current_word(cap->oap, cap->count1, include, FALSE); |
| 8348 | break; |
| 8349 | case 'W': /* "aW" = a WORD */ |
| 8350 | flag = current_word(cap->oap, cap->count1, include, TRUE); |
| 8351 | break; |
| 8352 | case 'b': /* "ab" = a braces block */ |
| 8353 | case '(': |
| 8354 | case ')': |
| 8355 | flag = current_block(cap->oap, cap->count1, include, '(', ')'); |
| 8356 | break; |
| 8357 | case 'B': /* "aB" = a Brackets block */ |
| 8358 | case '{': |
| 8359 | case '}': |
| 8360 | flag = current_block(cap->oap, cap->count1, include, '{', '}'); |
| 8361 | break; |
| 8362 | case '[': /* "a[" = a [] block */ |
| 8363 | case ']': |
| 8364 | flag = current_block(cap->oap, cap->count1, include, '[', ']'); |
| 8365 | break; |
| 8366 | case '<': /* "a<" = a <> block */ |
| 8367 | case '>': |
| 8368 | flag = current_block(cap->oap, cap->count1, include, '<', '>'); |
| 8369 | break; |
| 8370 | case 'p': /* "ap" = a paragraph */ |
| 8371 | flag = current_par(cap->oap, cap->count1, include, 'p'); |
| 8372 | break; |
| 8373 | case 's': /* "as" = a sentence */ |
| 8374 | flag = current_sent(cap->oap, cap->count1, include); |
| 8375 | break; |
Bram Moolenaar | cfbc5ee | 2004-07-02 15:38:35 +0000 | [diff] [blame] | 8376 | case '"': /* "a"" = a double quoted string */ |
| 8377 | case '\'': /* "a'" = a single quoted string */ |
| 8378 | case '`': /* "a`" = a backtick quoted string */ |
| 8379 | flag = current_quote(cap->oap, cap->count1, include, |
| 8380 | cap->nchar); |
| 8381 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8382 | #if 0 /* TODO */ |
| 8383 | case 'S': /* "aS" = a section */ |
| 8384 | case 'f': /* "af" = a filename */ |
| 8385 | case 'u': /* "au" = a URL */ |
| 8386 | #endif |
| 8387 | default: |
| 8388 | flag = FAIL; |
| 8389 | break; |
| 8390 | } |
| 8391 | |
| 8392 | curbuf->b_p_mps = mps_save; |
| 8393 | if (flag == FAIL) |
| 8394 | clearopbeep(cap->oap); |
| 8395 | adjust_cursor_col(); |
| 8396 | curwin->w_set_curswant = TRUE; |
| 8397 | } |
| 8398 | #endif |
| 8399 | |
| 8400 | /* |
| 8401 | * "q" command: Start/stop recording. |
| 8402 | * "q:", "q/", "q?": edit command-line in command-line window. |
| 8403 | */ |
| 8404 | static void |
| 8405 | nv_record(cap) |
| 8406 | cmdarg_T *cap; |
| 8407 | { |
| 8408 | if (cap->oap->op_type == OP_FORMAT) |
| 8409 | { |
| 8410 | /* "gqq" is the same as "gqgq": format line */ |
| 8411 | cap->cmdchar = 'g'; |
| 8412 | cap->nchar = 'q'; |
| 8413 | nv_operator(cap); |
| 8414 | } |
| 8415 | else if (!checkclearop(cap->oap)) |
| 8416 | { |
| 8417 | #ifdef FEAT_CMDWIN |
| 8418 | if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') |
| 8419 | { |
| 8420 | stuffcharReadbuff(cap->nchar); |
| 8421 | stuffcharReadbuff(K_CMDWIN); |
| 8422 | } |
| 8423 | else |
| 8424 | #endif |
| 8425 | /* (stop) recording into a named register, unless executing a |
| 8426 | * register */ |
| 8427 | if (!Exec_reg && do_record(cap->nchar) == FAIL) |
| 8428 | clearopbeep(cap->oap); |
| 8429 | } |
| 8430 | } |
| 8431 | |
| 8432 | /* |
| 8433 | * Handle the "@r" command. |
| 8434 | */ |
| 8435 | static void |
| 8436 | nv_at(cap) |
| 8437 | cmdarg_T *cap; |
| 8438 | { |
| 8439 | if (checkclearop(cap->oap)) |
| 8440 | return; |
| 8441 | #ifdef FEAT_EVAL |
| 8442 | if (cap->nchar == '=') |
| 8443 | { |
| 8444 | if (get_expr_register() == NUL) |
| 8445 | return; |
| 8446 | } |
| 8447 | #endif |
| 8448 | while (cap->count1-- && !got_int) |
| 8449 | { |
| 8450 | if (do_execreg(cap->nchar, FALSE, FALSE) == FAIL) |
| 8451 | { |
| 8452 | clearopbeep(cap->oap); |
| 8453 | break; |
| 8454 | } |
| 8455 | line_breakcheck(); |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | /* |
| 8460 | * Handle the CTRL-U and CTRL-D commands. |
| 8461 | */ |
| 8462 | static void |
| 8463 | nv_halfpage(cap) |
| 8464 | cmdarg_T *cap; |
| 8465 | { |
| 8466 | if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) |
| 8467 | || (cap->cmdchar == Ctrl_D |
| 8468 | && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) |
| 8469 | clearopbeep(cap->oap); |
| 8470 | else if (!checkclearop(cap->oap)) |
| 8471 | halfpage(cap->cmdchar == Ctrl_D, cap->count0); |
| 8472 | } |
| 8473 | |
| 8474 | /* |
| 8475 | * Handle "J" or "gJ" command. |
| 8476 | */ |
| 8477 | static void |
| 8478 | nv_join(cap) |
| 8479 | cmdarg_T *cap; |
| 8480 | { |
| 8481 | #ifdef FEAT_VISUAL |
| 8482 | if (VIsual_active) /* join the visual lines */ |
| 8483 | nv_operator(cap); |
| 8484 | else |
| 8485 | #endif |
| 8486 | if (!checkclearop(cap->oap)) |
| 8487 | { |
| 8488 | if (cap->count0 <= 1) |
| 8489 | cap->count0 = 2; /* default for join is two lines! */ |
| 8490 | if (curwin->w_cursor.lnum + cap->count0 - 1 > |
| 8491 | curbuf->b_ml.ml_line_count) |
| 8492 | clearopbeep(cap->oap); /* beyond last line */ |
| 8493 | else |
| 8494 | { |
| 8495 | prep_redo(cap->oap->regname, cap->count0, |
| 8496 | NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
| 8497 | do_do_join(cap->count0, cap->nchar == NUL); |
| 8498 | } |
| 8499 | } |
| 8500 | } |
| 8501 | |
| 8502 | /* |
| 8503 | * "P", "gP", "p" and "gp" commands. |
| 8504 | */ |
| 8505 | static void |
| 8506 | nv_put(cap) |
| 8507 | cmdarg_T *cap; |
| 8508 | { |
| 8509 | #ifdef FEAT_VISUAL |
| 8510 | int regname = 0; |
| 8511 | void *reg1 = NULL, *reg2 = NULL; |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 8512 | int empty = FALSE; |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8513 | int was_visual = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8514 | #endif |
| 8515 | int dir; |
| 8516 | int flags = 0; |
| 8517 | |
| 8518 | if (cap->oap->op_type != OP_NOP) |
| 8519 | { |
| 8520 | #ifdef FEAT_DIFF |
| 8521 | /* "dp" is ":diffput" */ |
| 8522 | if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') |
| 8523 | { |
| 8524 | clearop(cap->oap); |
| 8525 | nv_diffgetput(TRUE); |
| 8526 | } |
| 8527 | else |
| 8528 | #endif |
| 8529 | clearopbeep(cap->oap); |
| 8530 | } |
| 8531 | else |
| 8532 | { |
| 8533 | dir = (cap->cmdchar == 'P' |
| 8534 | || (cap->cmdchar == 'g' && cap->nchar == 'P')) |
| 8535 | ? BACKWARD : FORWARD; |
| 8536 | prep_redo_cmd(cap); |
| 8537 | if (cap->cmdchar == 'g') |
| 8538 | flags |= PUT_CURSEND; |
| 8539 | |
| 8540 | #ifdef FEAT_VISUAL |
| 8541 | if (VIsual_active) |
| 8542 | { |
| 8543 | /* Putting in Visual mode: The put text replaces the selected |
| 8544 | * text. First delete the selected text, then put the new text. |
| 8545 | * Need to save and restore the registers that the delete |
| 8546 | * overwrites if the old contents is being put. |
| 8547 | */ |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8548 | was_visual = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8549 | regname = cap->oap->regname; |
| 8550 | # ifdef FEAT_CLIPBOARD |
| 8551 | adjust_clip_reg(®name); |
| 8552 | # endif |
| 8553 | if (regname == 0 || VIM_ISDIGIT(regname) |
| 8554 | # ifdef FEAT_CLIPBOARD |
| 8555 | || (clip_unnamed && (regname == '*' || regname == '+')) |
| 8556 | # endif |
| 8557 | |
| 8558 | ) |
| 8559 | { |
| 8560 | /* the delete is going to overwrite the register we want to |
| 8561 | * put, save it first. */ |
| 8562 | reg1 = get_register(regname, TRUE); |
| 8563 | } |
| 8564 | |
| 8565 | /* Now delete the selected text. */ |
| 8566 | cap->cmdchar = 'd'; |
| 8567 | cap->nchar = NUL; |
| 8568 | cap->oap->regname = NUL; |
| 8569 | nv_operator(cap); |
| 8570 | do_pending_operator(cap, 0, FALSE); |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 8571 | empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8572 | |
| 8573 | /* delete PUT_LINE_BACKWARD; */ |
| 8574 | cap->oap->regname = regname; |
| 8575 | |
| 8576 | if (reg1 != NULL) |
| 8577 | { |
| 8578 | /* Delete probably changed the register we want to put, save |
| 8579 | * it first. Then put back what was there before the delete. */ |
| 8580 | reg2 = get_register(regname, FALSE); |
| 8581 | put_register(regname, reg1); |
| 8582 | } |
| 8583 | |
| 8584 | /* When deleted a linewise Visual area, put the register as |
| 8585 | * lines to avoid it joined with the next line. When deletion was |
| 8586 | * characterwise, split a line when putting lines. */ |
| 8587 | if (VIsual_mode == 'V') |
| 8588 | flags |= PUT_LINE; |
| 8589 | else if (VIsual_mode == 'v') |
| 8590 | flags |= PUT_LINE_SPLIT; |
| 8591 | if (VIsual_mode == Ctrl_V && dir == FORWARD) |
| 8592 | flags |= PUT_LINE_FORWARD; |
| 8593 | dir = BACKWARD; |
| 8594 | if ((VIsual_mode != 'V' |
| 8595 | && curwin->w_cursor.col < curbuf->b_op_start.col) |
| 8596 | || (VIsual_mode == 'V' |
| 8597 | && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) |
| 8598 | /* cursor is at the end of the line or end of file, put |
| 8599 | * forward. */ |
| 8600 | dir = FORWARD; |
| 8601 | } |
| 8602 | #endif |
| 8603 | do_put(cap->oap->regname, dir, cap->count1, flags); |
| 8604 | |
| 8605 | #ifdef FEAT_VISUAL |
| 8606 | /* If a register was saved, put it back now. */ |
| 8607 | if (reg2 != NULL) |
| 8608 | put_register(regname, reg2); |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8609 | |
| 8610 | /* What to reselect with "gv"? Selecting the just put text seems to |
| 8611 | * be the most useful, since the original text was removed. */ |
| 8612 | if (was_visual) |
| 8613 | { |
| 8614 | curbuf->b_visual_start = curbuf->b_op_start; |
| 8615 | curbuf->b_visual_end = curbuf->b_op_end; |
| 8616 | } |
| 8617 | |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 8618 | /* When all lines were selected and deleted do_put() leaves an empty |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 8619 | * line that needs to be deleted now. */ |
Bram Moolenaar | cf3630f | 2005-01-08 16:04:29 +0000 | [diff] [blame] | 8620 | if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
| 8621 | ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8622 | #endif |
| 8623 | auto_format(FALSE, TRUE); |
| 8624 | } |
| 8625 | } |
| 8626 | |
| 8627 | /* |
| 8628 | * "o" and "O" commands. |
| 8629 | */ |
| 8630 | static void |
| 8631 | nv_open(cap) |
| 8632 | cmdarg_T *cap; |
| 8633 | { |
| 8634 | #ifdef FEAT_DIFF |
| 8635 | /* "do" is ":diffget" */ |
| 8636 | if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') |
| 8637 | { |
| 8638 | clearop(cap->oap); |
| 8639 | nv_diffgetput(FALSE); |
| 8640 | } |
| 8641 | else |
| 8642 | #endif |
| 8643 | #ifdef FEAT_VISUAL |
| 8644 | if (VIsual_active) /* switch start and end of visual */ |
| 8645 | v_swap_corners(cap->cmdchar); |
| 8646 | else |
| 8647 | #endif |
| 8648 | n_opencmd(cap); |
| 8649 | } |
| 8650 | |
| 8651 | #ifdef FEAT_SNIFF |
| 8652 | /*ARGSUSED*/ |
| 8653 | static void |
| 8654 | nv_sniff(cap) |
| 8655 | cmdarg_T *cap; |
| 8656 | { |
| 8657 | ProcessSniffRequests(); |
| 8658 | } |
| 8659 | #endif |
| 8660 | |
| 8661 | #ifdef FEAT_NETBEANS_INTG |
| 8662 | static void |
| 8663 | nv_nbcmd(cap) |
| 8664 | cmdarg_T *cap; |
| 8665 | { |
| 8666 | netbeans_keycommand(cap->nchar); |
| 8667 | } |
| 8668 | #endif |
| 8669 | |
| 8670 | #ifdef FEAT_DND |
| 8671 | /*ARGSUSED*/ |
| 8672 | static void |
| 8673 | nv_drop(cap) |
| 8674 | cmdarg_T *cap; |
| 8675 | { |
| 8676 | do_put('~', BACKWARD, 1L, PUT_CURSEND); |
| 8677 | } |
| 8678 | #endif |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 8679 | |
| 8680 | #ifdef FEAT_AUTOCMD |
| 8681 | /* |
| 8682 | * Trigger CursorHold event. |
| 8683 | * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the |
| 8684 | * input buffer. "did_cursorhold" is set to avoid retriggering. |
| 8685 | */ |
| 8686 | /*ARGSUSED*/ |
| 8687 | static void |
| 8688 | nv_cursorhold(cap) |
| 8689 | cmdarg_T *cap; |
| 8690 | { |
| 8691 | apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); |
| 8692 | did_cursorhold = TRUE; |
Bram Moolenaar | fc73515 | 2005-03-22 22:54:12 +0000 | [diff] [blame] | 8693 | cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
Bram Moolenaar | 3918c95 | 2005-03-15 22:34:55 +0000 | [diff] [blame] | 8694 | } |
| 8695 | #endif |
| 8696 | |