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

Re: Any way to get vim recognize emacs modeline?

Expand Messages
  • Charles E. Campbell, Jr.
    ... You can always write your own modeline handler. General procedure: (untested) a) au BufRead,BufNewFile * call MyOwnModelineHandler() goes into your
    Message 1 of 7 , Mar 2, 2006
    • 0 Attachment
      panshizhu@... wrote:

      >such as the following:
      >
      >// -*- C++ -*-
      >
      >I don't use emacs, but many source files have this, since the standard C++
      >header does not had any "extension" in the filename, it is impossible for
      >Vim getting it's filetype right.
      >
      >Can Vim recognize the standard C++ header files "by default"?
      >
      >

      You can always write your own modeline handler. General procedure:
      (untested)

      a) au BufRead,BufNewFile * call MyOwnModelineHandler()
      goes into your <.vimrc>

      b) write MyOwnModelineHandler(). Do something like

      fun! MyOwnModelineHandler()
      let mp1= &modelines + 1
      let modeline= search('^\%<'.mpl.'l//-\*- ','W')
      if !modeline
      let mpend= line("$") - &modelines - 1
      let modeline= search('^\%>'.mpend.'l//-\*-','W')
      endif
      if modeline
      ---interpret and do whatever---
      endif
      endfun

      Place the function in your .vimrc or in your .vim/plugin directory.

      Enjoy!
      Chip Campbell
    • Benji Fisher
      ... An alternative to (b) is to use the generic modeline handler in foo.vim, my file of example vim scripts: http://www.vim.org/script.php?script_id=72 As I
      Message 2 of 7 , Mar 2, 2006
      • 0 Attachment
        On Thu, Mar 02, 2006 at 09:34:58PM -0500, Charles E. Campbell, Jr. wrote:
        > panshizhu@... wrote:
        >
        > >such as the following:
        > >
        > >// -*- C++ -*-
        > >
        > >I don't use emacs, but many source files have this, since the standard C++
        > >header does not had any "extension" in the filename, it is impossible for
        > >Vim getting it's filetype right.
        > >
        > >Can Vim recognize the standard C++ header files "by default"?
        > >
        > >
        >
        > You can always write your own modeline handler. General procedure:
        > (untested)
        >
        > a) au BufRead,BufNewFile * call MyOwnModelineHandler()
        > goes into your <.vimrc>
        >
        > b) write MyOwnModelineHandler(). Do something like

        An alternative to (b) is to use the generic modeline handler in
        foo.vim, my file of example vim scripts:

        http://www.vim.org/script.php?script_id=72

        As I edit this file, the "C++" line is Line 6, so

        :echo GetModelines('-\*- \(.\{-}\) -\*-')

        returns "6:C++". So something like

        au BufRead,BufNewFile * if GetModelines('-\*- \(.\{-}\) -\*-') == 'C++' |
        \ setf cpp | endif

        should work.

        HTH --Benji Fisher
      • Bram Moolenaar
        ... The problem is that the names in this header don t match with the Vim filetype names. It would require a translation table. And that probably won t be
        Message 3 of 7 , Mar 3, 2006
        • 0 Attachment
          Shizhu Pan wrote:

          > such as the following:
          >
          > // -*- C++ -*-
          >
          > I don't use emacs, but many source files have this, since the standard C++
          > header does not had any "extension" in the filename, it is impossible for
          > Vim getting it's filetype right.
          >
          > Can Vim recognize the standard C++ header files "by default"?

          The problem is that the names in this header don't match with the Vim
          filetype names. It would require a translation table. And that
          probably won't be fixed but needs regular updating. And allow the user
          to modify it. Not really simple and not fully reliable.

          --
          Q. What happens to programmers when they die?
          A: MS-Windows programmers are reinstalled. C++ programmers become undefined,
          anyone who refers to them will die as well. Java programmers reincarnate
          after being garbage collected.

          /// 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://www.ICCF.nl ///
        • panshizhu@routon.com
          ... That is the problem, but bear in mind that the all standard C++ headers like iostream, cstdio, etc., has no extensions in the file name. Since that is
          Message 4 of 7 , Mar 5, 2006
          • 0 Attachment
            Bram@... wrote on 2006.03.03 20:08:38:
            >
            > Shizhu Pan wrote:
            > > Can Vim recognize the standard C++ header files "by default"?
            >
            > The problem is that the names in this header don't match with the Vim
            > filetype names. It would require a translation table. And that
            > probably won't be fixed but needs regular updating. And allow the user
            > to modify it. Not really simple and not fully reliable.
            >
            > --

            That is the problem, but bear in mind that the all standard C++ headers
            like iostream, cstdio, etc., has no "extensions" in the file name.

            Since that is the "standard" form of C++ header file, I think there should
            be a "standard" way that Vim can recognize the standard C++ header file as
            C++.

            Any hint?
          • Thomas Adam
            ... You re wanting to recognise the filetype based on content, rather than extension? That might be tricky, given certain (and different) semantics used. The
            Message 5 of 7 , Mar 5, 2006
            • 0 Attachment
              --- panshizhu@... wrote:
              > Bram@... wrote on 2006.03.03 20:08:38:
              > >
              > > Shizhu Pan wrote:
              > > > Can Vim recognize the standard C++ header files "by default"?
              > >
              > > The problem is that the names in this header don't match with the Vim
              > > filetype names. It would require a translation table. And that
              > > probably won't be fixed but needs regular updating. And allow the user
              > > to modify it. Not really simple and not fully reliable.
              > >
              > > --
              >
              > That is the problem, but bear in mind that the all standard C++ headers
              > like iostream, cstdio, etc., has no "extensions" in the file name.

              You're wanting to recognise the filetype based on content, rather than
              extension? That might be tricky, given certain (and different) semantics
              used. The fact that most header files end in .h is sufficient in this case.

              -- Thomas Adam




              ___________________________________________________________
              Win a BlackBerry device from O2 with Yahoo!. Enter now. http://www.yahoo.co.uk/blackberry
            • thomas scott urban
              ... Something like this in your vimrc might help you: autocmd BufRead,BufNewFile /usr/include/c++/** setfiletype cpp I also set ts=8 in my modeline for the GCC
              Message 6 of 7 , Mar 6, 2006
              • 0 Attachment
                On Fri, 2006-03-03 at 09:50 +0800, panshizhu@... wrote:
                > such as the following:
                >
                > // -*- C++ -*-
                >
                > I don't use emacs, but many source files have this, since the standard C++
                > header does not had any "extension" in the filename, it is impossible for
                > Vim getting it's filetype right.
                >
                > Can Vim recognize the standard C++ header files "by default"?

                Something like this in your vimrc might help you:

                autocmd BufRead,BufNewFile /usr/include/c++/** setfiletype cpp

                I also set ts=8 in my modeline for the GCC c++ headers in the same line.



                If you have C++ std headers or other emacs tags you're worried about,
                then the other post might be more helpful.
              Your message has been successfully submitted and would be delivered to recipients shortly.