diff options
-rw-r--r-- | Filelist | 2 | ||||
-rw-r--r-- | src/Make_cyg_ming.mak | 4 | ||||
-rw-r--r-- | src/Make_morph.mak | 1 | ||||
-rw-r--r-- | src/Make_mvc.mak | 4 | ||||
-rw-r--r-- | src/Make_vms.mms | 8 | ||||
-rw-r--r-- | src/Makefile | 10 | ||||
-rw-r--r-- | src/README.md | 1 | ||||
-rw-r--r-- | src/ops.c | 3097 | ||||
-rw-r--r-- | src/proto.h | 1 | ||||
-rw-r--r-- | src/proto/ops.pro | 42 | ||||
-rw-r--r-- | src/proto/register.pro | 42 | ||||
-rw-r--r-- | src/register.c | 3007 | ||||
-rw-r--r-- | src/structs.h | 112 | ||||
-rw-r--r-- | src/version.c | 2 |
14 files changed, 3153 insertions, 3180 deletions
@@ -100,6 +100,7 @@ SRC_ALL = \ src/regexp_bt.c \ src/regexp_nfa.c \ src/regexp.h \ + src/register.c \ src/scriptfile.c \ src/screen.c \ src/search.c \ @@ -244,6 +245,7 @@ SRC_ALL = \ src/proto/profiler.pro \ src/proto/quickfix.pro \ src/proto/regexp.pro \ + src/proto/register.pro \ src/proto/scriptfile.pro \ src/proto/screen.pro \ src/proto/search.pro \ diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index bc60eb9a9c..3bc57aa44c 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -769,6 +769,7 @@ OBJ = \ $(OUTDIR)/profiler.o \ $(OUTDIR)/quickfix.o \ $(OUTDIR)/regexp.o \ + $(OUTDIR)/register.o \ $(OUTDIR)/scriptfile.o \ $(OUTDIR)/screen.o \ $(OUTDIR)/search.o \ @@ -1186,6 +1187,9 @@ $(OUTDIR)/os_win32.o: os_win32.c $(INCL) $(MZSCHEME_INCL) $(OUTDIR)/regexp.o: regexp.c regexp_bt.c regexp_nfa.c $(INCL) $(CC) -c $(CFLAGS) regexp.c -o $@ +$(OUTDIR)/register.o: register.c $(INCL) + $(CC) -c $(CFLAGS) register.c -o $@ + $(OUTDIR)/terminal.o: terminal.c $(INCL) $(TERM_DEPS) $(CC) -c $(CFLAGS) terminal.c -o $@ diff --git a/src/Make_morph.mak b/src/Make_morph.mak index 6b549df215..0f3cd4ebfd 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -85,6 +85,7 @@ SRC = arabic.c \ profiler.c \ quickfix.c \ regexp.c \ + register.c \ scriptfile.c \ screen.c \ search.c \ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 10c827a51b..3ad3547c1e 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -776,6 +776,7 @@ OBJ = \ $(OUTDIR)\profiler.obj \ $(OUTDIR)\quickfix.obj \ $(OUTDIR)\regexp.obj \ + $(OUTDIR)\register.obj \ $(OUTDIR)\scriptfile.obj \ $(OUTDIR)\screen.obj \ $(OUTDIR)\search.obj \ @@ -1651,6 +1652,8 @@ $(OUTDIR)/quickfix.obj: $(OUTDIR) quickfix.c $(INCL) $(OUTDIR)/regexp.obj: $(OUTDIR) regexp.c regexp_bt.c regexp_nfa.c $(INCL) +$(OUTDIR)/register.obj: $(OUTDIR) register.c $(INCL) + $(OUTDIR)/scriptfile.obj: $(OUTDIR) scriptfile.c $(INCL) $(OUTDIR)/screen.obj: $(OUTDIR) screen.c $(INCL) @@ -1840,6 +1843,7 @@ proto.h: \ proto/profiler.pro \ proto/quickfix.pro \ proto/regexp.pro \ + proto/register.pro \ proto/scriptfile.pro \ proto/screen.pro \ proto/search.pro \ diff --git a/src/Make_vms.mms b/src/Make_vms.mms index 6c791f13e7..b8e5085bb6 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -319,7 +319,7 @@ SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \ memfile.c memline.c message.c misc1.c misc2.c mouse.c move.c normal.c \ ops.c \ option.c optionstr.c popupmnu.c popupwin.c profiler.c quickfix.c \ - regexp.c scriptfile.c \ + regexp.c register.c scriptfile.c \ search.c session.c sha256.c sign.c spell.c spellfile.c syntax.c tag.c \ term.c termlib.c testing.c textprop.c ui.c undo.c usercmd.c \ userfunc.c version.c viminfo.c screen.c window.c os_unix.c os_vms.c \ @@ -340,7 +340,7 @@ OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \ misc1.obj misc2.obj mouse.obj move.obj mbyte.obj normal.obj ops.obj \ option.obj \ optionstr.obj popupmnu.obj popupwin.obj profiler.obj quickfix.obj \ - regexp.obj scriptfile.obj \ + regexp.obj register.obj scriptfile.obj \ search.obj session.obj sha256.obj sign.obj spell.obj spellfile.obj \ syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \ ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \ @@ -755,6 +755,10 @@ regexp.obj : regexp.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ globals.h +register.obj : register.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h scriptfile.obj : scriptfile.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ diff --git a/src/Makefile b/src/Makefile index eebef252e4..9462404adf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1644,6 +1644,7 @@ BASIC_SRC = \ pty.c \ quickfix.c \ regexp.c \ + register.c \ scriptfile.c \ screen.c \ search.c \ @@ -1778,6 +1779,7 @@ OBJ_COMMON = \ objects/pty.o \ objects/quickfix.o \ objects/regexp.o \ + objects/register.o \ objects/scriptfile.o \ objects/screen.o \ objects/search.o \ @@ -1937,6 +1939,7 @@ PRO_AUTO = \ pty.pro \ quickfix.pro \ regexp.pro \ + register.pro \ scriptfile.pro \ screen.pro \ search.pro \ @@ -3353,6 +3356,9 @@ objects/quickfix.o: quickfix.c objects/regexp.o: regexp.c regexp_bt.c regexp_nfa.c $(CCC) -o $@ regexp.c +objects/register.o: register.c + $(CCC) -o $@ register.c + objects/scriptfile.o: scriptfile.c $(CCC) -o $@ scriptfile.c @@ -3835,6 +3841,10 @@ objects/regexp.o: regexp.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h globals.h regexp_bt.c regexp_nfa.c +objects/register.o: register.c vim.h protodef.h auto/config.h feature.h os_unix.h \ + auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h globals.h objects/scriptfile.o: scriptfile.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ diff --git a/src/README.md b/src/README.md index dcbf408b5d..b5ee8b5718 100644 --- a/src/README.md +++ b/src/README.md @@ -63,6 +63,7 @@ popupwin.c | popup window profiler.c | vim script profiler quickfix.c | quickfix commands (":make", ":cn") regexp.c | pattern matching +register.c | handling registers scriptfile.c | runtime directory handling and sourcing scripts screen.c | lower level screen functions search.c | pattern searching @@ -14,66 +14,9 @@ #include "vim.h" -/* - * Number of registers. - * 0 = unnamed register, for normal yanks and puts - * 1..9 = registers '1' to '9', for deletes - * 10..35 = registers 'a' to 'z' - * 36 = delete register '-' - * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined - * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined - */ - -static yankreg_T y_regs[NUM_REGISTERS]; - -static yankreg_T *y_current; /* ptr to current yankreg */ -static int y_append; /* TRUE when appending */ -static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ - -/* - * structure used by block_prep, op_delete and op_yank for blockwise operators - * also op_change, op_shift, op_insert, op_replace - AKelly - */ -struct block_def -{ - int startspaces; /* 'extra' cols before first char */ - int endspaces; /* 'extra' cols after last char */ - int textlen; /* chars in block */ - char_u *textstart; /* pointer to 1st char (partially) in block */ - colnr_T textcol; /* index of chars (partially) in block */ - colnr_T start_vcol; /* start col of 1st char wholly inside block */ - colnr_T end_vcol; /* start col of 1st char wholly after block */ - int is_short; /* TRUE if line is too short to fit in block */ - int is_MAX; /* TRUE if curswant==MAXCOL when starting */ - int is_oneChar; /* TRUE if block within one character */ - int pre_whitesp; /* screen cols of ws before block */ - int pre_whitesp_c; /* chars of ws before block */ - colnr_T end_char_vcols; /* number of vcols of post-block char */ - colnr_T start_char_vcols; /* number of vcols of pre-block char */ -}; - static void shift_block(oparg_T *oap, int amount); -static int stuff_yank(int, char_u *); -static void put_reedit_in_typebuf(int silent); -static int put_in_typebuf(char_u *s, int esc, int colon, - int silent); -static void stuffescaped(char_u *arg, int literally); static void mb_adjust_opend(oparg_T *oap); -static void free_yank_all(void); -static int yank_copy_line(struct block_def *bd, long y_idx); -#ifdef FEAT_CLIPBOARD -static void copy_yank_reg(yankreg_T *reg); -static void may_set_selection(void); -#endif -#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) -static int preprocs_left(void); -#endif -static void dis_msg(char_u *p, int skip_esc); -static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int); static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); -#if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) -static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list); -#endif static int ends_in_white(linenr_T lnum); #ifdef FEAT_COMMENTS static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); @@ -124,31 +67,6 @@ static char opchars[][3] = {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB }; - yankreg_T * -get_y_regs(void) -{ - return y_regs; -} - - yankreg_T * -get_y_current(void) -{ - return y_current; -} - - yankreg_T * -get_y_previous(void) -{ - return y_previous; -} - - void -set_y_previous(yankreg_T *yreg) -{ - y_previous = yreg; -} - - /* * Translate a command name into an operator type. * Must only be called with a valid operator name! @@ -760,708 +678,11 @@ op_reindent(oparg_T *oap, int (*how)(void)) } #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ -#if defined(FEAT_EVAL) || defined(PROTO) -/* - * Keep the last expression line here, for repeating. - */ -static char_u *expr_line = NULL; - -/* - * Get an expression for the "\"=expr1" or "CTRL-R =expr1" - * Returns '=' when OK, NUL otherwise. - */ - int -get_expr_register(void) -{ - char_u *new_line; - - new_line = getcmdline('=', 0L, 0, TRUE); - if (new_line == NULL) - return NUL; - if (*new_line == NUL) /* use previous line */ - vim_free(new_line); - else - set_expr_line(new_line); - return '='; -} - -/* - * Set the expression for the '=' register. - * Argument must be an allocated string. - */ - void -set_expr_line(char_u *new_line) -{ - vim_free(expr_line); - expr_line = new_line; -} - -/* - * Get the result of the '=' register expression. - * Returns a pointer to allocated memory, or NULL for failure. - */ - char_u * -get_expr_line(void) -{ - char_u *expr_copy; - char_u *rv; - static int nested = 0; - - if (expr_line == NULL) - return NULL; - - /* Make a copy of the expression, because evaluating it may cause it to be - * changed. */ - expr_copy = vim_strsave(expr_line); - if (expr_copy == NULL) - return NULL; - - /* When we are invoked recursively limit the evaluation to 10 levels. - * Then return the string as-is. */ - if (nested >= 10) - return expr_copy; - - ++nested; - rv = eval_to_string(expr_copy, NULL, TRUE); - --nested; - vim_free(expr_copy); - return rv; -} - -/* - * Get the '=' register expression itself, without evaluating it. - */ - static char_u * -get_expr_line_src(void) -{ - if (expr_line == NULL) - return NULL; - return vim_strsave(expr_line); -} -#endif /* FEAT_EVAL */ - -/* - * Check if 'regname' is a valid name of a yank register. - * Note: There is no check for 0 (default register), caller should do this - */ - int -valid_yank_reg( - int regname, - int writing) /* if TRUE check for writable registers */ -{ - if ( (regname > 0 && ASCII_ISALNUM(regname)) - || (!writing && vim_strchr((char_u *) -#ifdef FEAT_EVAL - "/.%:=" -#else - "/.%:" -#endif - , regname) != NULL) - || regname == '#' - || regname == '"' - || regname == '-' - || regname == '_' -#ifdef FEAT_CLIPBOARD - || regname == '*' - || regname == '+' -#endif -#ifdef FEAT_DND - || (!writing && regname == '~') -#endif - ) - return TRUE; - return FALSE; -} - -/* - * Set y_current and y_append, according to the value of "regname". - * Cannot handle the '_' register. - * Must only be called with a valid register name! - * - * If regname is 0 and writing, use register 0 - * If regname is 0 and reading, use previous register - * - * Return TRUE when the register should be inserted literally (selection or - * clipboard). - */ - int -get_yank_register(int regname, int writing) -{ - int i; - int ret = FALSE; - - y_append = FALSE; - if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) - { - y_current = y_previous; - return ret; - } - i = regname; - if (VIM_ISDIGIT(i)) - i -= '0'; - else if (ASCII_ISLOWER(i)) - i = CharOrdLow(i) + 10; - else if (ASCII_ISUPPER(i)) - { - i = CharOrdUp(i) + 10; - y_append = TRUE; - } - else if (regname == '-') - i = DELETION_REGISTER; -#ifdef FEAT_CLIPBOARD - /* When selection is not available, use register 0 instead of '*' */ - else if (clip_star.available && regname == '*') - { - i = STAR_REGISTER; - ret = TRUE; - } - /* When clipboard is not available, use register 0 instead of '+' */ - else if (clip_plus.available && regname == '+') - { - i = PLUS_REGISTER; - ret = TRUE; - } -#endif -#ifdef FEAT_DND - else if (!writing && regname == '~') - i = TILDE_REGISTER; -#endif - else /* not 0-9, a-z, A-Z or '-': use register 0 */ - i = 0; - y_current = &(y_regs[i]); - if (writing) /* remember the register we write into for do_put() */ - y_previous = y_current; - return ret; -} - -#if defined(FEAT_CLIPBOARD) || defined(PROTO) -/* - * When "regname" is a clipboard register, obtain the selection. If it's not - * available return zero, otherwise return "regname". - */ - int -may_get_selection(int regname) -{ - if (regname == '*') - { - if (!clip_star.available) - regname = 0; - else - clip_get_selection(&clip_star); - } - else if (regname == '+') - { - if (!clip_plus.available) - regname = 0; - else - clip_get_selection(&clip_plus); - } - return regname; -} -#endif - -/* - * Obtain the contents of a "normal" register. The register is made empty. - * The returned pointer has allocated memory, use put_register() later. - */ - void * -get_register( - int name, - int copy) /* make a copy, if FALSE make register empty. */ -{ - yankreg_T *reg; - int i; - -#ifdef FEAT_CLIPBOARD - /* When Visual area changed, may have to update selection. Obtain the - * selection too. */ - if (name == '*' && clip_star.available) - { - if (clip_isautosel_star()) - clip_update_selection(&clip_star); - may_get_selection(name); - } - if (name == '+' && clip_plus.available) - { - if (clip_isautosel_plus()) - clip_update_selection(&clip_plus); - may_get_selection(name); - } -#endif - - get_yank_register(name, 0); - reg = ALLOC_ONE(yankreg_T); - if (reg != NULL) - { - *reg = *y_current; - if (copy) - { - /* If we run out of memory some or all of the lines are empty. */ - if (reg->y_size == 0) - reg->y_array = NULL; - else - reg->y_array = ALLOC_MULT(char_u *, reg->y_size); - if (reg->y_array != NULL) - { - for (i = 0; i < reg->y_size; ++i) - reg->y_array[i] = vim_strsave(y_current->y_array[i]); - } - } - else - y_current->y_array = NULL; - } - return (void *)reg; -} - -/* - * Put "reg" into register "name". Free any previous contents and "reg". - */ - void -put_register(int name, void *reg) -{ - get_yank_register(name, 0); - free_yank_all(); - *y_current = *(yankreg_T *)reg; - vim_free(reg); - -#ifdef FEAT_CLIPBOARD - /* Send text written to clipboard register to the clipboard. */ - may_set_selection(); -#endif -} - -#if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \ - || defined(PROTO) - void -free_register(void *reg) -{ - yankreg_T tmp; - - tmp = *y_current; - *y_current = *(yankreg_T *)reg; - free_yank_all(); - vim_free(reg); - *y_current = tmp; -} -#endif - -#if defined(FEAT_MOUSE) || defined(PROTO) -/* - * return TRUE if the current yank register has type MLINE - */ - int -yank_register_mline(int regname) -{ - if (regname != 0 && !valid_yank_reg(regname, FALSE)) - return FALSE; - if (regname == '_') /* black hole is always empty */ - return FALSE; - get_yank_register(regname, FALSE); - return (y_current->y_type == MLINE); -} -#endif - -/* - * Start or stop recording into a yank register. - * - * Return FAIL for failure, OK otherwise. - */ - int -do_record(int c) -{ - char_u *p; - static int regname; - yankreg_T *old_y_previous, *old_y_current; - int retval; - - if (reg_recording == 0) /* start recording */ - { - /* registers 0-9, a-z and " are allowed */ - if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) - retval = FAIL; - else - { - reg_recording = c; - showmode(); - regname = c; - retval = OK; - } - } - else /* stop recording */ - { - /* - * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this - * needs to be removed again to put it in a register. exec_reg then - * adds the escaping back later. - */ - reg_recording = 0; - msg(""); - p = get_recorded(); - if (p == NULL) - retval = FAIL; - else - { - /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ - vim_unescape_csi(p); - - /* - * We don't want to change the default register here, so save and - * restore the current register name. - */ - old_y_previous = y_previous; - old_y_current = y_current; - - retval = stuff_yank(regname, p); - - y_previous = old_y_previous; - y_current = old_y_current; - } - } - return retval; -} - -/* - * Stuff string "p" into yank register "regname" as a single line (append if - * uppercase). "p" must have been alloced. - * - * return FAIL for failure, OK otherwise - */ - static int -stuff_yank(int regname, char_u *p) -{ - char_u *lp; - char_u **pp; - - /* check for read-only register */ - if (regname != 0 && !valid_yank_reg(regname, TRUE)) - { - vim_free(p); - return FAIL; - } - if (regname == '_') /* black hole: don't do anything */ - { - vim_free(p); - return OK; - } - get_yank_register(regname, TRUE); - if (y_append && y_current->y_array != NULL) - { - pp = &(y_current->y_array[y_current->y_size - 1]); - lp = alloc(STRLEN(*pp) + STRLEN(p) + 1); - if (lp == NULL) - { - vim_free(p); - return FAIL; - } - STRCPY(lp, *pp); - STRCAT(lp, p); - vim_free(p); - vim_free(*pp); - *pp = lp; - } - else - { - free_yank_all(); - if ((y_current->y_array = ALLOC_ONE(char_u *)) == NULL) - { - vim_free(p); - return FAIL; - } - y_current->y_array[0] = p; - y_current->y_size = 1; - y_current->y_type = MCHAR; /* used to be MLINE, why? */ -#ifdef FEAT_VIMINFO - y_current->y_time_set = vim_time(); -#endif - } - return OK; -} - -static int execreg_lastc = NUL; - - int -get_execreg_lastc(void) -{ - return execreg_lastc; -} - - void -set_execreg_lastc(int lastc) -{ - execreg_lastc = lastc; -} - -/* - * Execute a yank register: copy it into the stuff buffer. - * - * Return FAIL for failure, OK otherwise. - */ - int -do_execreg( - int regname, - int colon, /* insert ':' before each line */ - int addcr, /* always add '\n' to end of line */ - int silent) /* set "silent" flag in typeahead buffer */ -{ - long i; - char_u *p; - int retval = OK; - int remap; - - // repeat previous one - if (regname == '@') - { - if (execreg_lastc == NUL) - { - emsg(_("E748: No previously used register")); - return FAIL; - } - regname = execreg_lastc; - } - // check for valid regname - if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) - { - emsg_invreg(regname); - return FAIL; - } - execreg_lastc = regname; - -#ifdef FEAT_CLIPBOARD - regname = may_get_selection(regname); -#endif - - // black hole: don't stuff anything - if (regname == '_') - return OK; - - // use last command line - if (regname == ':') - { - if (last_cmdline == NULL) - { - emsg(_(e_nolastcmd)); - return FAIL; - } - // don't keep the cmdline containing @: - VIM_CLEAR(new_last_cmdline); - // Escape all control characters with a CTRL-V - p = vim_strsave_escaped_ext(last_cmdline, - (char_u *)"\001\002\003\004\005\006\007" - "\010\011\012\013\014\015\016\017" - "\020\021\022\023\024\025\026\027" - "\030\031\032\033\034\035\036\037", - Ctrl_V, FALSE); - if (p != NULL) - { - /* When in Visual mode "'<,'>" will be prepended to the command. - * Remove it when it's already there. */ - if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) - retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); - else - retval = put_in_typebuf(p, TRUE, TRUE, silent); - } - vim_free(p); - } -#ifdef FEAT_EVAL - else if (regname == '=') - { - p = get_expr_line(); - if (p == NULL) - return FAIL; - retval = put_in_typebuf(p, TRUE, colon, silent); - vim_free(p); - } -#endif - else if (regname == '.') /* use last inserted text */ - { - p = get_last_insert_save(); - if (p == NULL) - { - emsg(_(e_noinstext)); - return FAIL; - } - retval = put_in_typebuf(p, FALSE, colon, silent); - vim_free(p); - } - else - { - get_yank_register(regname, FALSE); - if (y_current->y_array == NULL) - return FAIL; - - /* Disallow remaping for ":@r". */ - remap = colon ? REMAP_NONE : REMAP_YES; - - /* - * Insert lines into typeahead buffer, from last one to first one. - */ - put_reedit_in_typebuf(silent); - for (i = y_current->y_size; --i >= 0; ) - { - char_u *escaped; - - /* insert NL between lines and after last line if type is MLINE */ - if (y_current->y_type == MLINE || i < y_current->y_size - 1 - || addcr) - { - if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) - return FAIL; - } - escaped = vim_strsave_escape_csi(y_current->y_array[i]); - if (escaped == NULL) - return FAIL; - retval = ins_typebuf(escaped, remap, 0, TRUE, silent); - vim_free(escaped); - if (retval == FAIL) - return FAIL; - if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) - == FAIL) - return FAIL; - } - reg_executing = regname == 0 ? '"' : regname; // disable "q" command - } - return retval; -} - -/* - * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's - * used only after other typeahead has been processed. - */ - static void -put_reedit_in_typebuf(int silent) -{ - char_u buf[3]; - - if (restart_edit != NUL) - { - if (restart_edit == 'V') - { - buf[0] = 'g'; - buf[1] = 'R'; - buf[2] = NUL; - } - else - { - buf[0] = restart_edit == 'I' ? 'i' : restart_edit; - buf[1] = NUL; - } - if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) - restart_edit = NUL; - } -} - -/* - * Insert register contents "s" into the typeahead buffer, so that it will be - * executed again. - * When "esc" is TRUE it is to be taken literally: Escape CSI characters and - * no remapping. - */ - static int -put_in_typebuf( - char_u *s, - int esc, - int colon, /* add ':' before the line */ - int silent) -{ - int retval = OK; - - put_reedit_in_typebuf(silent); - if (colon) - retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); - if (retval == OK) - { - char_u *p; - - if (esc) - p = vim_strsave_escape_csi(s); - else - p = s; - if (p == NULL) - retval = FAIL; - else - retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, - 0, TRUE, silent); - if (esc) - vim_free(p); - } - if (colon && retval == OK) - retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); - return retval; -} - -/* - * Insert a yank register: copy it into the Read buffer. - * Used by CTRL-R command and middle mouse button in insert mode. - * - * return FAIL for failure, OK otherwise - */ - int -insert_reg( - int regname, - int literally_arg) /* insert literally, not as if typed */ -{ - long i; - int retval = OK; - char_u *arg; - int allocated; - int literally = literally_arg; - - /* - * It is possible to get into an endless loop by having CTRL-R a in - * register a and then, in insert mode, doing CTRL-R a. - * If you hit CTRL-C, the loop will be broken here. - */ - ui_breakcheck(); - if (got_int) - return FAIL; - - /* check for valid regname */ - if (regname != NUL && !valid_yank_reg(regname, FALSE)) - return FAIL; - -#ifdef FEAT_CLIPBOARD - regname = may_get_selection(regname); -#endif - - if (regname == '.') /* insert last inserted text */ - retval = stuff_inserted(NUL, 1L, TRUE); - else if (get_spec_reg(regname, &arg, &allocated, TRUE)) - { - if (arg == NULL) - return FAIL; - stuffescaped(arg, literally); - if (allocated) - vim_free(arg); - } - else /* name or number register */ - { - if (get_yank_register(regname, FALSE)) - literally = TRUE; - if (y_current->y_array == NULL) - retval = FAIL; - else - { - for (i = 0; i < y_current->y_size; ++i) - { - stuffescaped(y_current->y_array[i], literally); - /* - * Insert a newline between lines and after last line if - * y_type is MLINE. - */ - if (y_current->y_type == MLINE || i < y_current->y_size - 1) - stuffcharReadbuff('\n'); - } - } - } - - return retval; -} - /* * Stuff a string into the typeahead buffer, such that edit() will insert it * literally ("literally" TRUE) or interpret is as typed characters. */ - static void + void stuffescaped(char_u *arg, int literally) { int c; @@ -1498,242 +719,6 @@ stuffescaped(char_u *arg, int literally) } /* - * If "regname" is a special register, return TRUE and store a pointer to its - * value in "argp". - */ - int -get_spec_reg( - int regname, - char_u **argp, - int *allocated, /* return: TRUE when value was allocated */ - int errmsg) /* give error message when failing */ -{ - int cnt; - - *argp = NULL; - *allocated = FALSE; - switch (regname) - { - case '%': /* file name */ - if (errmsg) - check_fname(); /* will give emsg if not set */ - *argp = curbuf->b_fname; - return TRUE; - - case '#': /* alternate file name */ - *argp = getaltfname(errmsg); /* may give emsg if not set */ - return TRUE; - -#ifdef FEAT_EVAL - case '=': /* result of expression */ - *argp = get_expr_line(); - *allocated = TRUE; - return TRUE; -#endif - - case ':': /* last command line */ - if (last_cmdline == NULL && errmsg) - emsg(_(e_nolastcmd)); - *argp = last_cmdline; - return TRUE; - - case '/': /* last search-pattern */ - if (last_search_pat() == NULL && errmsg) - emsg(_(e_noprevre)); - *argp = last_search_pat(); - return TRUE; - - case '.': /* last inserted text */ - *argp = get_last_insert_save(); - *allocated = TRUE; - if (*argp == NULL && errmsg) - emsg(_(e_noinstext)); - return TRUE; - -#ifdef FEAT_SEARCHPATH - case Ctrl_F: /* Filename under cursor */ - case Ctrl_P: /* Path under cursor, expand via "path" */ - if (!errmsg) - return FALSE; - *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP - | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); - *allocated = TRUE; - return TRUE; -#endif - - case Ctrl_W: /* word under cursor */ - case Ctrl_A: /* WORD (mnemonic All) under cursor */ - if (!errmsg) - return FALSE; - cnt = find_ident_under_cursor(argp, regname == Ctrl_W - ? (FIND_IDENT|FIND_STRING) : FIND_STRING); - *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; - *allocated = TRUE; - return TRUE; - - case Ctrl_L: /* Line under cursor */ - if (!errmsg) - return FALSE; - - *argp = ml_get_buf(curwin->w_buffer, - curwin->w_cursor.lnum, FALSE); - return TRUE; - - case '_': /* black hole: always empty */ - *argp = (char_u *)""; - return TRUE; - } - - return FALSE; -} - -/* - * Paste a yank register into the command line. - * Only for non-special registers. - * Used by CTRL-R command in command-line mode - * insert_reg() can't be used here, because special characters from the - * register contents will be interpreted as commands. - * - * return FAIL for failure, OK otherwise - */ - int -cmdline_paste_reg( - int regname, - int literally_arg, /* Insert text |