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

Re: syntax auto detect

Expand Messages
  • Gary Johnson
    ... You might also open $VIMRUNTIME/filetype.vim and search for .cmd to see how vim distinguishes rexx files from dosbatch files that share the .cmd suffix.
    Message 1 of 15 , Apr 30, 2008
    • 0 Attachment
      On 2008-04-25, zhengquan <zhang.zhengquan@...> wrote:
      > Hello,
      > I wonder if vim can auto detect filetypes.
      > I want to edit some .cmd files which are actually scheme scripts.
      >
      > I can not add mode lines to the files because they will cause trouble
      > when read by other programs. I also do not want to use autocmd to
      > autodetect .cmd extensions. I would like to know if there are some
      > smarter mechanisms for auto detecting filetypes.

      :help new-filetype-scripts

      You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
      to see how vim distinguishes rexx files from dosbatch files that
      share the .cmd suffix. You could create your own
      ~/.vim/filetype.vim and add similar logic to detect scheme files.
      See

      :help new-filetype

      HTH,
      Gary


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • zhengquan
      Thanks, I originally thought the modeline could not be put behind comment indicators. Zhengquan ... --~--~---------~--~----~------------~-------~--~----~ You
      Message 2 of 15 , May 1, 2008
      • 0 Attachment
        Thanks, I originally thought the modeline could not be put behind
        comment indicators.

        Zhengquan

        On Apr 26, 9:59 am, "Benjamin Fritz" <fritzophre...@...> wrote:
        > On 4/25/08, zhengquan <zhang.zhengq...@...> wrote:
        >
        >
        >
        > > Hello,
        > > I wonder if vim can auto detect filetypes.
        > > I want to edit some .cmd files which are actually scheme scripts.
        >
        > > I can not add mode lines to the files because they will cause trouble
        > > when read by other programs. I also do not want to use autocmd to
        > > autodetect .cmd extensions. I would like to know if there are some
        > > smarter mechanisms for auto detecting filetypes.
        >
        > > Thanks.
        >
        > Why would mode lines cause trouble with other programs? You just put
        > them into code comments, which should be ignored by other programs.
        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • zhengquan
        Thanks! Zhengquan ... --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information, visit
        Message 3 of 15 , May 1, 2008
        • 0 Attachment
          Thanks!

          Zhengquan

          On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
          > On 2008-04-25, zhengquan <zhang.zhengq...@...> wrote:
          >
          > > Hello,
          > > I wonder if vim can auto detect filetypes.
          > > I want to edit some .cmd files which are actually scheme scripts.
          >
          > > I can not add mode lines to the files because they will cause trouble
          > > when read by other programs. I also do not want to use autocmd to
          > > autodetect .cmd extensions. I would like to know if there are some
          > > smarter mechanisms for auto detecting filetypes.
          >
          > :help new-filetype-scripts
          >
          > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
          > to see how vim distinguishes rexx files from dosbatch files that
          > share the .cmd suffix. You could create your own
          > ~/.vim/filetype.vim and add similar logic to detect scheme files.
          > See
          >
          > :help new-filetype
          >
          > HTH,
          > Gary
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... Well, in fact they were _meant_ to be placed in comments, so as not to be detected as errors by a compiler. I believe that the existence of two kinds of
          Message 4 of 15 , May 1, 2008
          • 0 Attachment
            On 02/05/08 00:17, zhengquan wrote:
            > Thanks, I originally thought the modeline could not be put behind
            > comment indicators.
            >
            > Zhengquan

            Well, in fact they were _meant_ to be placed in comments, so as not to
            be detected as errors by a compiler. I believe that the existence of two
            kinds of modelines is due to the existence of two kinds of comments:

            to-EOL

            # vim: et tw=78
            // vim: noignorecase

            start-and-end

            /* vim: set noet ts=8 sts=4 :*/
            <!-- vim: set et sts=2 :-->


            Best regards,
            Tony.
            --
            If all the world's economists were laid end to end, we wouldn't reach a
            conclusion.
            -- William Baumol

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • zhengquan
            Thanks, that is really nice. Best regards, Zhengquan On May 1, 6:26 pm, Tony Mechelynck ...
            Message 5 of 15 , May 2, 2008
            • 0 Attachment
              Thanks, that is really nice.

              Best regards,
              Zhengquan

              On May 1, 6:26 pm, Tony Mechelynck <antoine.mechely...@...>
              wrote:
              > On 02/05/08 00:17, zhengquan wrote:
              >
              > > Thanks, I originally thought the modeline could not be put behind
              > > comment indicators.
              >
              > > Zhengquan
              >
              > Well, in fact they were _meant_ to be placed in comments, so as not to
              > be detected as errors by a compiler. I believe that the existence of two
              > kinds of modelines is due to the existence of two kinds of comments:
              >
              > to-EOL
              >
              > # vim: et tw=78
              > // vim: noignorecase
              >
              > start-and-end
              >
              > /* vim: set noet ts=8 sts=4 :*/
              > <!-- vim: set et sts=2 :-->
              >
              > Best regards,
              > Tony.
              > --
              > If all the world's economists were laid end to end, we wouldn't reach a
              > conclusion.
              > -- William Baumol
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • zhengquan
              Hello, I saw the detection method in filetype.vim It peeks the first line to see what it is, I wonder if there are smarter and more automatic ways to detect
              Message 6 of 15 , May 23, 2008
              • 0 Attachment
                Hello,
                I saw the detection method in filetype.vim
                It peeks the first line to see what it is, I wonder if there are
                smarter and more automatic ways to detect the syntax and tell what the
                filetype is.

                Thanks.
                Zhengquan

                On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                >
                > > Hello,
                > > I wonder if vim can auto detect filetypes.
                > > I want to edit some .cmd files which are actually scheme scripts.
                >
                > > I can not add mode lines to the files because they will cause trouble
                > > when read by other programs. I also do not want to use autocmd to
                > > autodetect .cmd extensions. I would like to know if there are some
                > > smarter mechanisms for auto detecting filetypes.
                >
                > :help new-filetype-scripts
                >
                > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                > to see how vim distinguishes rexx files from dosbatch files that
                > share the .cmd suffix. You could create your own
                > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                > See
                >
                > :help new-filetype
                >
                > HTH,
                > Gary
                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Benjamin Fritz
                ... The most automatic way is file extension (or file name in the case of makefiles). If you can t detect it by file extension, then the only other method
                Message 7 of 15 , May 23, 2008
                • 0 Attachment
                  On 5/23/08, zhengquan <zhang.zhengquan@...> wrote:
                  >
                  > Hello,
                  > I saw the detection method in filetype.vim
                  > It peeks the first line to see what it is, I wonder if there are
                  > smarter and more automatic ways to detect the syntax and tell what the
                  > filetype is.
                  >
                  > Thanks.
                  > Zhengquan
                  >
                  > On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                  > > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                  > >
                  > > > Hello,
                  > > > I wonder if vim can auto detect filetypes.
                  > > > I want to edit some .cmd files which are actually scheme scripts.
                  > >
                  > > > I can not add mode lines to the files because they will cause trouble
                  > > > when read by other programs. I also do not want to use autocmd to
                  > > > autodetect .cmd extensions. I would like to know if there are some
                  > > > smarter mechanisms for auto detecting filetypes.
                  > >
                  > > :help new-filetype-scripts
                  > >
                  > > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                  > > to see how vim distinguishes rexx files from dosbatch files that
                  > > share the .cmd suffix. You could create your own
                  > > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                  > > See
                  > >
                  > > :help new-filetype
                  > >
                  > > HTH,
                  > > Gary
                  > >
                  >

                  The most automatic way is file extension (or file name in the case of
                  makefiles).

                  If you can't detect it by file extension, then the only other method
                  possible is to look at the file contents. You could detect a special
                  language construct that is very likely to occur in every file of its
                  type, or you can look at the first line which will sometimes tell you
                  what type of file it is.

                  What other method were you thinking of? What do you mean by a "smarter" method?

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Tony Mechelynck
                  ... It all depends on the syntax, I think, and filetype.vim does quite a good job. For some types, like *.c, *.cpp, *.htm, *.html, *.vim, vimrc, fstab, etc.,
                  Message 8 of 15 , May 23, 2008
                  • 0 Attachment
                    On 23/05/08 23:46, zhengquan wrote:
                    > Hello,
                    > I saw the detection method in filetype.vim
                    > It peeks the first line to see what it is, I wonder if there are
                    > smarter and more automatic ways to detect the syntax and tell what the
                    > filetype is.
                    >
                    > Thanks.
                    > Zhengquan

                    It all depends on the syntax, I think, and filetype.vim does quite a
                    good job. For some types, like *.c, *.cpp, *.htm, *.html, *.vim, vimrc,
                    fstab, etc., the mere name of the file, or even part of it, is enough to
                    determine the filetype, and in those cases filetype.vim uses that. For
                    other filetypes, that's not enough: for example, Unix shell scripts can
                    have any name, so something else must be used to define them. Checking
                    them for "executable" permissions wouldn't work, since on Unix, binary
                    executables also have those permissions and can also have any name
                    (unlike on Windows, where *.bat and sometimes *.btm are shell scripts,
                    while *.exe and sometimes *.dll, *.com, etc., are binary executables).
                    Happily Unix shell scripts usually have #! followed by the shell name in
                    their first line, so that's a good criterion for that filetype.

                    Best regards,
                    Tony.
                    --
                    We must remember the First Amendment which protects any shrill jackass
                    no matter how self-seeking.
                    -- F. G. Withington

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Gary Johnson
                    ... How much more automatic can you get? As for smarter, the only information there is is the file s name and its contents. Vim will sometimes examine more
                    Message 9 of 15 , May 23, 2008
                    • 0 Attachment
                      On 2008-05-23, zhengquan <zhang.zhengquan@...> wrote:

                      > On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                      > > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                      > >
                      > > > Hello,
                      > > > I wonder if vim can auto detect filetypes.
                      > > > I want to edit some .cmd files which are actually scheme scripts.
                      > >
                      > > > I can not add mode lines to the files because they will cause trouble
                      > > > when read by other programs. I also do not want to use autocmd to
                      > > > autodetect .cmd extensions. I would like to know if there are some
                      > > > smarter mechanisms for auto detecting filetypes.
                      > >
                      > > :help new-filetype-scripts
                      > >
                      > > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                      > > to see how vim distinguishes rexx files from dosbatch files that
                      > > share the .cmd suffix. You could create your own
                      > > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                      > > See
                      > >
                      > > :help new-filetype

                      > Hello,
                      > I saw the detection method in filetype.vim
                      > It peeks the first line to see what it is, I wonder if there are
                      > smarter and more automatic ways to detect the syntax and tell what the
                      > filetype is.

                      How much more automatic can you get? As for smarter, the only
                      information there is is the file's name and its contents. Vim will
                      sometimes examine more than the first line of a file to try to
                      determine its contents, especially if the file name has no suffix at
                      all. See $VIMRUNTIME/scripts.vim.

                      Regards,
                      Gary


                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • zhengquan
                      Thanks, that makes sense to me. Regards, Zhengquan On May 23, 5:09 pm, Tony Mechelynck ...
                      Message 10 of 15 , May 23, 2008
                      • 0 Attachment
                        Thanks, that makes sense to me.

                        Regards,
                        Zhengquan

                        On May 23, 5:09 pm, Tony Mechelynck <antoine.mechely...@...>
                        wrote:
                        > On 23/05/08 23:46, zhengquan wrote:
                        >
                        > > Hello,
                        > > I saw the detection method in filetype.vim
                        > > It peeks the first line to see what it is, I wonder if there are
                        > > smarter and more automatic ways to detect the syntax and tell what the
                        > > filetype is.
                        >
                        > > Thanks.
                        > > Zhengquan
                        >
                        > It all depends on the syntax, I think, and filetype.vim does quite a
                        > good job. For some types, like *.c, *.cpp, *.htm, *.html, *.vim, vimrc,
                        > fstab, etc., the mere name of the file, or even part of it, is enough to
                        > determine the filetype, and in those cases filetype.vim uses that. For
                        > other filetypes, that's not enough: for example, Unix shell scripts can
                        > have any name, so something else must be used to define them. Checking
                        > them for "executable" permissions wouldn't work, since on Unix, binary
                        > executables also have those permissions and can also have any name
                        > (unlike on Windows, where *.bat and sometimes *.btm are shell scripts,
                        > while *.exe and sometimes *.dll, *.com, etc., are binary executables).
                        > Happily Unix shell scripts usually have #! followed by the shell name in
                        > their first line, so that's a good criterion for that filetype.
                        >
                        > Best regards,
                        > Tony.
                        > --
                        > We must remember the First Amendment which protects any shrill jackass
                        > no matter how self-seeking.
                        > -- F. G. Withington
                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • zhengquan
                        In fact I have lots of command file ending with cmd, but the contents in it are quite different. One of them looks like this, I guess I will have to write the
                        Message 11 of 15 , May 23, 2008
                        • 0 Attachment
                          In fact I have lots of command file ending with cmd, but the contents
                          in
                          it are quite different. One of them looks like this, I guess I will
                          have
                          to write the syntax for that though I know nothing about it at the
                          moment. Do you think it takes long to write syntax for that?

                          Thanks.
                          Zhengquan

                          #----------------------------------------------------------------------
                          #
                          #-Setting global variable:
                          #set Vdd 1.5

                          #----------------------------------------------------------------------
                          #
                          #-Conditional setting of local variables:
                          #if @Vd@ < 0.1
                          #define _TRANSMOD_ * DriftDiffusion
                          #define _DRIVINGFORCE_ GradQuasiFermi
                          #define _B2BAVAL_ * No band-to-band and impact ionization
                          #define _EQUATIONS_ Poisson Electron Hole

                          #else
                          #define _TRANSMOD_ Hydrodynamics( eTemperature )
                          #define _DRIVINGFORCE_ CarrierTempDrive
                          #define _B2BAVAL_ Band2Band(E2) Avalanche(CarrierTempDrive)
                          #define _EQUATIONS_ Poisson Electron Hole eTemperature

                          #endif
                          #----------------------------------------------------------------------
                          #

                          Electrode{
                          { Name="source" Voltage= 0.0 Resistor= 40 }
                          { Name="drain" Voltage= 0.0 Resistor= 40 }
                          { Name="gate" Voltage=-0.1 }
                          { Name="substrate" Voltage= 0.0 }
                          #-Conditional inclusion of code:
                          #if [string compare @Body@ "Tied"] == 0
                          { Name="bodytie" Voltage=0.0 eRecVelocity=0 }
                          #endif
                          }

                          File{
                          #-Predefined GENESISe paranmeters
                          Grid = "@tdr@"
                          Plot = "@tdrdat@"
                          Current = "@plot@"
                          Output = "@log@"
                          Param = "@parameter@"
                          }

                          Physics{
                          #-Using local variables:
                          _TRANSMOD_
                          eQCvanDort
                          EffectiveIntrinsicDensity( OldSlotboom )
                          Recombination( SRH(DopingDep) )
                          }

                          Physics(Material="Silicon"){
                          Mobility(
                          PhuMob
                          eHighFieldsaturation( _DRIVINGFORCE_ )
                          hHighFieldsaturation( GradQuasiFermi )
                          Enormal
                          )
                          Recombination(
                          SRH( DopingDep )
                          _B2BAVAL_
                          )
                          }

                          Plot{
                          *--Density and Currents, etc
                          eDensity hDensity
                          TotalCurrent/Vector eCurrent/Vector hCurrent/Vector
                          eMobility hMobility
                          eVelocity hVelocity
                          eQuasiFermi hQuasiFermi

                          *--Temperature
                          eTemperature * Temperature hTemperature

                          *--Fields and charges
                          ElectricField/Vector Potential SpaceCharge

                          *--Doping Profiles
                          Doping DonorConcentration AcceptorConcentration

                          *--Generation/Recombination
                          SRH Band2Band * Auger
                          AvalancheGeneration eAvalancheGeneration hAvalancheGeneration

                          *--Driving forces
                          eGradQuasiFermi/Vector hGradQuasiFermi/Vector
                          eEparallel hEparallel eENormal hENormal

                          *--Band structure/Composition
                          BandGap
                          BandGapNarrowing
                          Affinity
                          ConductionBand ValenceBand

                          *--Traps
                          * eTrappedCharge hTrappedCharge
                          * eGapStatesRecombination hGapStatesRecombination
                          }

                          Math {
                          Extrapolate
                          Avalderivatives
                          RelErrControl
                          Digits=5
                          ErRef(electron)=1.e10
                          ErRef(hole)=1.e10
                          Notdamped=50
                          Iterations=20
                          DirectCurrent
                          }

                          Solve {
                          NewCurrentFile="init"
                          Coupled(Iterations=100){ Poisson }
                          Coupled{ Poisson Electron Hole }

                          Quasistationary(
                          InitialStep=1e-1 Increment=1.2
                          Minstep=1e-5 MaxStep=0.1
                          Goal{ Name="drain" Voltage= @Vd@ }
                          ){ Coupled{ _EQUATIONS_ } }

                          NewCurrentFile=""

                          Quasistationary(
                          DoZero
                          InitialStep=5e-2 Increment=1.5
                          Minstep=1e-5 MaxStep=0.05
                          Goal{ Name="gate" Voltage= @Vdd@ }
                          ){ Coupled{ _EQUATIONS_ }
                          #-Arithmatic with variables: enforcing ~0.1V steps for all values of
                          Vdd
                          CurrentPlot( Time=(Range=(0 1) Intervals=@<int(Vdd/0.1)>@ )
                          )
                          }
                          }


                          On May 23, 5:11 pm, Gary Johnson <garyj...@...> wrote:
                          > On 2008-05-23, zhengquan <zhang.zhengq...@...> wrote:
                          >
                          >
                          >
                          > > On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                          > > > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                          >
                          > > > > Hello,
                          > > > > I wonder if vim can auto detect filetypes.
                          > > > > I want to edit some .cmd files which are actually scheme scripts.
                          >
                          > > > > I can not add mode lines to the files because they will cause trouble
                          > > > > when read by other programs. I also do not want to use autocmd to
                          > > > > autodetect .cmd extensions. I would like to know if there are some
                          > > > > smarter mechanisms for auto detecting filetypes.
                          >
                          > > > :help new-filetype-scripts
                          >
                          > > > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                          > > > to see how vim distinguishes rexx files from dosbatch files that
                          > > > share the .cmd suffix. You could create your own
                          > > > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                          > > > See
                          >
                          > > > :help new-filetype
                          > > Hello,
                          > > I saw the detection method in filetype.vim
                          > > It peeks the first line to see what it is, I wonder if there are
                          > > smarter and more automatic ways to detect the syntax and tell what the
                          > > filetype is.
                          >
                          > How much more automatic can you get? As for smarter, the only
                          > information there is is the file's name and its contents. Vim will
                          > sometimes examine more than the first line of a file to try to
                          > determine its contents, especially if the file name has no suffix at
                          > all. See $VIMRUNTIME/scripts.vim.
                          >
                          > Regards,
                          > Gary

                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_use" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        • Gary Johnson
                          ... By saying that the contents of your .cmd files are quite different, do you mean that you think it will be difficult to determine the file type from the
                          Message 12 of 15 , May 23, 2008
                          • 0 Attachment
                            On 2008-05-23, zhengquan <zhang.zhengquan@...> wrote:

                            > On May 23, 5:11 pm, Gary Johnson <garyj...@...> wrote:
                            > > On 2008-05-23, zhengquan <zhang.zhengq...@...> wrote:
                            > >
                            > >
                            > >
                            > > > On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                            > > > > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                            > >
                            > > > > > Hello,
                            > > > > > I wonder if vim can auto detect filetypes.
                            > > > > > I want to edit some .cmd files which are actually scheme scripts.
                            > >
                            > > > > > I can not add mode lines to the files because they will cause trouble
                            > > > > > when read by other programs. I also do not want to use autocmd to
                            > > > > > autodetect .cmd extensions. I would like to know if there are some
                            > > > > > smarter mechanisms for auto detecting filetypes.
                            > >
                            > > > > :help new-filetype-scripts
                            > >
                            > > > > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                            > > > > to see how vim distinguishes rexx files from dosbatch files that
                            > > > > share the .cmd suffix. You could create your own
                            > > > > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                            > > > > See
                            > >
                            > > > > :help new-filetype
                            > > > Hello,
                            > > > I saw the detection method in filetype.vim
                            > > > It peeks the first line to see what it is, I wonder if there are
                            > > > smarter and more automatic ways to detect the syntax and tell what the
                            > > > filetype is.
                            > >
                            > > How much more automatic can you get? As for smarter, the only
                            > > information there is is the file's name and its contents. Vim will
                            > > sometimes examine more than the first line of a file to try to
                            > > determine its contents, especially if the file name has no suffix at
                            > > all. See $VIMRUNTIME/scripts.vim.

                            > In fact I have lots of command file ending with cmd, but the
                            > contents in it are quite different. One of them looks like this, I
                            > guess I will have to write the syntax for that though I know
                            > nothing about it at the moment. Do you think it takes long to
                            > write syntax for that?

                            By saying that the contents of your .cmd files are quite
                            different, do you mean that you think it will be difficult to
                            determine the file type from the contents? If so, one approach to
                            solving the problem would be to search for patterns unique to the
                            _other_ file types that have the .cmd extension, and if none of
                            those patterns match, declare the file to be of your file type. Are
                            we still talking about scheme files?

                            Next, are you asking about writing a syntax for the purpose of
                            highlighting the file, or for the purpose of detecting the file
                            type? For detecting the file type, you don't want to do a very
                            thorough job of analyzing the syntax, you want to look for a simple
                            pattern that distinguishes your file type from any other have that
                            same extension. If you're the only one using this filetype
                            detection scheme, you can even "cheat" and look for patterns that
                            are unique to _your_ style of programming in that language.

                            For example, I don't recall ever seeing a line beginning with *-- in
                            any other language. If all your scheme files contain at least one
                            line like that, you could use a command like "search('^\*--')" and
                            use the result as is $VIMRUNTIME/filetype.vim.

                            How difficult it is to write syntax rules for highlighting a file
                            depends on the complexity of the language and your objectives. It's
                            much easier to write syntax rules that highlight a syntacticly
                            correct file so that it is easier to read than it is to write syntax
                            rules that check for the correctness of the syntax and highlight
                            errors. Even if the language is complex, if you use only a subset
                            of it, then you can get away with writing syntax rules for only that
                            subset.

                            Regards,
                            Gary


                            --~--~---------~--~----~------------~-------~--~----~
                            You received this message from the "vim_use" maillist.
                            For more information, visit http://www.vim.org/maillist.php
                            -~----------~----~----~----~------~----~------~--~---
                          • zhengquan
                            ... yes, some cmd files are actually tcl files, some are scheme files, and some are mesh command files, some are like what I showed, all of them end with .cmd
                            Message 13 of 15 , May 23, 2008
                            • 0 Attachment
                              On May 23, 7:14 pm, Gary Johnson <garyj...@...> wrote:
                              > On 2008-05-23, zhengquan <zhang.zhengq...@...> wrote:
                              >
                              >
                              >
                              > > On May 23, 5:11 pm, Gary Johnson <garyj...@...> wrote:
                              > > > On 2008-05-23, zhengquan <zhang.zhengq...@...> wrote:
                              >
                              > > > > On May 1, 1:45 am, Gary Johnson <garyj...@...> wrote:
                              > > > > > On 2008-04-25,zhengquan<zhang.zhengq...@...> wrote:
                              >
                              > > > > > > Hello,
                              > > > > > > I wonder if vim can auto detect filetypes.
                              > > > > > > I want to edit some .cmd files which are actually scheme scripts.
                              >
                              > > > > > > I can not add mode lines to the files because they will cause trouble
                              > > > > > > when read by other programs. I also do not want to use autocmd to
                              > > > > > > autodetect .cmd extensions. I would like to know if there are some
                              > > > > > > smarter mechanisms for auto detecting filetypes.
                              >
                              > > > > > :help new-filetype-scripts
                              >
                              > > > > > You might also open $VIMRUNTIME/filetype.vim and search for "\.cmd"
                              > > > > > to see how vim distinguishes rexx files from dosbatch files that
                              > > > > > share the .cmd suffix. You could create your own
                              > > > > > ~/.vim/filetype.vim and add similar logic to detect scheme files.
                              > > > > > See
                              >
                              > > > > > :help new-filetype
                              > > > > Hello,
                              > > > > I saw the detection method in filetype.vim
                              > > > > It peeks the first line to see what it is, I wonder if there are
                              > > > > smarter and more automatic ways to detect the syntax and tell what the
                              > > > > filetype is.
                              >
                              > > > How much more automatic can you get? As for smarter, the only
                              > > > information there is is the file's name and its contents. Vim will
                              > > > sometimes examine more than the first line of a file to try to
                              > > > determine its contents, especially if the file name has no suffix at
                              > > > all. See $VIMRUNTIME/scripts.vim.
                              > > In fact I have lots of command file ending with cmd, but the
                              > > contents in it are quite different. One of them looks like this, I
                              > > guess I will have to write the syntax for that though I know
                              > > nothing about it at the moment. Do you think it takes long to
                              > > write syntax for that?
                              >
                              > By saying that the contents of your .cmd files are quite
                              > different, do you mean that you think it will be difficult to
                              > determine the file type from the contents? If so, one approach to
                              > solving the problem would be to search for patterns unique to the
                              > _other_ file types that have the .cmd extension, and if none of
                              > those patterns match, declare the file to be of your file type. Are
                              > we still talking about scheme files?
                              >

                              yes, some cmd files are actually tcl files, some are scheme files, and
                              some are mesh command files, some are like what I showed, all of them
                              end with .cmd .

                              > Next, are you asking about writing a syntax for the purpose of
                              > highlighting the file, or for the purpose of detecting the file
                              > type? For detecting the file type, you don't want to do a very
                              > thorough job of analyzing the syntax, you want to look for a simple
                              > pattern that distinguishes your file type from any other have that
                              > same extension. If you're the only one using this filetype
                              > detection scheme, you can even "cheat" and look for patterns that
                              > are unique to _your_ style of programming in that language.
                              I want to write scripts to detect what are actually tcl, scheme files,
                              since vim has syntax for them. I also want to write scripts to detect
                              the mesh command files and the command files I showed, and I want to
                              write syntax for them. Now I understand what you mean, it is feasible.
                              >
                              > For example, I don't recall ever seeing a line beginning with *-- in
                              > any other language. If all your scheme files contain at least one
                              > line like that, you could use a command like "search('^\*--')" and
                              > use the result as is $VIMRUNTIME/filetype.vim.
                              well, *-- is not unique in this kind of files, the keywords: math,
                              solve,
                              file... are unique to it.
                              >
                              > How difficult it is to write syntax rules for highlighting a file
                              > depends on the complexity of the language and your objectives. It's
                              > much easier to write syntax rules that highlight a syntacticly
                              > correct file so that it is easier to read than it is to write syntax
                              > rules that check for the correctness of the syntax and highlight
                              > errors. Even if the language is complex, if you use only a subset
                              > of it, then you can get away with writing syntax rules for only that
                              > subset.
                              >
                              > Regards,
                              > Gary

                              Thank you very much, Gary.

                              Regards,
                              Zhengquan

                              --~--~---------~--~----~------------~-------~--~----~
                              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.