Loading ...
Sorry, an error occurred while loading the content.
 

Re: getline, setline

Expand Messages
  • Bram Moolenaar
    ... This is inconsistent. Same for line2byte() and synID(). These all take a line number argument, they should work in the same way. Try out this patch: ...
    Message 1 of 2 , Jan 28, 2000
      Ralf Arens wrote:

      > is there a reason that
      >
      > let text = getline(".")
      >
      > works and
      >
      > call setline(".", text)
      >
      > doesn't?
      >
      > I would find it more consistent if they behaved the same.

      This is inconsistent. Same for line2byte() and synID(). These all take a
      line number argument, they should work in the same way.

      Try out this patch:

      *** ../vim-5.6/src/eval.c Sun Jan 16 22:41:05 2000
      --- src/eval.c Fri Jan 28 20:58:14 2000
      ***************
      *** 143,148 ****
      --- 143,149 ----
      static int get_env_var __ARGS((char_u **arg, VAR retvar, int evaluate));
      static int find_internal_func __ARGS((char_u *name));
      static int get_func_var __ARGS((char_u *name, int len, VAR retvar, char_u **arg, linenr_t firstline, linenr_t lastline, int *doesrange, int evaluate));
      + static linenr_t get_arg_lnum __ARGS((VAR argvars, VAR retvar));
      static void f_append __ARGS((VAR argvars, VAR retvar));
      static void f_argc __ARGS((VAR argvars, VAR retvar));
      static void f_argv __ARGS((VAR argvars, VAR retvar));
      ***************
      *** 2133,2147 ****
      return ret;
      }

      - /*********************************************
      - * Implementation of the built-in functions
      - */
      -
      /*
      ! * "append(lnum, string)" function
      */
      ! static void
      ! f_append(argvars, retvar)
      VAR argvars;
      VAR retvar;
      {
      --- 2134,2144 ----
      return ret;
      }

      /*
      ! * Get the lnum from the first argument. Also accepts ".", "$", etc.
      */
      ! static linenr_t
      ! get_arg_lnum(argvars, retvar)
      VAR argvars;
      VAR retvar;
      {
      ***************
      *** 2154,2159 ****
      --- 2151,2174 ----
      lnum = retvar->var_val.var_number;
      clear_var(retvar);
      }
      + return lnum;
      + }
      +
      + /*********************************************
      + * Implementation of the built-in functions
      + */
      +
      + /*
      + * "append(lnum, string)" function
      + */
      + static void
      + f_append(argvars, retvar)
      + VAR argvars;
      + VAR retvar;
      + {
      + long lnum;
      +
      + lnum = get_arg_lnum(argvars, retvar);
      retvar->var_val.var_number = 1; /* Default: Failed */

      if (lnum >= 0 && lnum <= curbuf->b_ml.ml_line_count
      ***************
      *** 2747,2760 ****
      linenr_t lnum;
      char_u *p;

      ! lnum = get_var_number(&argvars[0]);
      ! if (lnum == 0) /* no valid number, try using line() */
      ! {
      ! f_line(argvars, retvar);
      ! lnum = retvar->var_val.var_number;
      ! clear_var(retvar);
      ! }
      !
      if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
      p = ml_get(lnum);
      else
      --- 2762,2768 ----
      linenr_t lnum;
      char_u *p;

      ! lnum = get_arg_lnum(argvars, retvar);
      if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
      p = ml_get(lnum);
      else
      ***************
      *** 3390,3396 ****
      #else
      linenr_t lnum;

      ! lnum = get_var_number(&argvars[0]);
      if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count + 1)
      retvar->var_val.var_number = -1;
      else
      --- 3398,3404 ----
      #else
      linenr_t lnum;

      ! lnum = get_arg_lnum(argvars, retvar);
      if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count + 1)
      retvar->var_val.var_number = -1;
      else
      ***************
      *** 3598,3604 ****
      linenr_t lnum;
      char_u *line;

      ! lnum = get_var_number(&argvars[0]);
      line = get_var_string(&argvars[1]);
      retvar->var_val.var_number = 1; /* FAIL is default */

      --- 3606,3612 ----
      linenr_t lnum;
      char_u *line;

      ! lnum = get_arg_lnum(argvars, retvar);
      line = get_var_string(&argvars[1]);
      retvar->var_val.var_number = 1; /* FAIL is default */

      ***************
      *** 3722,3728 ****
      long col;
      int trans;

      ! line = get_var_number(&argvars[0]);
      col = get_var_number(&argvars[1]) - 1;
      trans = get_var_number(&argvars[2]);

      --- 3730,3736 ----
      long col;
      int trans;

      ! line = get_arg_lnum(argvars, retvar);
      col = get_var_number(&argvars[1]) - 1;
      trans = get_var_number(&argvars[2]);


      --
      CRONE: Who sent you?
      ARTHUR: The Knights Who Say Ni!
      CRONE: Aaaagh! (she looks around in rear) No! We have no shrubberies here.
      "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

      /-/-- Bram Moolenaar --- Bram@... --- http://www.moolenaar.net --\-\
      \ \ Vim: http://www.vim.org ICCF Holland: http://www.vim.org/iccf / /
    Your message has been successfully submitted and would be delivered to recipients shortly.