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

matchit: problem when matching end of function in matlab

Expand Messages
  • seth
    hi! i want to use matchit to match begin and end of functions in matlab. the begin is indicated by keyword function . the end is implicitly defined by next
    Message 1 of 5 , Feb 1, 2008
    • 0 Attachment
      hi!

      i want to use "matchit" to match begin and end of functions in matlab.
      the begin is indicated by keyword "function". the end is implicitly
      defined by next occurrence of "function" or end-of-file, whatever comes
      first. example:

      function foo
      'something'
      'something else'

      function bar
      'begin of bar'
      'end of bar'

      now i wanna match the beginning of functions and their implicit end.
      therefore i tried

      let b:match_words = '\<function\>:\%$\|\_.\%(\s*\<function\>\)\@='

      begin = word "function"
      end = eof or
      a place followed by optional spaces and the word "function"

      but that end does not work as i want, because even if the cursor is at
      'something' or somewhere at 'begin of bar' and i press '%', the cursor
      jumps to the previous "function".
      but i expected: no moving of cursor.
      what did i do wrong?


      background (jfyi):
      /ftplugin/matlab.vim needs to be revised and i could do that partially
      already, but there are still some problems.
      in matlab every function may be ended by "end", but it many cases this
      "end" may be omitted. but this is something i want to examine lateron.

      tia!
      seth

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Szabolcs
      ... This is not entirely correct ... A function can be terminated with end , and nested functions are legal: function y = myfun(x) function h = g(k) h = k*k;
      Message 2 of 5 , Feb 1, 2008
      • 0 Attachment
        On Feb 1, 3:55 pm, seth <vim_3...@...> wrote:
        >
        > i want to use "matchit" to match begin and end of functions in matlab.
        > the begin is indicated by keyword "function". the end is implicitly
        > defined by next occurrence of "function" or end-of-file, whatever comes
        > first. example:

        This is not entirely correct ...

        A function can be terminated with "end", and nested functions are
        legal:

        function y = myfun(x)

        function h = g(k)
        h = k*k;
        end

        y = g(x);

        end
        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • seth
        hi! ... of course. ... i just wanted to simplify my question as much as possible. and so the answer of A.Politz was the clarification i needed. prosit seth
        Message 3 of 5 , Feb 1, 2008
        • 0 Attachment
          hi!

          Szabolcs wrote:
          > On Feb 1, 3:55 pm, seth <vim_3...@...> wrote:
          >
          >> i want to use "matchit" to match begin and end of functions in
          >> matlab. the begin is indicated by keyword "function". the end is
          >> implicitly defined by next occurrence of "function" or end-of-file,
          >> whatever comes first. [...]
          >
          > This is not entirely correct ...
          >
          > A function can be terminated with "end", and nested functions are
          > legal:
          >
          > function y = myfun(x)
          >
          > function h = g(k) h = k*k; end
          >
          > y = g(x);
          >
          > end

          of course.
          you did not read my whole message. i wrote:
          >> in matlab every function may be ended by "end", but it many cases
          >> this "end" may be omitted. but this is something i want to examine
          >> later on.

          i just wanted to simplify my question as much as possible. and so the
          answer of A.Politz was the clarification i needed.

          prosit
          seth

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • A.Politz
          ... Sadly it was entirely wrong. I am sorry. The reason why the cursor is moved without beeing on a match_word is, that the plugin chooses the best match,
          Message 4 of 5 , Feb 7, 2008
          • 0 Attachment
            seth wrote:

            >hi!
            >
            >Szabolcs wrote:
            >
            >
            >>On Feb 1, 3:55 pm, seth <vim_3...@...> wrote:
            >>
            >>
            >>
            >>>i want to use "matchit" to match begin and end of functions in
            >>>matlab. the begin is indicated by keyword "function". the end is
            >>>implicitly defined by next occurrence of "function" or end-of-file,
            >>>whatever comes first. [...]
            >>>
            >>>
            >>This is not entirely correct ...
            >>
            >>A function can be terminated with "end", and nested functions are
            >>legal:
            >>
            >>function y = myfun(x)
            >>
            >>function h = g(k) h = k*k; end
            >>
            >>y = g(x);
            >>
            >>end
            >>
            >>
            >
            >of course.
            >you did not read my whole message. i wrote:
            >
            >
            >>>in matlab every function may be ended by "end", but it many cases
            >>>this "end" may be omitted. but this is something i want to examine
            >>>later on.
            >>>
            >>>
            >
            >i just wanted to simplify my question as much as possible. and so the
            >answer of A.Politz was the clarification i needed.
            >
            >
            >
            >
            Sadly it was entirely wrong. I am sorry. The reason why the cursor
            is moved without beeing on a match_word is, that the plugin chooses
            the "best" match, rather than doing nothing. Take a look at ':h
            matchit-choose'


            -ap


            --
            :wq


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • seth
            hi! ... well, i read :h matchit-choose already, but i still don t know, why the following is happening: ... if true foo end function bar baz ... with the
            Message 5 of 5 , Feb 11, 2008
            • 0 Attachment
              hi!

              A.Politz wrote:
              > seth wrote:
              >>i just wanted to simplify my question as much as possible. and so the
              >>answer of A.Politz was the clarification i needed.
              >
              > Sadly it was entirely wrong. I am sorry. The reason why the cursor
              > is moved without beeing on a match_word is, that the plugin chooses
              > the "best" match, rather than doing nothing. Take a look at ':h
              > matchit-choose'

              well, i read ":h matchit-choose" already, but i still don't know, why
              the following is happening:

              let's use this matlab-code:

              --------%<--------
              if true
              foo
              end

              function bar
              baz
              -------->%--------

              with the matchit-code:
              let b:match_words = '\<if\>:\<end\>,\<function\>:\%$'

              now let the cursor be somewhere at "foo" and now press "%"
              -> nothing will happen.

              but if the cursor is at "b" in "baz",
              -> cursor will jump to the beginning of the function.

              your first anwser, that matchit can only match linewise, seemed more
              plausible. was that wrong?

              prost
              seth

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