Patch 8.2.4180
Problem:    'balloonexpr' is evaluated in the current script context.
Solution:   Use the script context where the option was set.
Files:      src/beval.c, src/option.c, src/proto/option.pro,
            src/testdir/test_balloon.vim,
            src/testdir/dumps/Test_balloon_eval_term_01.dump,
            src/testdir/dumps/Test_balloon_eval_term_01a.dump,
            src/testdir/dumps/Test_balloon_eval_term_02.dump


*** ../vim-8.2.4179/src/beval.c 2021-12-09 10:50:48.562865618 +0000
--- src/beval.c 2022-01-22 15:06:42.909532848 +0000
***************
*** 259,264 ****
--- 259,266 ----
                                                    : wp->w_buffer->b_p_bexpr;
        if (*bexpr != NUL)
        {
+           sctx_T      save_sctx = current_sctx;
+ 
            // Convert window pointer to number.
            for (cw = firstwin; cw != wp; cw = cw->w_next)
                ++winnr;
***************
*** 284,289 ****
--- 286,301 ----
                ++sandbox;
            ++textwinlock;
  
+           if (bexpr == p_bexpr)
+           {
+               sctx_T *sp = get_option_sctx("balloonexpr");
+ 
+               if (sp != NULL)
+                   current_sctx = *sp;
+           }
+           else
+               current_sctx = curbuf->b_p_script_ctx[BV_BEXPR];
+ 
            vim_free(result);
            result = eval_to_string(bexpr, TRUE);
  
***************
*** 300,305 ****
--- 312,318 ----
            if (use_sandbox)
                --sandbox;
            --textwinlock;
+           current_sctx = save_sctx;
  
            set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
            if (result != NULL && result[0] != NUL)
*** ../vim-8.2.4179/src/option.c        2022-01-21 16:31:06.299109897 +0000
--- src/option.c        2022-01-22 14:50:03.791004000 +0000
***************
*** 2615,2620 ****
--- 2615,2635 ----
  }
  
  /*
+  * Get the script context of global option "name".
+  *
+  */
+     sctx_T *
+ get_option_sctx(char *name)
+ {
+     int idx = findoption((char_u *)name);
+ 
+     if (idx >= 0)
+       return &options[idx].script_ctx;
+     siemsg("no such option: %s", name);
+     return NULL;
+ }
+ 
+ /*
   * Set the script_ctx for a termcap option.
   * "name" must be the two character code, e.g. "RV".
   * When "name" is NULL use "opt_idx".
*** ../vim-8.2.4179/src/proto/option.pro        2022-01-15 10:00:59.576603900 
+0000
--- src/proto/option.pro        2022-01-22 14:49:03.468207282 +0000
***************
*** 22,27 ****
--- 22,28 ----
  void redraw_titles(void);
  int valid_name(char_u *val, char *allowed);
  void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
+ sctx_T *get_option_sctx(char *name);
  void set_term_option_sctx_idx(char *name, int opt_idx);
  void check_redraw(long_u flags);
  int findoption(char_u *arg);
*** ../vim-8.2.4179/src/testdir/test_balloon.vim        2020-08-12 
17:50:31.871655841 +0100
--- src/testdir/test_balloon.vim        2022-01-22 15:06:08.246282155 +0000
***************
*** 10,16 ****
  
  let s:common_script =<< trim [CODE]
    call setline(1, ["one one one", "two tXo two", "three three three"])
!   set balloonevalterm balloonexpr=MyBalloonExpr() balloondelay=100
    func MyBalloonExpr()
      return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ":\n" .. 
v:beval_text
    endfun
--- 10,17 ----
  
  let s:common_script =<< trim [CODE]
    call setline(1, ["one one one", "two tXo two", "three three three"])
!   set balloonevalterm balloonexpr=MyBalloonExpr()..s:trailing balloondelay=100
!   let s:trailing = '<'  " check that script context is set
    func MyBalloonExpr()
      return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ":\n" .. 
v:beval_text
    endfun
*** ../vim-8.2.4179/src/testdir/dumps/Test_balloon_eval_term_01.dump    
2020-06-09 14:57:32.929019414 +0100
--- src/testdir/dumps/Test_balloon_eval_term_01.dump    2022-01-22 
15:03:39.581527357 +0000
***************
*** 2,8 ****
  |t|w|o| |t|X|o| |t|w|o| @38
  |t|h|r|e| +0#0000001#ffd7ff255@17| +0#0000000#ffffff0@27
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255|l|i|n|e| |2| |c|o|l|u|m|n| |6|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|t|X|o| @13| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
--- 2,8 ----
  |t|w|o| |t|X|o| |t|w|o| @38
  |t|h|r|e| +0#0000001#ffd7ff255@17| +0#0000000#ffffff0@27
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255|l|i|n|e| |2| |c|o|l|u|m|n| |6|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|t|X|o|<| @12| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
*** ../vim-8.2.4179/src/testdir/dumps/Test_balloon_eval_term_01a.dump   
2020-06-09 14:57:32.929019414 +0100
--- src/testdir/dumps/Test_balloon_eval_term_01a.dump   2022-01-22 
15:04:43.496125408 +0000
***************
*** 2,8 ****
  |t|w|o| |t|X|o| |t|w|o| @38
  |t|h|r|e| +0#0000001#ffd7ff255@17| +0#0000000#ffffff0@27
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255|l|i|n|e| |2| |c|o|l|u|m|n| |6|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|t|X|o| @13| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
--- 2,8 ----
  |t|w|o| |t|X|o| |t|w|o| @38
  |t|h|r|e| +0#0000001#ffd7ff255@17| +0#0000000#ffffff0@27
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255|l|i|n|e| |2| |c|o|l|u|m|n| |6|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|t|X|o|<| @12| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
*** ../vim-8.2.4179/src/testdir/dumps/Test_balloon_eval_term_02.dump    
2020-06-09 14:57:32.929019414 +0100
--- src/testdir/dumps/Test_balloon_eval_term_02.dump    2022-01-22 
15:05:20.367321435 +0000
***************
*** 3,9 ****
  |t|h|r|e|e+0&#e0e0e08| |t|h>r+0&#ffffff0|e@1| |t|h|r|e@1| @32
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255|l|i|n|e| |3| |c|o|l|u|m|n| |5|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|e| |t|h|r| @11| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
--- 3,9 ----
  |t|h|r|e|e+0&#e0e0e08| |t|h>r+0&#ffffff0|e@1| |t|h|r|e@1| @32
  |~+0#4040ff13&| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255|l|i|n|e| |3| |c|o|l|u|m|n| |5|:| | 
+0#4040ff13#ffffff0@27
! |~| @2| +0#0000001#ffd7ff255|e| |t|h|r|<| @10| +0#4040ff13#ffffff0@27
  |~| @2| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@27
  |~| @48
  |~| @48
*** ../vim-8.2.4179/src/version.c       2022-01-22 13:39:04.107476183 +0000
--- src/version.c       2022-01-22 15:06:58.873188580 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4180,
  /**/

-- 
I wonder, do vegetarians eat fruit bats?

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220122151018.1BC911C11B3%40moolenaar.net.

Raspunde prin e-mail lui