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

32325Re: bug in explicit :setf behavior?

Expand Messages
  • Bram Moolenaar
    May 1, 2003
    • 0 Attachment
      I wrote to Dorai:

      > > Ability to do :setlocal all< would be a lifesaver.
      > > Once that's in, changing the definition of
      > >
      > > :setf {filetype}
      > >
      > > to be something like
      > >
      > > :if !did_filetype()
      > > : if exists("b:did_ftplugin")
      > > : unlet b:did_ftplugin
      > > : endif
      > > : if exists("b:did_indent")
      > > : unlet b:did_indent
      > > : endif
      > > : setlocal all<
      > > : setlocal filetype={filetype}
      > > :endif
      > >
      > > should all be all that's needed. The old plugin
      > > files wouldn't need to be changed. (If they introduced
      > > let variables and function definitions, those would
      > > stay across filetype changes for the same buffer, but
      > > perhaps that's harmless?)
      >
      > I don't like this, because the order in which things are done will
      > matter, e.g.:
      >
      > :setl tw=55
      > :setf mail
      >
      > Will work differently from:
      >
      > :setf mail
      > :setl tw=55
      >
      > Even when the "mail" filetype plugin doesn't set 'tw'. That is not what
      > people expect.

      A simple solution would be to support the b:undo_ftplugin variable. It
      should be set by the filetype plugin to the commands required to undo
      the settings. I have implemented this for the Vim plugin.

      Note that a bug in the source code needs to be fixed for this to work.
      Apparently nobody tried doing ":setlocal tw<" yet!

      Would there be any problem with this approach?


      *** runtime/ftplugin.vim~ Fri Oct 19 15:21:05 2001
      --- runtime/ftplugin.vim Thu May 1 19:40:27 2003
      ***************
      *** 12,17 ****
      --- 12,21 ----
      au FileType * call s:LoadFTPlugin()
      func! s:LoadFTPlugin()
      if expand("<amatch>") != ""
      + if exists("b:undo_ftplugin")
      + exe b:undo_ftplugin
      + unlet b:undo_ftplugin b:did_ftplugin
      + endif
      if &cpo =~# "S" && exists("b:did_ftplugin")
      " In compatible mode options are reset to the global values, need to
      " set the local values also when a plugin was already used.
      *** runtime/ftplugin/vim.vim~ Fri Apr 25 20:14:38 2003
      --- runtime/ftplugin/vim.vim Thu May 1 19:44:34 2003
      ***************
      *** 11,16 ****
      --- 11,22 ----
      " Don't load another plugin for this buffer
      let b:did_ftplugin = 1

      + let cpo_save = &cpo
      + set cpo-=C
      +
      + let b:undo_ftplugin = "setl fo< com< tw< commentstring<"
      + \ . "| unlet b:match_ignorecase b:match_words b:match_skip"
      +
      " Set 'formatoptions' to break comment lines but not other lines,
      " and insert the comment leader when hitting <CR> or using "o".
      setlocal fo-=t fo+=croql
      ***************
      *** 24,31 ****
      " Comments start with a double quote
      setlocal commentstring=\"%s

      - set cpo-=C
      -
      " Let the matchit plugin know what items can be matched.
      if exists("loaded_matchit")
      let b:match_ignorecase = 0
      --- 30,35 ----
      ***************
      *** 41,43 ****
      --- 45,48 ----
      \ synIDattr(synID(line("."),col("."),1),"name") =~? "comment\\|string"'
      endif

      + let &cpo = cpo_save
      *** src/option.c~ Wed Apr 30 16:39:05 2003
      --- src/option.c Thu May 1 19:51:43 2003
      ***************
      *** 3515,3521 ****
      value = (long)options[opt_idx].def_val[
      ((flags & P_VI_DEF) || cp_val)
      ? VI_DEFAULT : VIM_DEFAULT];
      ! else if (nextchar == '^')
      value = *(long *)get_varp_scope(&(options[opt_idx]),
      OPT_GLOBAL);
      else if (((long *)varp == &p_wc
      --- 3515,3521 ----
      value = (long)options[opt_idx].def_val[
      ((flags & P_VI_DEF) || cp_val)
      ? VI_DEFAULT : VIM_DEFAULT];
      ! else if (nextchar == '<')
      value = *(long *)get_varp_scope(&(options[opt_idx]),
      OPT_GLOBAL);
      else if (((long *)varp == &p_wc

      --
      hundred-and-one symptoms of being an internet addict:
      133. You communicate with people on other continents more than you
      do with your own neighbors.

      /// 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 at Amazon -- http://ICCF.nl/click1.html ///
    • Show all 17 messages in this topic