aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-02 22:51:08 -0400
committerScott Prager <splinterofchaos@gmail.com>2014-12-11 20:29:59 -0500
commite18538f3ef44ffeea8e0ce4c0797c72d185e6b5c (patch)
tree7b37c645cd4c33aab6feec7d49f080bde38cbed4 /src/nvim/ops.c
parentc6271f57671e9dae22675fc76e1f2e3e30a2bda0 (diff)
downloadrneovim-e18538f3ef44ffeea8e0ce4c0797c72d185e6b5c.tar.gz
rneovim-e18538f3ef44ffeea8e0ce4c0797c72d185e6b5c.tar.bz2
rneovim-e18538f3ef44ffeea8e0ce4c0797c72d185e6b5c.zip
vim-patch:7.4.242
Problem: getreg() does not distinguish between a NL used for a line break and a NL used for a NUL character. Solution: Add another argument to return a list. (ZyX) https://code.google.com/p/vim/source/detail?r=v7-4-242
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c68
1 files changed, 46 insertions, 22 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index c20a017088..04a8a0017d 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4654,30 +4654,42 @@ char_u get_reg_type(int regname, long *reglen)
return MAUTO;
}
-/*
- * Return the contents of a register as a single allocated string.
- * Used for "@r" in expressions and for getreg().
- * Returns NULL for error.
- */
-char_u *
-get_reg_contents (
- int regname,
- int allowexpr, /* allow "=" register */
- int expr_src /* get expression for "=" register */
-)
+/// When `flags` has `kGRegList` return a list with text `s`.
+/// Otherwise just return `s`.
+static char_u *get_reg_wrap_one_line(char_u *s, int flags)
+{
+ if (!(flags & kGRegList)) {
+ return s;
+ }
+ list_T *list = list_alloc();
+ list_append_string(list, NULL, -1);
+ list->lv_first->li_tv.vval.v_string = s;
+ return (char_u *)list;
+}
+
+/// Gets the contents of a register.
+/// @remark Used for `@r` in expressions and for `getreg()`.
+///
+/// @param regname The register.
+/// @param flags see @ref GRegFlags
+///
+/// @returns The contents of the register as an allocated string.
+/// @returns A linked list cast to a string when given @ref kGRegList.
+/// @returns NULL for error.
+// TODO(SplinterOfChaos): Maybe this should return a void*.
+char_u *get_reg_contents(int regname, int flags)
{
long i;
- char_u *retval;
- int allocated;
- /* Don't allow using an expression register inside an expression */
+ // Don't allow using an expression register inside an expression.
if (regname == '=') {
- if (allowexpr) {
- if (expr_src)
- return get_expr_line_src();
- return get_expr_line();
+ if (flags & kGRegNoExpr) {
+ return NULL;
}
- return NULL;
+ if (flags & kGRegExprSrc) {
+ return get_reg_wrap_one_line(get_expr_line_src(), flags);
+ }
+ return get_reg_wrap_one_line(get_expr_line(), flags);
}
if (regname == '@') /* "@@" is used for unnamed register */
@@ -4689,18 +4701,30 @@ get_reg_contents (
get_clipboard(regname);
+ char_u *retval;
+ int allocated;
if (get_spec_reg(regname, &retval, &allocated, FALSE)) {
if (retval == NULL)
return NULL;
- if (!allocated)
- retval = vim_strsave(retval);
- return retval;
+ if (allocated) {
+ return get_reg_wrap_one_line(retval, flags);
+ }
+ return get_reg_wrap_one_line(vim_strsave(retval), flags);
}
get_yank_register(regname, FALSE);
if (y_current->y_array == NULL)
return NULL;
+ if (flags & kGRegList) {
+ list_T *list = list_alloc();
+ for (int i = 0; i < y_current->y_size; ++i) {
+ list_append_string(list, y_current->y_array[i], -1);
+ }
+
+ return (char_u *) list;
+ }
+
/*
* Compute length of resulting string.
*/