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

[Patch] Fix Count_words()

Expand Messages
  • Ag. D. Hatzimanikas
    Hi, Please issue, ... let count = count + Wordcount(getline(n)) The Wordcount function does not exists. Again from the same function, the count variable is a
    Message 1 of 2 , May 2, 2008
    • 0 Attachment
      Hi,

      Please issue,

      :helpgrep Wordcount


      let count = count + Wordcount(getline(n))

      The Wordcount function does not exists.


      Again from the same function, the "count" variable is a read only, so it
      has to be preceded with an "l:". Funny thing is that the "count" var is
      being mentioned for this same reason in,

      :h l:var

      The attached patch fixes both issues.
      The implementation however to replace the Wordcount function its up to
      you to decide. From my tests returns the same number of words with
      g <CTRL-G>.

      And since we are talking about documentation another minor thing in,

      :h libcall()

      the last example refers to the next function libcallnr().

      Regards,

      Ag.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... It counts white space separated words, but that shouldn t matter in this context. ... I ll move it to there. -- Trees moving back and forth is what makes
      Message 2 of 2 , May 4, 2008
      • 0 Attachment
        Ag. D Hatzimanikas wrote:

        > Please issue,
        >
        > :helpgrep Wordcount
        >
        >
        > let count = count + Wordcount(getline(n))
        >
        > The Wordcount function does not exists.
        >
        >
        > Again from the same function, the "count" variable is a read only, so it
        > has to be preceded with an "l:". Funny thing is that the "count" var is
        > being mentioned for this same reason in,
        >
        > :h l:var
        >
        > The attached patch fixes both issues.
        > The implementation however to replace the Wordcount function its up to
        > you to decide. From my tests returns the same number of words with
        > g <CTRL-G>.

        I think this is a slightly better solution:

        :function Count_words() range
        : let lnum = a:firstline
        : let n = 0
        : while lnum <= a:lastline
        : let n = n + len(split(getline(lnum)))
        : let lnum = lnum + 1
        : endwhile
        : echo "found " . n . " words"
        :endfunction

        It counts white space separated words, but that shouldn't matter in this
        context.

        > And since we are talking about documentation another minor thing in,
        >
        > :h libcall()
        >
        > the last example refers to the next function libcallnr().

        I'll move it to there.

        --
        Trees moving back and forth is what makes the wind blow.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.