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

Enhancements to the winnr() function

Expand Messages
  • Yegappan Lakshmanan
    Hi all, The winnr() function currently returns only the current window number. It is cumbersome to determine the last window number or the previously accessed
    Message 1 of 3 , Aug 31, 2003
      Hi all,

      The winnr() function currently returns only the current window
      number. It is cumbersome to determine the last window number or
      the previously accessed window number. The attached patch
      enhances the winnr() function to return these values.

      winnr() (to be backward compatible)
      winnr("")
      winnr("%") - Return the current window number.
      winnr("$") - Return the last window number.
      winnr("#") - Return the previously accessed window number.

      - Yegappan

      ----------------------------------------------------------------
      *** src/eval.c.orig Fri May 30 12:11:19 2003
      --- src/eval.c Sun Aug 31 17:59:32 2003
      ***************
      *** 2818,2824 ****
      {"wincol", 0, 0, f_wincol},
      {"winheight", 1, 1, f_winheight},
      {"winline", 0, 0, f_winline},
      ! {"winnr", 0, 0, f_winnr},
      {"winwidth", 1, 1, f_winwidth},
      };

      --- 2818,2824 ----
      {"wincol", 0, 0, f_wincol},
      {"winheight", 1, 1, f_winheight},
      {"winline", 0, 0, f_winline},
      ! {"winnr", 0, 1, f_winnr},
      {"winwidth", 1, 1, f_winwidth},
      };

      ***************
      *** 7193,7200 ****
      int nr = 1;
      #ifdef FEAT_WINDOWS
      win_T *wp;

      ! for (wp = firstwin; wp != curwin; wp = wp->w_next)
      ++nr;
      #endif
      retvar->var_val.var_number = nr;
      --- 7193,7219 ----
      int nr = 1;
      #ifdef FEAT_WINDOWS
      win_T *wp;
      + char_u *name;
      + win_T *search_wp;

      ! if (argvars[0].var_type != VAR_UNKNOWN)
      ! name = argvars[0].var_val.var_string;
      ! else
      ! name = NULL;
      !
      ! search_wp = NULL;
      ! if ((name == NULL) || (*name == NUL) || (name[0] == '%'))
      ! search_wp = curwin;
      ! else if ((name[0] == '#') && (prevwin != NULL))
      ! search_wp = prevwin;
      ! else if (name[0] == '$')
      ! search_wp = lastwin;
      ! else {
      ! retvar->var_val.var_number = -1;
      ! return;
      ! }
      !
      ! for (wp = firstwin; wp != search_wp; wp = wp->w_next)
      ++nr;
      #endif
      retvar->var_val.var_number = nr;
      *** runtime/doc/eval.txt.orig Sun Jun 1 05:45:23 2003
      --- runtime/doc/eval.txt Sun Aug 31 18:01:06 2003
      ***************
      *** 2572,2579 ****
      the window. The first line is one.

      *winnr()*
      ! winnr() The result is a Number, which is the number of the
      current
      ! window. The top window has number 1.

      winwidth({nr}) *winwidth()*
      The result is a Number, which is the width of window {nr}.
      --- 2572,2583 ----
      the window. The first line is one.

      *winnr()*
      ! winnr([expr]) The result is a Number, which is the number of the window
      ! specified by {expr}. The top window has number 1. If {expr}
      ! is not specified or if the {expr} is either "" or "%", then
      ! the current window number is returned. If {expr} is "$", then
      ! the last window number is returned. If {expr} is "#", then
      ! the previously accessed window number is returned.

      winwidth({nr}) *winwidth()*
      The result is a Number, which is the width of window {nr}.



      __________________________________
      Do you Yahoo!?
      Yahoo! SiteBuilder - Free, easy-to-use web site design software
      http://sitebuilder.yahoo.com
    • Yegappan Lakshmanan
      A small addition in the patch to the eval.txt help file below. ... If an invalid {expr} is specified, then -1 is returned. - Yegappan ...
      Message 2 of 3 , Aug 31, 2003
        A small addition in the patch to the eval.txt help file below.

        --- Yegappan Lakshmanan <yegappan@...> wrote:
        > Hi all,
        >
        > The winnr() function currently returns only the current window
        > number. It is cumbersome to determine the last window number or
        > the previously accessed window number. The attached patch
        > enhances the winnr() function to return these values.
        >
        > winnr() (to be backward compatible)
        > winnr("")
        > winnr("%") - Return the current window number.
        > winnr("$") - Return the last window number.
        > winnr("#") - Return the previously accessed window number.
        >
        > - Yegappan
        >
        > ----------------------------------------------------------------
        > *** src/eval.c.orig Fri May 30 12:11:19 2003
        > --- src/eval.c Sun Aug 31 17:59:32 2003
        > ***************
        > *** 2818,2824 ****
        > {"wincol", 0, 0, f_wincol},
        > {"winheight", 1, 1, f_winheight},
        > {"winline", 0, 0, f_winline},
        > ! {"winnr", 0, 0, f_winnr},
        > {"winwidth", 1, 1, f_winwidth},
        > };
        >
        > --- 2818,2824 ----
        > {"wincol", 0, 0, f_wincol},
        > {"winheight", 1, 1, f_winheight},
        > {"winline", 0, 0, f_winline},
        > ! {"winnr", 0, 1, f_winnr},
        > {"winwidth", 1, 1, f_winwidth},
        > };
        >
        > ***************
        > *** 7193,7200 ****
        > int nr = 1;
        > #ifdef FEAT_WINDOWS
        > win_T *wp;
        >
        > ! for (wp = firstwin; wp != curwin; wp = wp->w_next)
        > ++nr;
        > #endif
        > retvar->var_val.var_number = nr;
        > --- 7193,7219 ----
        > int nr = 1;
        > #ifdef FEAT_WINDOWS
        > win_T *wp;
        > + char_u *name;
        > + win_T *search_wp;
        >
        > ! if (argvars[0].var_type != VAR_UNKNOWN)
        > ! name = argvars[0].var_val.var_string;
        > ! else
        > ! name = NULL;
        > !
        > ! search_wp = NULL;
        > ! if ((name == NULL) || (*name == NUL) || (name[0] == '%'))
        > ! search_wp = curwin;
        > ! else if ((name[0] == '#') && (prevwin != NULL))
        > ! search_wp = prevwin;
        > ! else if (name[0] == '$')
        > ! search_wp = lastwin;
        > ! else {
        > ! retvar->var_val.var_number = -1;
        > ! return;
        > ! }
        > !
        > ! for (wp = firstwin; wp != search_wp; wp = wp->w_next)
        > ++nr;
        > #endif
        > retvar->var_val.var_number = nr;
        > *** runtime/doc/eval.txt.orig Sun Jun 1 05:45:23 2003
        > --- runtime/doc/eval.txt Sun Aug 31 18:01:06 2003
        > ***************
        > *** 2572,2579 ****
        > the window. The first line is one.
        >
        > *winnr()*
        > ! winnr() The result is a Number, which is the number of the
        > current
        > ! window. The top window has number 1.
        >
        > winwidth({nr}) *winwidth()*
        > The result is a Number, which is the width of window {nr}.
        > --- 2572,2583 ----
        > the window. The first line is one.
        >
        > *winnr()*
        > ! winnr([expr]) The result is a Number, which is the number of the window
        > ! specified by {expr}. The top window has number 1. If {expr}
        > ! is not specified or if the {expr} is either "" or "%", then
        > ! the current window number is returned. If {expr} is "$", then
        > ! the last window number is returned. If {expr} is "#", then
        > ! the previously accessed window number is returned.

        If an invalid {expr} is specified, then -1 is returned.

        - Yegappan

        >
        > winwidth({nr}) *winwidth()*
        > The result is a Number, which is the width of window {nr}.
        >
        >
        >


        __________________________________
        Do you Yahoo!?
        Yahoo! SiteBuilder - Free, easy-to-use web site design software
        http://sitebuilder.yahoo.com
      • Bram Moolenaar
        ... Looks OK to me. Nikolai Weibull made a similar patch a while ago, but I still didn t include it. This one goes in the todo list, bug fixing has priority.
        Message 3 of 3 , Sep 1, 2003
          Yegappan Lakshmanan wrote:

          > The winnr() function currently returns only the current window
          > number. It is cumbersome to determine the last window number or
          > the previously accessed window number. The attached patch
          > enhances the winnr() function to return these values.
          >
          > winnr() (to be backward compatible)
          > winnr("")
          > winnr("%") - Return the current window number.
          > winnr("$") - Return the last window number.
          > winnr("#") - Return the previously accessed window number.

          Looks OK to me. Nikolai Weibull made a similar patch a while ago, but I
          still didn't include it. This one goes in the todo list, bug fixing has
          priority.

          --
          Linux is just like a wigwam: no Windows, no Gates and an Apache inside.

          /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
          /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
          \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
          \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
        Your message has been successfully submitted and would be delivered to recipients shortly.