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

Weird errors on :exec in :com on strings referencing script variables

Expand Messages
  • Preben 'Peppe' Guldberg
    I have noticed that an :exec as part of a :command defined in a different script which references a script local variable some times works, sometimes not. It
    Message 1 of 2 , Aug 28, 2003
    • 0 Attachment
      I have noticed that an :exec as part of a :command defined in a
      different script which references a script local variable some times
      works, sometimes not. It took me a while to drum up a reproducable
      example that will eventually work on some systems.

      Anyway, my test setup contains three files. The first one holds these
      functions and command:

      " ==== fun.vim ====
      com! VarVal echo 's:var = ' . s:var

      The other script calls :VarVal

      " ==== ex.vim ====
      echo '=== ' . g:counter . ' ==='
      let s:var = 'Script variable'
      VarVal
      echo 'Third time lucky'

      And finally a script to write and source both of these files a few
      times:

      " === run.vim
      let g:counter = 1 | e fun.vim | w | e ex.vim | w | so # | so %
      let g:counter = 2 | e fun.vim | w | e ex.vim | w | so # | so %
      let g:counter = 3 | e fun.vim | w | e ex.vim | w | so # | so %

      As best as I can determine, writing and sourceing both files is required
      three times before I don't get the error below.

      Invoked as

      $ vim -u NONE -N -c 'so run.vim'

      the result on a "FreeBSD 4.7-RELEASE-p13 i386" machine is this:

      "ex.vim" 4L, 94C written
      === 1 ===
      Error detected while processing ex.vim:
      line 3:
      E121: Undefined variable: s:var
      E15: Invalid expression: 's:var = ' . s:var
      "ex.vim" 4L, 94C written
      === 2 ===
      E121: Undefined variable: s:var
      E15: Invalid expression: 's:var = ' . s:var
      "ex.vim" 4L, 94C written
      === 3 ===
      s:var = Script variable
      Third time lucky

      :version output for the vim is

      VIM - Vi IMproved 6.2 (2003 Jun 1, compiled Aug 28 2003 21:32:15)
      Included patches: 1-71
      Compiled by peppe@...
      Normal version without GUI. Features included (+) or not (-):
      -arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset
      +cindent -clientserver -clipboard +cmdline_compl +cmdline_hist
      +cmdline_info +comments +cryptv -cscope +dialog_con +diff +digraphs
      -dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi
      +file_in_path +find_in_path +folding -footer +fork() +gettext
      -hangul_input -iconv +insert_expand +jumplist -keymap -langmap +libcall
      +linebreak +lispindent +listcmds +localmap +menu +mksession
      +modify_fname +mouse -mouseshape -mouse_dec -mouse_gpm -mouse_jsbterm
      -mouse_netterm +mouse_xterm -multi_byte +multi_lang -netbeans_intg
      -osfiletype +path_extra -perl +postscript +printer -python +quickfix
      -rightleft -ruby +scrollbind -signs +smartindent -sniff +statusline
      -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl
      +terminfo +termresponse +textobjects +title -toolbar +user_commands
      +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace
      +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
      -xterm_clipboard -xterm_save
      system vimrc file: "$VIM/vimrc"
      user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
      fall-back for $VIM: "/usr/local/share/vim"
      Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include
      -g -O2
      Linking:
      gcc -L/usr/local/lib -o vim -lncurses -lposix1e -lintl



      It seems machine dependent whether it will work eventually or not. I am
      sure I saw the same on a Solaris 8 machine with vim 6.2.14. On a Mac OS
      X 10.2.6 I keep getting E121 and E15 no matter how many times the
      edit/write/source cycle appears in run.vim.

      Note that joining run.vim and ex.vim in one file and sourcing it works
      fine.

      I'd appreciate any feedback on this, as I am rather stumped.

      Peppe
      --
      se nocp cpo=BceFsx!$ sh=/bin/sh hid bs=2 ic scs hls ai isf-== hi=100
      filetype plugin indent on | syn on | se lz ls=2 ru so=4 noea fdo-=block
      cno <C-A> <C-B>
      omap S V/\n^-- $\\|\%$/<CR>
    • Bram Moolenaar
      ... In the scripts you give :exec isn t used. You probably mean using :source . ... [...] ... I get the same thing three times. This is on FreeBSD 4.8. I
      Message 2 of 2 , Sep 2, 2003
      • 0 Attachment
        Preben Guldberg wrote:

        > I have noticed that an :exec as part of a :command defined in a
        > different script which references a script local variable some times
        > works, sometimes not. It took me a while to drum up a reproducable
        > example that will eventually work on some systems.

        In the scripts you give ":exec" isn't used. You probably mean using
        ":source".

        > Anyway, my test setup contains three files. The first one holds these
        > functions and command:
        [...]

        > the result on a "FreeBSD 4.7-RELEASE-p13 i386" machine is this:

        I get the same thing three times. This is on FreeBSD 4.8.

        I can't explain that the behavior changes after doing it two times. I
        checked that the script ID is properly restored after a failed command.
        Hopefully this is not a compiler bug. Did you try removing "-O2" from
        the compilation command?

        > It seems machine dependent whether it will work eventually or not. I am
        > sure I saw the same on a Solaris 8 machine with vim 6.2.14. On a Mac OS
        > X 10.2.6 I keep getting E121 and E15 no matter how many times the
        > edit/write/source cycle appears in run.vim.

        The features Vim was compiled with might matter. I tried with and
        without GUI but that didn't make a change for me.

        --
        TALL KNIGHT: We shall say Ni! again to you if you do not appease us.
        ARTHUR: All right! What do you want?
        TALL KNIGHT: We want ... a shrubbery!
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// 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 here: http://ICCF-Holland.org/click1.html ///
      Your message has been successfully submitted and would be delivered to recipients shortly.