Mirror of the Vim source from https://github.com/vim/vim
修訂 | 1c586ee8dd452d305bebf633d5b8c78ba1ab170d (tree) |
---|---|
時間 | 2006-01-21 08:10:18 |
作者 | vimboss |
Commiter | vimboss |
updated for version 7.0183
@@ -1,4 +1,4 @@ | ||
1 | -*eval.txt* For Vim version 7.0aa. Last change: 2006 Jan 13 | |
1 | +*eval.txt* For Vim version 7.0aa. Last change: 2006 Jan 20 | |
2 | 2 | |
3 | 3 | |
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -28,6 +28,7 @@ | ||
28 | 28 | 9. Examples |eval-examples| |
29 | 29 | 10. No +eval feature |no-eval-feature| |
30 | 30 | 11. The sandbox |eval-sandbox| |
31 | +12. Textlock |textlock| | |
31 | 32 | |
32 | 33 | {Vi does not have any of these commands} |
33 | 34 |
@@ -6830,5 +6831,33 @@ | ||
6830 | 6831 | option that may have been set from a modeline, e.g. |
6831 | 6832 | 'foldexpr'. |
6832 | 6833 | |
6834 | + *sandbox-option* | |
6835 | +A few options contain an expression. When this expression is evaluated it may | |
6836 | +have to be done in the sandbox to avoid trouble. But the sandbox is | |
6837 | +restrictive, thus this only happens when the option was set from an insecure | |
6838 | +location. Insecure in this context are: | |
6839 | +- sourcing a .vimrc or .exrc in the current directlry | |
6840 | +- while executing in the sandbox | |
6841 | +- value coming from a modeline | |
6842 | + | |
6843 | +Note that when in the sandbox and saving an option value and restoring it, the | |
6844 | +option will still be marked as it was set in the sandbox. | |
6845 | + | |
6846 | +============================================================================== | |
6847 | +12. Textlock *textlock* | |
6848 | + | |
6849 | +In a few situations it is not allowed to change the text in the buffer, jump | |
6850 | +to another window and some other things that might confuse or break what Vim | |
6851 | +is currently doing. This mostly applies to things that happen when Vim is | |
6852 | +actually doing something else. For example, evaluating the 'balloonexpr' may | |
6853 | +happen any moment the mouse cursor is resting at some position. | |
6854 | + | |
6855 | +This is not allowed when the textlock is active: | |
6856 | + - changing the buffer text | |
6857 | + - jumping to another buffer or window | |
6858 | + - editing another file | |
6859 | + - closing a window or quitting Vim | |
6860 | + - etc. | |
6861 | + | |
6833 | 6862 | |
6834 | 6863 | vim:tw=78:ts=8:ft=help:norl: |
@@ -1,4 +1,4 @@ | ||
1 | -*options.txt* For Vim version 7.0aa. Last change: 2006 Jan 19 | |
1 | +*options.txt* For Vim version 7.0aa. Last change: 2006 Jan 20 | |
2 | 2 | |
3 | 3 | |
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -1037,6 +1037,12 @@ | ||
1037 | 1037 | Vim does not try to send a message to an external debugger (Netbeans |
1038 | 1038 | or Sun Workshop). |
1039 | 1039 | |
1040 | + The expression may be evaluated in the |sandbox|, see | |
1041 | + |sandbox-option|. | |
1042 | + | |
1043 | + It is not allowed to change text or jump to another window while | |
1044 | + evaluating 'balloonexpr' |textlock|. | |
1045 | + | |
1040 | 1046 | To check whether line breaks in the balloon text work use this check: > |
1041 | 1047 | if has("balloon_multiline") |
1042 | 1048 | < |
@@ -2771,8 +2777,13 @@ | ||
2771 | 2777 | {not available when compiled without the |+folding| |
2772 | 2778 | or |+eval| feature} |
2773 | 2779 | The expression used for when 'foldmethod' is "expr". It is evaluated |
2774 | - for each line to obtain its fold level. See |fold-expr|. Also see | |
2775 | - |eval-sandbox|. | |
2780 | + for each line to obtain its fold level. See |fold-expr|. | |
2781 | + | |
2782 | + The expression may be evaluated in the |sandbox|, see | |
2783 | + |sandbox-option|. | |
2784 | + | |
2785 | + It is not allowed to change text or jump to another window while | |
2786 | + evaluating 'foldexpr' |textlock|. | |
2776 | 2787 | |
2777 | 2788 | *'foldignore'* *'fdi'* |
2778 | 2789 | 'foldignore' 'fdi' string (default: "#") |
@@ -2904,6 +2915,12 @@ | ||
2904 | 2915 | An expression which is used to specify the text displayed for a closed |
2905 | 2916 | fold. See |fold-foldtext|. |
2906 | 2917 | |
2918 | + The expression may be evaluated in the |sandbox|, see | |
2919 | + |sandbox-option|. | |
2920 | + | |
2921 | + It is not allowed to change text or jump to another window while | |
2922 | + evaluating 'foldtext' |textlock|. | |
2923 | + | |
2907 | 2924 | *'formatoptions'* *'fo'* |
2908 | 2925 | 'formatoptions' 'fo' string (Vim default: "tcq", Vi default: "vt") |
2909 | 2926 | local to buffer |
@@ -3696,11 +3713,17 @@ | ||
3696 | 3713 | option to a file name. Mostly useful to change "." to "/" for Java: > |
3697 | 3714 | :set includeexpr=substitute(v:fname,'\\.','/','g') |
3698 | 3715 | < The "v:fname" variable will be set to the file name that was detected. |
3699 | - Evaluated in the |sandbox|. | |
3716 | + | |
3700 | 3717 | Also used for the |gf| command if an unmodified file name can't be |
3701 | 3718 | found. Allows doing "gf" on the name after an 'include' statement. |
3702 | 3719 | Also used for |<cfile>|. |
3703 | 3720 | |
3721 | + The expression may be evaluated in the |sandbox|, see | |
3722 | + |sandbox-option|. | |
3723 | + | |
3724 | + It is not allowed to change text or jump to another window while | |
3725 | + evaluating 'includeexpr' |textlock|. | |
3726 | + | |
3704 | 3727 | *'incsearch'* *'is'* *'noincsearch'* *'nois'* |
3705 | 3728 | 'incsearch' 'is' boolean (default off) |
3706 | 3729 | global |
@@ -3746,9 +3769,16 @@ | ||
3746 | 3769 | :set indentexpr=GetMyIndent() |
3747 | 3770 | < Error messages will be suppressed, unless the 'debug' option contains |
3748 | 3771 | "msg". |
3749 | - See |indent-expression|. Also see |eval-sandbox|. | |
3772 | + See |indent-expression|. | |
3750 | 3773 | NOTE: This option is made empty when 'compatible' is set. |
3751 | 3774 | |
3775 | + The expression may be evaluated in the |sandbox|, see | |
3776 | + |sandbox-option|. | |
3777 | + | |
3778 | + It is not allowed to change text or jump to another window while | |
3779 | + evaluating 'indentexpr' |textlock|. | |
3780 | + | |
3781 | + | |
3752 | 3782 | *'indentkeys'* *'indk'* |
3753 | 3783 | 'indentkeys' 'indk' string (default "0{,0},:,0#,!^F,o,O,e") |
3754 | 3784 | local to buffer |
@@ -6084,7 +6114,13 @@ | ||
6084 | 6114 | temporarily to that of the window (and buffer) whose statusline is |
6085 | 6115 | currently being drawn. The expression will evaluate in this context. |
6086 | 6116 | The variable "actual_curbuf" is set to the 'bufnr()' number of the |
6087 | - real current buffer. The expression is evaluated in the |sandbox|. | |
6117 | + real current buffer. | |
6118 | + | |
6119 | + The 'statusline' option may be evaluated in the |sandbox|, see | |
6120 | + |sandbox-option|. | |
6121 | + | |
6122 | + It is not allowed to change text or jump to another window while | |
6123 | + evaluating 'statusline' |textlock|. | |
6088 | 6124 | |
6089 | 6125 | If the statusline is not updated when you want it (e.g., after setting |
6090 | 6126 | a variable that's used in an expression), you can force an update by |
@@ -5349,6 +5349,7 @@ | ||
5349 | 5349 | hebrew.txt hebrew.txt /*hebrew.txt* |
5350 | 5350 | help various.txt /*help* |
5351 | 5351 | help-context help.txt /*help-context* |
5352 | +help-tags tags 1 | |
5352 | 5353 | help-translated various.txt /*help-translated* |
5353 | 5354 | help-xterm-window various.txt /*help-xterm-window* |
5354 | 5355 | help.txt help.txt /*help.txt* |
@@ -6404,6 +6405,7 @@ | ||
6404 | 6405 | s:var eval.txt /*s:var* |
6405 | 6406 | s<CR> change.txt /*s<CR>* |
6406 | 6407 | sandbox eval.txt /*sandbox* |
6408 | +sandbox-option eval.txt /*sandbox-option* | |
6407 | 6409 | save-file editing.txt /*save-file* |
6408 | 6410 | save-settings starting.txt /*save-settings* |
6409 | 6411 | scheme.vim syntax.txt /*scheme.vim* |
@@ -6929,6 +6931,7 @@ | ||
6929 | 6931 | tex.vim syntax.txt /*tex.vim* |
6930 | 6932 | text-objects motion.txt /*text-objects* |
6931 | 6933 | text-objects-changed version5.txt /*text-objects-changed* |
6934 | +textlock eval.txt /*textlock* | |
6932 | 6935 | tf.vim syntax.txt /*tf.vim* |
6933 | 6936 | this_session-variable eval.txt /*this_session-variable* |
6934 | 6937 | throw-catch eval.txt /*throw-catch* |
@@ -1,4 +1,4 @@ | ||
1 | -*todo.txt* For Vim version 7.0aa. Last change: 2006 Jan 19 | |
1 | +*todo.txt* For Vim version 7.0aa. Last change: 2006 Jan 20 | |
2 | 2 | |
3 | 3 | |
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -30,20 +30,6 @@ | ||
30 | 30 | *known-bugs* |
31 | 31 | -------------------- Known bugs and current work ----------------------- |
32 | 32 | |
33 | -Evaluate 'balloonexpr' in the sandbox only when it was set from an unsafe | |
34 | -place (e.g., modeline)? Patch from Sumner Hayes, Jan 12. Also use for other | |
35 | -options? | |
36 | - | |
37 | -":saveas asdf.c" should set 'filetype' to c when it's empty. Also for ":w | |
38 | -asdf.c" when it sets the buffer filename. | |
39 | - | |
40 | -When ":cclose" is used the buffer is not wiped out and is no longer recognized | |
41 | -as a quickfix buffer, thus it's not reused either. | |
42 | - | |
43 | -Patch to support lists and dicts for the Python interface. (G. Sumner Hayes, | |
44 | -Jan 12). Docs in a previous patch. | |
45 | -Use free_tv() instead of clear_tv() and vim_free(). | |
46 | - | |
47 | 33 | ccomplete: |
48 | 34 | - When using page-up/page-down in menu it sometimes jumps more than a page. |
49 | 35 | - When an option is set: In completion mode and the user types (identifier) |
@@ -71,9 +57,9 @@ | ||
71 | 57 | Can't reproduce it right now... |
72 | 58 | |
73 | 59 | spelling: |
74 | -- Include script to cleanup a .add file. (Antonio Colombo, Jan 9) | |
75 | -- suggestions for "macARONI" doesn't include "macaroni", they are all allcap. | |
76 | - suggestion for "KG" to "kg" when it's keepcase. | |
60 | +- Use runtime/cleanadd script to cleanup .add files. When to invoke it? | |
61 | + After deleting a word and some timestamp difference perhaps? | |
62 | +- suggestion for "KG" to "kg" when it's keepcase. | |
77 | 63 | - Autocommand event for when a spell file is missing. Allows making a plugin |
78 | 64 | that fetches the file over internet. Pattern == language. |
79 | 65 | - Using KEEPCASE flag still allows all-upper word, docs say it doesn't. |
@@ -1,4 +1,4 @@ | ||
1 | -*version7.txt* For Vim version 7.0aa. Last change: 2006 Jan 19 | |
1 | +*version7.txt* For Vim version 7.0aa. Last change: 2006 Jan 20 | |
2 | 2 | |
3 | 3 | |
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -154,6 +154,9 @@ | ||
154 | 154 | With the |:profile| command you can find out where your function or script |
155 | 155 | wastes its time. |
156 | 156 | |
157 | +In the Python interface vim.eval() also handles Dictionaries and Lists. | |
158 | +|python-eval| (G. Sumner Hayes) | |
159 | + | |
157 | 160 | |
158 | 161 | Spell checking *new-spell* |
159 | 162 | -------------- |
@@ -667,6 +670,15 @@ | ||
667 | 670 | allocated memory, running out of memory can always be detected. Allows |
668 | 671 | matching more complex things, but Vim may seem to hang while doing that. |
669 | 672 | |
673 | +Previously some options were always evaluated in the |sandbox|. Now that only | |
674 | +happens when the option was set from a modeline or in secure mode. Applies to | |
675 | +'balloonexpr', 'foldexpr', 'foldtext' and 'includeexpr'. (Sumner Hayes) | |
676 | + | |
677 | +Some commands and expressions could have nasty side effects, such as using | |
678 | +CTRL-R = while editing a search pattern and the expression invokes a function | |
679 | +that jumps to another window. The |textlock| has been added to prevent this | |
680 | +from happening. | |
681 | + | |
670 | 682 | ":breakadd here" and ":breakdel here" can be used to set or delete a |
671 | 683 | breakpoint at the cursor. |
672 | 684 |
@@ -925,6 +937,10 @@ | ||
925 | 937 | Allow using ":global" in the sandbox, it doesn't do anything harmful by |
926 | 938 | itself. |
927 | 939 | |
940 | +":saveas asdf.c" will set 'filetype' to c when it's empty. Also for ":w | |
941 | +asdf.c" when it sets the filename for the buffer. | |
942 | + | |
943 | + | |
928 | 944 | ============================================================================== |
929 | 945 | COMPILE TIME CHANGES *compile-changes-7* |
930 | 946 |
@@ -1528,8 +1544,8 @@ | ||
1528 | 1544 | |
1529 | 1545 | When evaluating an expression for CTRL-R = on the command line it was possible |
1530 | 1546 | to call a function that opens a new window, resulting in errors for |
1531 | -incremental search, and many other nasty things were possible. Now set | |
1532 | -"cmdline_busy" and disallow changing the buffer or jumpting to another window | |
1547 | +incremental search, and many other nasty things were possible. Now use the | |
1548 | +|textlock| to disallow changing the buffer or jumping to another window | |
1533 | 1549 | to protect from unexpected behavior. Same for CTRL-\ e. |
1534 | 1550 | |
1535 | 1551 | "d(" deleted the character under the cursor, while the documentation specified |
@@ -1574,4 +1590,10 @@ | ||
1574 | 1590 | !cmd foo<Tab>" also escape characters that are special for the shell: |
1575 | 1591 | "!;&()<>". |
1576 | 1592 | |
1593 | +When the name of the buffer was set by a ":r fname" command |cpo-f| no | |
1594 | +autocommands were triggered to notify about the change in the buffer list. | |
1595 | + | |
1596 | +In the quickfix buffer 'bufhidden' was set to "delete", which caused closing | |
1597 | +the quickfix window to leave an unlisted "No Name" buffer behind every time. | |
1598 | + | |
1577 | 1599 | vim:tw=78:ts=8:ft=help:norl: |
@@ -291,7 +291,7 @@ | ||
291 | 291 | #endif |
292 | 292 | /* Don't allow changes in the buffer while editing the cmdline. The |
293 | 293 | * caller of getcmdline() may get confused. */ |
294 | - if (cmdline_busy) | |
294 | + if (textlock != 0) | |
295 | 295 | { |
296 | 296 | EMSG(_(e_secure)); |
297 | 297 | return FALSE; |
@@ -420,8 +420,8 @@ | ||
420 | 420 | static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv)); |
421 | 421 | static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID)); |
422 | 422 | static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2)); |
423 | -static char_u *list2string __ARGS((typval_T *tv)); | |
424 | -static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo)); | |
423 | +static char_u *list2string __ARGS((typval_T *tv, int copyID)); | |
424 | +static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID)); | |
425 | 425 | static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID)); |
426 | 426 | static void set_ref_in_list __ARGS((list_T *l, int copyID)); |
427 | 427 | static void set_ref_in_item __ARGS((typval_T *tv, int copyID)); |
@@ -435,10 +435,10 @@ | ||
435 | 435 | static int dict_add __ARGS((dict_T *d, dictitem_T *item)); |
436 | 436 | static long dict_len __ARGS((dict_T *d)); |
437 | 437 | static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len)); |
438 | -static char_u *dict2string __ARGS((typval_T *tv)); | |
438 | +static char_u *dict2string __ARGS((typval_T *tv, int copyID)); | |
439 | 439 | static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
440 | -static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); | |
441 | -static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf)); | |
440 | +static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); | |
441 | +static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID)); | |
442 | 442 | static char_u *string_quote __ARGS((char_u *str, int function)); |
443 | 443 | static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate)); |
444 | 444 | static int find_internal_func __ARGS((char_u *name)); |
@@ -1175,20 +1175,26 @@ | ||
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | /* |
1178 | - * Call eval_to_string() with "sandbox" set and not using local variables. | |
1178 | + * Call eval_to_string() without using current local variables and using | |
1179 | + * textlock. When "use_sandbox" is TRUE use the sandbox. | |
1179 | 1180 | */ |
1180 | 1181 | char_u * |
1181 | -eval_to_string_safe(arg, nextcmd) | |
1182 | +eval_to_string_safe(arg, nextcmd, use_sandbox) | |
1182 | 1183 | char_u *arg; |
1183 | 1184 | char_u **nextcmd; |
1185 | + int use_sandbox; | |
1184 | 1186 | { |
1185 | 1187 | char_u *retval; |
1186 | 1188 | void *save_funccalp; |
1187 | 1189 | |
1188 | 1190 | save_funccalp = save_funccal(); |
1189 | - ++sandbox; | |
1191 | + if (use_sandbox) | |
1192 | + ++sandbox; | |
1193 | + ++textlock; | |
1190 | 1194 | retval = eval_to_string(arg, nextcmd); |
1191 | - --sandbox; | |
1195 | + if (use_sandbox) | |
1196 | + --sandbox; | |
1197 | + --textlock; | |
1192 | 1198 | restore_funccal(save_funccalp); |
1193 | 1199 | return retval; |
1194 | 1200 | } |
@@ -1566,9 +1572,12 @@ | ||
1566 | 1572 | typval_T tv; |
1567 | 1573 | int retval; |
1568 | 1574 | char_u *s; |
1575 | + int use_sandbox = was_set_insecurely((char_u *)"foldexpr"); | |
1569 | 1576 | |
1570 | 1577 | ++emsg_off; |
1571 | - ++sandbox; | |
1578 | + if (use_sandbox) | |
1579 | + ++sandbox; | |
1580 | + ++textlock; | |
1572 | 1581 | *cp = NUL; |
1573 | 1582 | if (eval0(arg, &tv, NULL, TRUE) == FAIL) |
1574 | 1583 | retval = 0; |
@@ -1591,7 +1600,9 @@ | ||
1591 | 1600 | clear_tv(&tv); |
1592 | 1601 | } |
1593 | 1602 | --emsg_off; |
1594 | - --sandbox; | |
1603 | + if (use_sandbox) | |
1604 | + --sandbox; | |
1605 | + --textlock; | |
1595 | 1606 | |
1596 | 1607 | return retval; |
1597 | 1608 | } |
@@ -1985,7 +1996,7 @@ | ||
1985 | 1996 | int c; |
1986 | 1997 | char_u *s; |
1987 | 1998 | |
1988 | - s = echo_string(&tv, &tf, numbuf); | |
1999 | + s = echo_string(&tv, &tf, numbuf, 0); | |
1989 | 2000 | c = *arg; |
1990 | 2001 | *arg = NUL; |
1991 | 2002 | list_one_var_a((char_u *)"", |
@@ -5310,6 +5321,18 @@ | ||
5310 | 5321 | return item1 == NULL && item2 == NULL; |
5311 | 5322 | } |
5312 | 5323 | |
5324 | +#if defined(FEAT_PYTHON) || defined(PROTO) | |
5325 | +/* | |
5326 | + * Return the dictitem that an entry in a hashtable points to. | |
5327 | + */ | |
5328 | + dictitem_T * | |
5329 | +dict_lookup(hi) | |
5330 | + hashitem_T *hi; | |
5331 | +{ | |
5332 | + return HI2DI(hi); | |
5333 | +} | |
5334 | +#endif | |
5335 | + | |
5313 | 5336 | /* |
5314 | 5337 | * Return TRUE when two dictionaries have exactly the same key/values. |
5315 | 5338 | */ |
@@ -5777,8 +5800,9 @@ | ||
5777 | 5800 | * May return NULL. |
5778 | 5801 | */ |
5779 | 5802 | static char_u * |
5780 | -list2string(tv) | |
5803 | +list2string(tv, copyID) | |
5781 | 5804 | typval_T *tv; |
5805 | + int copyID; | |
5782 | 5806 | { |
5783 | 5807 | garray_T ga; |
5784 | 5808 |
@@ -5786,7 +5810,7 @@ | ||
5786 | 5810 | return NULL; |
5787 | 5811 | ga_init2(&ga, (int)sizeof(char), 80); |
5788 | 5812 | ga_append(&ga, '['); |
5789 | - if (list_join(&ga, tv->vval.v_list, (char_u *)", ", FALSE) == FAIL) | |
5813 | + if (list_join(&ga, tv->vval.v_list, (char_u *)", ", FALSE, copyID) == FAIL) | |
5790 | 5814 | { |
5791 | 5815 | vim_free(ga.ga_data); |
5792 | 5816 | return NULL; |
@@ -5802,11 +5826,12 @@ | ||
5802 | 5826 | * Return FAIL or OK. |
5803 | 5827 | */ |
5804 | 5828 | static int |
5805 | -list_join(gap, l, sep, echo) | |
5829 | +list_join(gap, l, sep, echo, copyID) | |
5806 | 5830 | garray_T *gap; |
5807 | 5831 | list_T *l; |
5808 | 5832 | char_u *sep; |
5809 | 5833 | int echo; |
5834 | + int copyID; | |
5810 | 5835 | { |
5811 | 5836 | int first = TRUE; |
5812 | 5837 | char_u *tofree; |
@@ -5822,9 +5847,9 @@ | ||
5822 | 5847 | ga_concat(gap, sep); |
5823 | 5848 | |
5824 | 5849 | if (echo) |
5825 | - s = echo_string(&item->li_tv, &tofree, numbuf); | |
5826 | - else | |
5827 | - s = tv2string(&item->li_tv, &tofree, numbuf); | |
5850 | + s = echo_string(&item->li_tv, &tofree, numbuf, copyID); | |
5851 | + else | |
5852 | + s = tv2string(&item->li_tv, &tofree, numbuf, copyID); | |
5828 | 5853 | if (s != NULL) |
5829 | 5854 | ga_concat(gap, s); |
5830 | 5855 | vim_free(tofree); |
@@ -6355,8 +6380,9 @@ | ||
6355 | 6380 | * May return NULL. |
6356 | 6381 | */ |
6357 | 6382 | static char_u * |
6358 | -dict2string(tv) | |
6383 | +dict2string(tv, copyID) | |
6359 | 6384 | typval_T *tv; |
6385 | + int copyID; | |
6360 | 6386 | { |
6361 | 6387 | garray_T ga; |
6362 | 6388 | int first = TRUE; |
@@ -6391,7 +6417,7 @@ | ||
6391 | 6417 | vim_free(tofree); |
6392 | 6418 | } |
6393 | 6419 | ga_concat(&ga, (char_u *)": "); |
6394 | - s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf); | |
6420 | + s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID); | |
6395 | 6421 | if (s != NULL) |
6396 | 6422 | ga_concat(&ga, s); |
6397 | 6423 | vim_free(tofree); |
@@ -6535,13 +6561,15 @@ | ||
6535 | 6561 | * If the memory is allocated "tofree" is set to it, otherwise NULL. |
6536 | 6562 | * "numbuf" is used for a number. |
6537 | 6563 | * Does not put quotes around strings, as ":echo" displays values. |
6564 | + * When "copyID" is not NULL replace recursive lists and dicts with "...". | |
6538 | 6565 | * May return NULL; |
6539 | 6566 | */ |
6540 | 6567 | static char_u * |
6541 | -echo_string(tv, tofree, numbuf) | |
6568 | +echo_string(tv, tofree, numbuf, copyID) | |
6542 | 6569 | typval_T *tv; |
6543 | 6570 | char_u **tofree; |
6544 | 6571 | char_u *numbuf; |
6572 | + int copyID; | |
6545 | 6573 | { |
6546 | 6574 | static int recurse = 0; |
6547 | 6575 | char_u *r = NULL; |
@@ -6560,19 +6588,51 @@ | ||
6560 | 6588 | *tofree = NULL; |
6561 | 6589 | r = tv->vval.v_string; |
6562 | 6590 | break; |
6591 | + | |
6563 | 6592 | case VAR_LIST: |
6564 | - *tofree = list2string(tv); | |
6565 | - r = *tofree; | |
6566 | - break; | |
6593 | + if (tv->vval.v_list == NULL) | |
6594 | + { | |
6595 | + *tofree = NULL; | |
6596 | + r = NULL; | |
6597 | + } | |
6598 | + else if (copyID != 0 && tv->vval.v_list->lv_copyID == copyID) | |
6599 | + { | |
6600 | + *tofree = NULL; | |
6601 | + r = (char_u *)"[...]"; | |
6602 | + } | |
6603 | + else | |
6604 | + { | |
6605 | + tv->vval.v_list->lv_copyID = copyID; | |
6606 | + *tofree = list2string(tv, copyID); | |
6607 | + r = *tofree; | |
6608 | + } | |
6609 | + break; | |
6610 | + | |
6567 | 6611 | case VAR_DICT: |
6568 | - *tofree = dict2string(tv); | |
6569 | - r = *tofree; | |
6570 | - break; | |
6612 | + if (tv->vval.v_dict == NULL) | |
6613 | + { | |
6614 | + *tofree = NULL; | |
6615 | + r = NULL; | |
6616 | + } | |
6617 | + else if (copyID != 0 && tv->vval.v_dict->dv_copyID == copyID) | |
6618 | + { | |
6619 | + *tofree = NULL; | |
6620 | + r = (char_u *)"{...}"; | |
6621 | + } | |
6622 | + else | |
6623 | + { | |
6624 | + tv->vval.v_dict->dv_copyID = copyID; | |
6625 | + *tofree = dict2string(tv, copyID); | |
6626 | + r = *tofree; | |
6627 | + } | |
6628 | + break; | |
6629 | + | |
6571 | 6630 | case VAR_STRING: |
6572 | 6631 | case VAR_NUMBER: |
6573 | 6632 | *tofree = NULL; |
6574 | 6633 | r = get_tv_string_buf(tv, numbuf); |
6575 | 6634 | break; |
6635 | + | |
6576 | 6636 | default: |
6577 | 6637 | EMSG2(_(e_intern2), "echo_string()"); |
6578 | 6638 | *tofree = NULL; |
@@ -6590,10 +6650,11 @@ | ||
6590 | 6650 | * May return NULL; |
6591 | 6651 | */ |
6592 | 6652 | static char_u * |
6593 | -tv2string(tv, tofree, numbuf) | |
6653 | +tv2string(tv, tofree, numbuf, copyID) | |
6594 | 6654 | typval_T *tv; |
6595 | 6655 | char_u **tofree; |
6596 | 6656 | char_u *numbuf; |
6657 | + int copyID; | |
6597 | 6658 | { |
6598 | 6659 | switch (tv->v_type) |
6599 | 6660 | { |
@@ -6610,7 +6671,7 @@ | ||
6610 | 6671 | default: |
6611 | 6672 | EMSG2(_(e_intern2), "tv2string()"); |
6612 | 6673 | } |
6613 | - return echo_string(tv, tofree, numbuf); | |
6674 | + return echo_string(tv, tofree, numbuf, copyID); | |
6614 | 6675 | } |
6615 | 6676 | |
6616 | 6677 | /* |
@@ -11302,7 +11363,7 @@ | ||
11302 | 11363 | if (sep != NULL) |
11303 | 11364 | { |
11304 | 11365 | ga_init2(&ga, (int)sizeof(char), 80); |
11305 | - list_join(&ga, argvars[0].vval.v_list, sep, TRUE); | |
11366 | + list_join(&ga, argvars[0].vval.v_list, sep, TRUE, 0); | |
11306 | 11367 | ga_append(&ga, NUL); |
11307 | 11368 | rettv->vval.v_string = (char_u *)ga.ga_data; |
11308 | 11369 | } |
@@ -11695,7 +11756,7 @@ | ||
11695 | 11756 | break; |
11696 | 11757 | } |
11697 | 11758 | vim_free(tofree); |
11698 | - str = echo_string(&li->li_tv, &tofree, strbuf); | |
11759 | + str = echo_string(&li->li_tv, &tofree, strbuf,0); | |
11699 | 11760 | if (str == NULL) |
11700 | 11761 | break; |
11701 | 11762 | } |
@@ -13734,8 +13795,8 @@ | ||
13734 | 13795 | char_u numbuf1[NUMBUFLEN]; |
13735 | 13796 | char_u numbuf2[NUMBUFLEN]; |
13736 | 13797 | |
13737 | - p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1); | |
13738 | - p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2); | |
13798 | + p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1, 0); | |
13799 | + p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2, 0); | |
13739 | 13800 | if (item_compare_ic) |
13740 | 13801 | res = STRICMP(p1, p2); |
13741 | 13802 | else |
@@ -14212,7 +14273,7 @@ | ||
14212 | 14273 | char_u numbuf[NUMBUFLEN]; |
14213 | 14274 | |
14214 | 14275 | rettv->v_type = VAR_STRING; |
14215 | - rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf); | |
14276 | + rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, 0); | |
14216 | 14277 | if (tofree == NULL) |
14217 | 14278 | rettv->vval.v_string = vim_strsave(rettv->vval.v_string); |
14218 | 14279 | } |
@@ -16407,7 +16468,7 @@ | ||
16407 | 16468 | char_u *s; |
16408 | 16469 | char_u numbuf[NUMBUFLEN]; |
16409 | 16470 | |
16410 | - s = echo_string(&v->di_tv, &tofree, numbuf); | |
16471 | + s = echo_string(&v->di_tv, &tofree, numbuf, ++current_copyID); | |
16411 | 16472 | list_one_var_a(prefix, v->di_key, v->di_tv.v_type, |
16412 | 16473 | s == NULL ? (char_u *)"" : s); |
16413 | 16474 | vim_free(tofree); |
@@ -16782,7 +16843,7 @@ | ||
16782 | 16843 | } |
16783 | 16844 | else if (eap->cmdidx == CMD_echo) |
16784 | 16845 | msg_puts_attr((char_u *)" ", echo_attr); |
16785 | - p = echo_string(&rettv, &tofree, numbuf); | |
16846 | + p = echo_string(&rettv, &tofree, numbuf, ++current_copyID); | |
16786 | 16847 | if (p != NULL) |
16787 | 16848 | for ( ; *p != NUL && !got_int; ++p) |
16788 | 16849 | { |
@@ -18499,7 +18560,7 @@ | ||
18499 | 18560 | msg_outnum((long)argvars[i].vval.v_number); |
18500 | 18561 | else |
18501 | 18562 | { |
18502 | - trunc_string(tv2string(&argvars[i], &tofree, numbuf), | |
18563 | + trunc_string(tv2string(&argvars[i], &tofree, numbuf, 0), | |
18503 | 18564 | buf, MSG_BUF_CLEN); |
18504 | 18565 | msg_puts(buf); |
18505 | 18566 | vim_free(tofree); |
@@ -18584,7 +18645,7 @@ | ||
18584 | 18645 | /* The value may be very long. Skip the middle part, so that we |
18585 | 18646 | * have some idea how it starts and ends. smsg() would always |
18586 | 18647 | * truncate it at the end. */ |
18587 | - trunc_string(tv2string(fc.rettv, &tofree, numbuf), | |
18648 | + trunc_string(tv2string(fc.rettv, &tofree, numbuf, 0), | |
18588 | 18649 | buf, MSG_BUF_CLEN); |
18589 | 18650 | smsg((char_u *)_("%s returning %s"), sourcing_name, buf); |
18590 | 18651 | vim_free(tofree); |
@@ -18806,7 +18867,7 @@ | ||
18806 | 18867 | char_u numbuf[NUMBUFLEN]; |
18807 | 18868 | |
18808 | 18869 | if (rettv != NULL) |
18809 | - s = echo_string((typval_T *)rettv, &tofree, numbuf); | |
18870 | + s = echo_string((typval_T *)rettv, &tofree, numbuf, 0); | |
18810 | 18871 | if (s == NULL) |
18811 | 18872 | s = (char_u *)""; |
18812 | 18873 |
@@ -19076,7 +19137,7 @@ | ||
19076 | 19137 | default: continue; |
19077 | 19138 | } |
19078 | 19139 | fprintf(fp, "!%s\t%s\t", this_var->di_key, s); |
19079 | - p = echo_string(&this_var->di_tv, &tofree, numbuf); | |
19140 | + p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); | |
19080 | 19141 | if (p != NULL) |
19081 | 19142 | viminfo_writestring(fp, p); |
19082 | 19143 | vim_free(tofree); |
@@ -2583,11 +2583,19 @@ | ||
2583 | 2583 | retval = FAIL; |
2584 | 2584 | goto theend; |
2585 | 2585 | } |
2586 | + | |
2587 | + /* If 'filetype' was empty try detecting it now. */ | |
2588 | + if (*curbuf->b_p_ft == NUL) | |
2589 | + { | |
2590 | + (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE); | |
2591 | + do_modelines(FALSE); | |
2592 | + } | |
2586 | 2593 | #endif |
2587 | 2594 | } |
2588 | 2595 | |
2589 | 2596 | retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, |
2590 | 2597 | eap, eap->append, eap->forceit, TRUE, FALSE); |
2598 | + | |
2591 | 2599 | } |
2592 | 2600 | |
2593 | 2601 | theend: |
@@ -2861,7 +2869,7 @@ | ||
2861 | 2869 | int retval; |
2862 | 2870 | char_u *free_me = NULL; |
2863 | 2871 | |
2864 | - if (editing_cmdline()) | |
2872 | + if (text_locked()) | |
2865 | 2873 | return 1; |
2866 | 2874 | |
2867 | 2875 | if (fnum == 0) |
@@ -661,13 +661,13 @@ | ||
661 | 661 | restore_cmdline(&save_ccline); |
662 | 662 | if (c == '=') |
663 | 663 | { |
664 | - /* Need to save and restore ccline. And set cmdline_busy | |
664 | + /* Need to save and restore ccline. And set "textlock" | |
665 | 665 | * to avoid nasty things like going to another buffer when |
666 | 666 | * evaluating an expression. */ |
667 | 667 | save_cmdline(&save_ccline); |
668 | - ++cmdline_busy; | |
668 | + ++textlock; | |
669 | 669 | p = get_expr_line(); |
670 | - --cmdline_busy; | |
670 | + --textlock; | |
671 | 671 | restore_cmdline(&save_ccline); |
672 | 672 | |
673 | 673 | if (p != NULL && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) |
@@ -1875,17 +1875,18 @@ | ||
1875 | 1875 | #endif |
1876 | 1876 | |
1877 | 1877 | /* |
1878 | - * Return TRUE when the command line is being edited. That means the current | |
1879 | - * buffer and window can't be changed. | |
1878 | + * Return TRUE when the text must not be changed and we can't switch to | |
1879 | + * another window or buffer. Used when editing the command line, evaluating | |
1880 | + * 'balloonexpr', etc. | |
1880 | 1881 | */ |
1881 | 1882 | int |
1882 | -editing_cmdline() | |
1883 | +text_locked() | |
1883 | 1884 | { |
1884 | 1885 | #ifdef FEAT_CMDWIN |
1885 | 1886 | if (cmdwin_type != 0) |
1886 | 1887 | return TRUE; |
1887 | 1888 | #endif |
1888 | - return cmdline_busy; | |
1889 | + return textlock != 0; | |
1889 | 1890 | } |
1890 | 1891 | |
1891 | 1892 | /* |
@@ -1893,7 +1894,7 @@ | ||
1893 | 1894 | * window is open or editing the cmdline in another way. |
1894 | 1895 | */ |
1895 | 1896 | void |
1896 | -editing_cmdline_msg() | |
1897 | +text_locked_msg() | |
1897 | 1898 | { |
1898 | 1899 | #ifdef FEAT_CMDWIN |
1899 | 1900 | if (cmdwin_type != 0) |
@@ -2814,12 +2815,12 @@ | ||
2814 | 2815 | regname = may_get_selection(regname); |
2815 | 2816 | #endif |
2816 | 2817 | |
2817 | - /* Need to save and restore ccline. And set cmdline_busy to avoid nasty | |
2818 | + /* Need to save and restore ccline. And set "textlock" to avoid nasty | |
2818 | 2819 | * things like going to another buffer when evaluating an expression. */ |
2819 | 2820 | save_cmdline(&save_ccline); |
2820 | - ++cmdline_busy; | |
2821 | + ++textlock; | |
2821 | 2822 | i = get_spec_reg(regname, &arg, &allocated, TRUE); |
2822 | - --cmdline_busy; | |
2823 | + --textlock; | |
2823 | 2824 | restore_cmdline(&save_ccline); |
2824 | 2825 | |
2825 | 2826 | if (i) |
@@ -3837,8 +3838,8 @@ | ||
3837 | 3838 | |
3838 | 3839 | /* Custom expansion takes care of special things, match |
3839 | 3840 | * backslashes literally (perhaps also for other types?) */ |
3840 | - if ((context == EXPAND_USER_DEFINED || | |
3841 | - context == EXPAND_USER_LIST) && fname[i] == '\\') | |
3841 | + if ((context == EXPAND_USER_DEFINED | |
3842 | + || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
3842 | 3843 | new_len++; /* '\' becomes "\\" */ |
3843 | 3844 | } |
3844 | 3845 | retval = alloc(new_len); |
@@ -1938,7 +1938,8 @@ | ||
1938 | 1938 | curbuf = wp->w_buffer; |
1939 | 1939 | |
1940 | 1940 | ++emsg_off; |
1941 | - text = eval_to_string_safe(wp->w_p_fdt, NULL); | |
1941 | + text = eval_to_string_safe(wp->w_p_fdt, NULL, | |
1942 | + was_set_insecurely((char_u *)"foldtext")); | |
1942 | 1943 | --emsg_off; |
1943 | 1944 | |
1944 | 1945 | curwin = save_curwin; |
@@ -86,7 +86,6 @@ | ||
86 | 86 | #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) |
87 | 87 | EXTERN int cmdline_star INIT(= FALSE); /* cmdline is crypted */ |
88 | 88 | #endif |
89 | -EXTERN int cmdline_busy INIT(= FALSE); /* editing the cmdline */ | |
90 | 89 | |
91 | 90 | EXTERN int exec_from_reg INIT(= FALSE); /* executing register */ |
92 | 91 |
@@ -547,12 +546,16 @@ | ||
547 | 546 | * allowed, e.g. when sourcing .exrc or .vimrc |
548 | 547 | * in current directory */ |
549 | 548 | |
549 | +EXTERN int textlock INIT(= 0); | |
550 | + /* non-zero when changing text and jumping to | |
551 | + * another window or buffer is not allowed */ | |
552 | + | |
550 | 553 | #ifdef FEAT_EVAL |
551 | 554 | # define HAVE_SANDBOX |
552 | 555 | EXTERN int sandbox INIT(= 0); |
553 | - /* non-zero when evaluating an expression in a | |
554 | - * "sandbox". Not allowed to change the | |
555 | - * buffer. */ | |
556 | + /* Non-zero when evaluating an expression in a | |
557 | + * "sandbox". Several things are not allowed | |
558 | + * then. */ | |
556 | 559 | #endif |
557 | 560 | |
558 | 561 | EXTERN int silent_mode INIT(= FALSE); |
@@ -1413,10 +1416,7 @@ | ||
1413 | 1416 | EXTERN char_u e_guarded[] INIT(= N_("E463: Region is guarded, cannot modify")); |
1414 | 1417 | EXTERN char_u e_nbreadonly[] INIT(= N_("E744: NetBeans does not allow changes in read-only files")); |
1415 | 1418 | #endif |
1416 | -#if defined(FEAT_INS_EXPAND) || defined(FEAT_EVAL) || defined(FEAT_SYN_HL) \ | |
1417 | - || defined(PROTO) | |
1418 | 1419 | EXTERN char_u e_intern2[] INIT(= N_("E685: Internal error: %s")); |
1419 | -#endif | |
1420 | 1420 | EXTERN char_u e_maxmempat[] INIT(= N_("E363: pattern uses more memory than 'maxmempattern'")); |
1421 | 1421 | EXTERN char_u e_emptybuf[] INIT(= N_("E749: empty buffer")); |
1422 | 1422 |
@@ -23,6 +23,7 @@ | ||
23 | 23 | { |
24 | 24 | win_T *wp; |
25 | 25 | int col; |
26 | + int use_sandbox; | |
26 | 27 | linenr_T lnum; |
27 | 28 | char_u *text; |
28 | 29 | static char_u *result = NULL; |
@@ -50,10 +51,17 @@ | ||
50 | 51 | set_vim_var_string(VV_BEVAL_TEXT, text, -1); |
51 | 52 | vim_free(text); |
52 | 53 | |
53 | - ++sandbox; | |
54 | + use_sandbox = was_set_insecurely((char_u *)"balloonexpr"); | |
55 | + if (use_sandbox) | |
56 | + ++sandbox; | |
57 | + ++textlock; | |
58 | + | |
54 | 59 | vim_free(result); |
55 | 60 | result = eval_to_string(p_bexpr, NULL); |
56 | - --sandbox; | |
61 | + | |
62 | + if (use_sandbox) | |
63 | + --sandbox; | |
64 | + --textlock; | |
57 | 65 | |
58 | 66 | set_vim_var_string(VV_BEVAL_TEXT, NULL, -1); |
59 | 67 | if (result != NULL && result[0] != NUL) |
@@ -1082,35 +1082,137 @@ | ||
1082 | 1082 | return result; |
1083 | 1083 | } |
1084 | 1084 | |
1085 | +/* | |
1086 | + * Function to translate a typval_T into a PyObject; this will recursively | |
1087 | + * translate lists/dictionaries into their Python equivalents. | |
1088 | + * | |
1089 | + * The depth parameter is too avoid infinite recursion, set it to 1 when | |
1090 | + * you call VimToPython. | |
1091 | + */ | |
1092 | + static PyObject * | |
1093 | +VimToPython(typval_T *our_tv, int depth, PyObject *lookupDict) | |
1094 | +{ | |
1095 | + PyObject *result; | |
1096 | + PyObject *newObj; | |
1097 | + char ptrBuf[NUMBUFLEN]; | |
1098 | + | |
1099 | + /* Avoid infinite recursion */ | |
1100 | + if (depth > 100) | |
1101 | + { | |
1102 | + Py_INCREF(Py_None); | |
1103 | + result = Py_None; | |
1104 | + return result; | |
1105 | + } | |
1106 | + | |
1107 | + /* Check if we run into a recursive loop. The item must be in lookupDict | |
1108 | + * then and we can use it again. */ | |
1109 | + sprintf(ptrBuf, "%ld", (long)our_tv); | |
1110 | + result = PyDict_GetItemString(lookupDict, ptrBuf); | |
1111 | + if (result != NULL) | |
1112 | + Py_INCREF(result); | |
1113 | + else if (our_tv->v_type == VAR_STRING) | |
1114 | + { | |
1115 | + result = Py_BuildValue("s", our_tv->vval.v_string); | |
1116 | + PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1117 | + } | |
1118 | + else if (our_tv->v_type == VAR_NUMBER) | |
1119 | + { | |
1120 | + char buf[NUMBUFLEN]; | |
1121 | + | |
1122 | + /* For backwards compatibility numbers are stored as strings. */ | |
1123 | + sprintf(buf, "%ld", (long)our_tv->vval.v_number); | |
1124 | + result = Py_BuildValue("s", buf); | |
1125 | + PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1126 | + } | |
1127 | + else if (our_tv->v_type == VAR_LIST) | |
1128 | + { | |
1129 | + list_T *list = our_tv->vval.v_list; | |
1130 | + listitem_T *curr; | |
1131 | + | |
1132 | + result = PyList_New(0); | |
1133 | + PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1134 | + | |
1135 | + if (list != NULL) | |
1136 | + { | |
1137 | + for (curr = list->lv_first; curr != NULL; curr = curr->li_next) | |
1138 | + { | |
1139 | + newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict); | |
1140 | + PyList_Append(result, newObj); | |
1141 | + Py_DECREF(newObj); | |
1142 | + } | |
1143 | + } | |
1144 | + } | |
1145 | + else if (our_tv->v_type == VAR_DICT) | |
1146 | + { | |
1147 | + result = PyDict_New(); | |
1148 | + PyDict_SetItemString(lookupDict, ptrBuf, result); | |
1149 | + | |
1150 | + if (our_tv->vval.v_dict != NULL) | |
1151 | + { | |
1152 | + hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab; | |
1153 | + int todo = ht->ht_used; | |
1154 | + hashitem_T *hi; | |
1155 | + dictitem_T *di; | |
1156 | + | |
1157 | + for (hi = ht->ht_array; todo > 0; ++hi) | |
1158 | + { | |
1159 | + if (!HASHITEM_EMPTY(hi)) | |
1160 | + { | |
1161 | + --todo; | |
1162 | + | |
1163 | + di = dict_lookup(hi); | |
1164 | + newObj = VimToPython(&di->di_tv, depth + 1, lookupDict); | |
1165 | + PyDict_SetItemString(result, (char *)hi->hi_key, newObj); | |
1166 | + Py_DECREF(newObj); | |
1167 | + } | |
1168 | + } | |
1169 | + } | |
1170 | + } | |
1171 | + else | |
1172 | + { | |
1173 | + Py_INCREF(Py_None); | |
1174 | + result = Py_None; | |
1175 | + } | |
1176 | + | |
1177 | + return result; | |
1178 | +} | |
1179 | + | |
1085 | 1180 | /*ARGSUSED*/ |
1086 | 1181 | static PyObject * |
1087 | 1182 | VimEval(PyObject *self, PyObject *args) |
1088 | 1183 | { |
1089 | 1184 | #ifdef FEAT_EVAL |
1090 | 1185 | char *expr; |
1091 | - char *str; | |
1186 | + typval_T *our_tv; | |
1092 | 1187 | PyObject *result; |
1188 | + PyObject *lookup_dict; | |
1093 | 1189 | |
1094 | 1190 | if (!PyArg_ParseTuple(args, "s", &expr)) |
1095 | 1191 | return NULL; |
1096 | 1192 | |
1097 | 1193 | Py_BEGIN_ALLOW_THREADS |
1098 | 1194 | Python_Lock_Vim(); |
1099 | - str = (char *)eval_to_string((char_u *)expr, NULL); | |
1195 | + our_tv = eval_expr((char_u *)expr, NULL); | |
1196 | + | |
1100 | 1197 | Python_Release_Vim(); |
1101 | 1198 | Py_END_ALLOW_THREADS |
1102 | 1199 | |
1103 | - if (str == NULL) | |
1200 | + if (our_tv == NULL) | |
1104 | 1201 | { |
1105 | 1202 | PyErr_SetVim(_("invalid expression")); |
1106 | 1203 | return NULL; |
1107 | 1204 | } |
1108 | 1205 | |
1109 | - result = Py_BuildValue("s", str); | |
1206 | + /* Convert the Vim type into a Python type. Create a dictionary that's | |
1207 | + * used to check for recursive loops. */ | |
1208 | + lookup_dict = PyDict_New(); | |
1209 | + result = VimToPython(our_tv, 1, lookup_dict); | |
1210 | + Py_DECREF(lookup_dict); | |
1211 | + | |
1110 | 1212 | |
1111 | 1213 | Py_BEGIN_ALLOW_THREADS |
1112 | 1214 | Python_Lock_Vim(); |
1113 | - vim_free(str); | |
1215 | + free_tv(our_tv); | |
1114 | 1216 | Python_Release_Vim(); |
1115 | 1217 | Py_END_ALLOW_THREADS |
1116 | 1218 |
@@ -7673,12 +7673,17 @@ | ||
7673 | 7673 | int indent; |
7674 | 7674 | pos_T pos; |
7675 | 7675 | int save_State; |
7676 | + int use_sandbox = was_set_insecurely((char_u *)"indentexpr"); | |
7676 | 7677 | |
7677 | 7678 | pos = curwin->w_cursor; |
7678 | 7679 | set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum); |
7679 | - ++sandbox; | |
7680 | + if (use_sandbox) | |
7681 | + ++sandbox; | |
7682 | + ++textlock; | |
7680 | 7683 | indent = eval_to_number(curbuf->b_p_inde); |
7681 | - --sandbox; | |
7684 | + if (use_sandbox) | |
7685 | + --sandbox; | |
7686 | + --textlock; | |
7682 | 7687 | |
7683 | 7688 | /* Restore the cursor position so that 'indentexpr' doesn't need to. |
7684 | 7689 | * Pretend to be in Insert mode, allow cursor past end of line for "o" |
@@ -317,6 +317,7 @@ | ||
317 | 317 | #define P_GETTEXT 0x80000L/* expand default value with _() */ |
318 | 318 | #define P_NOGLOB 0x100000L/* do not use local value for global vimrc */ |
319 | 319 | #define P_NFNAME 0x200000L/* only normal file name chars allowed */ |
320 | +#define P_INSECURE 0x400000L/* option was set from a modeline */ | |
320 | 321 | |
321 | 322 | /* |
322 | 323 | * options[] is initialized here. |
@@ -1460,7 +1461,7 @@ | ||
1460 | 1461 | {"magic", NULL, P_BOOL|P_VI_DEF, |
1461 | 1462 | (char_u *)&p_magic, PV_NONE, |
1462 | 1463 | {(char_u *)TRUE, (char_u *)0L}}, |
1463 | - {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, | |
1464 | + {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, | |
1464 | 1465 | #ifdef FEAT_QUICKFIX |
1465 | 1466 | (char_u *)&p_mef, PV_NONE, |
1466 | 1467 | {(char_u *)"", (char_u *)0L} |
@@ -2632,6 +2633,7 @@ | ||
2632 | 2633 | |
2633 | 2634 | static void set_option_default __ARGS((int, int opt_flags, int compatible)); |
2634 | 2635 | static void set_options_default __ARGS((int opt_flags)); |
2636 | +static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value)); | |
2635 | 2637 | static char_u *illegal_char __ARGS((char_u *, int)); |
2636 | 2638 | static int string_to_key __ARGS((char_u *arg)); |
2637 | 2639 | #ifdef FEAT_CMDWIN |
@@ -3157,6 +3159,9 @@ | ||
3157 | 3159 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = |
3158 | 3160 | *(int *)varp; |
3159 | 3161 | } |
3162 | + | |
3163 | + /* the default value is not insecure */ | |
3164 | + options[opt_idx].flags &= ~P_INSECURE; | |
3160 | 3165 | } |
3161 | 3166 | |
3162 | 3167 | #ifdef FEAT_EVAL |
@@ -3790,6 +3795,12 @@ | ||
3790 | 3795 | } |
3791 | 3796 | } |
3792 | 3797 | |
3798 | + /* Skip all options that are not window-local (used when showing | |
3799 | + * an already loaded buffer in a window). */ | |
3800 | + if ((opt_flags & OPT_WINONLY) | |
3801 | + && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) | |
3802 | + goto skip; | |
3803 | + | |
3793 | 3804 | /* Disallow changing some options from modelines */ |
3794 | 3805 | if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE)) |
3795 | 3806 | { |
@@ -3797,15 +3808,9 @@ | ||
3797 | 3808 | goto skip; |
3798 | 3809 | } |
3799 | 3810 | |
3800 | - /* Skip all options that are not window-local (used when showing | |
3801 | - * an already loaded buffer in a window). */ | |
3802 | - if ((opt_flags & OPT_WINONLY) | |
3803 | - && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) | |
3804 | - goto skip; | |
3805 | - | |
3806 | 3811 | #ifdef HAVE_SANDBOX |
3807 | 3812 | /* Disallow changing some options in the sandbox */ |
3808 | - if (sandbox > 0 && (flags & P_SECURE)) | |
3813 | + if (sandbox != 0 && (flags & P_SECURE)) | |
3809 | 3814 | { |
3810 | 3815 | errmsg = (char_u *)_(e_sandbox); |
3811 | 3816 | goto skip; |
@@ -4343,8 +4348,10 @@ | ||
4343 | 4348 | redraw_all_later(CLEAR); |
4344 | 4349 | } |
4345 | 4350 | } |
4351 | + | |
4346 | 4352 | if (opt_idx >= 0) |
4347 | - options[opt_idx].flags |= P_WAS_SET; | |
4353 | + did_set_option(opt_idx, opt_flags, | |
4354 | + !prepending && !adding && !removing); | |
4348 | 4355 | } |
4349 | 4356 | |
4350 | 4357 | skip: |
@@ -4405,6 +4412,31 @@ | ||
4405 | 4412 | return OK; |
4406 | 4413 | } |
4407 | 4414 | |
4415 | +/* | |
4416 | + * Call this when an option has been given a new value through a user command. | |
4417 | + * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. | |
4418 | + */ | |
4419 | + static void | |
4420 | +did_set_option(opt_idx, opt_flags, new_value) | |
4421 | + int opt_idx; | |
4422 | + int opt_flags; /* possibly with OPT_MODELINE */ | |
4423 | + int new_value; /* value was replaced completely */ | |
4424 | +{ | |
4425 | + options[opt_idx].flags |= P_WAS_SET; | |
4426 | + | |
4427 | + /* When an option is set in the sandbox, from a modeline or in secure mode | |
4428 | + * set the P_INSECURE flag. Otherwise, if a new value is stored reset the | |
4429 | + * flag. */ | |
4430 | + if (secure | |
4431 | +#ifdef HAVE_SANDBOX | |
4432 | + || sandbox != 0 | |
4433 | +#endif | |
4434 | + || (opt_flags & OPT_MODELINE)) | |
4435 | + options[opt_idx].flags |= P_INSECURE; | |
4436 | + else if (new_value) | |
4437 | + options[opt_idx].flags &= ~P_INSECURE; | |
4438 | +} | |
4439 | + | |
4408 | 4440 | static char_u * |
4409 | 4441 | illegal_char(errbuf, c) |
4410 | 4442 | char_u *errbuf; |
@@ -4837,6 +4869,25 @@ | ||
4837 | 4869 | return; /* cannot happen: didn't find it! */ |
4838 | 4870 | } |
4839 | 4871 | |
4872 | +#if defined(FEAT_EVAL) || defined(PROTO) | |
4873 | +/* | |
4874 | + * Return TRUE when option "opt" was set from a modeline or in secure mode. | |
4875 | + * Return FALSE when it wasn't. | |
4876 | + * Return -1 for an unknown option. | |
4877 | + */ | |
4878 | + int | |
4879 | +was_set_insecurely(opt) | |
4880 | + char_u *opt; | |
4881 | +{ | |
4882 | + int idx = findoption(opt); | |
4883 | + | |
4884 | + if (idx >= 0) | |
4885 | + return (options[idx].flags & P_INSECURE) != 0; | |
4886 | + EMSG2(_(e_intern2), "was_set_insecurely()"); | |
4887 | + return -1; | |
4888 | +} | |
4889 | +#endif | |
4890 | + | |
4840 | 4891 | /* |
4841 | 4892 | * Set a string option to a new value (without checking the effect). |
4842 | 4893 | * The string is copied into allocated memory. |
@@ -4938,9 +4989,9 @@ | ||
4938 | 4989 | : opt_flags); |
4939 | 4990 | oldval = *varp; |
4940 | 4991 | *varp = s; |
4941 | - options[opt_idx].flags |= P_WAS_SET; | |
4942 | - (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, | |
4943 | - opt_flags); | |
4992 | + if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, | |
4993 | + opt_flags) == NULL) | |
4994 | + did_set_option(opt_idx, opt_flags, TRUE); | |
4944 | 4995 | } |
4945 | 4996 | } |
4946 | 4997 |
@@ -6571,10 +6622,6 @@ | ||
6571 | 6622 | { |
6572 | 6623 | int old_value = *(int *)varp; |
6573 | 6624 | |
6574 | -#ifdef FEAT_GUI | |
6575 | - need_mouse_correct = TRUE; | |
6576 | -#endif | |
6577 | - | |
6578 | 6625 | /* Disallow changing some options from secure mode */ |
6579 | 6626 | if ((secure |
6580 | 6627 | #ifdef HAVE_SANDBOX |
@@ -6589,6 +6636,10 @@ | ||
6589 | 6636 | options[opt_idx].scriptID = current_SID; |
6590 | 6637 | #endif |
6591 | 6638 | |
6639 | +#ifdef FEAT_GUI | |
6640 | + need_mouse_correct = TRUE; | |
6641 | +#endif | |
6642 | + | |
6592 | 6643 | /* May set global value for local option. */ |
6593 | 6644 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
6594 | 6645 | *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; |
@@ -7077,15 +7128,22 @@ | ||
7077 | 7128 | long old_Columns = Columns; /* remember old Columns */ |
7078 | 7129 | long *pp = (long *)varp; |
7079 | 7130 | |
7080 | -#ifdef FEAT_GUI | |
7081 | - need_mouse_correct = TRUE; | |
7082 | -#endif | |
7131 | + /* Disallow changing some options from secure mode. */ | |
7132 | + if ((secure | |
7133 | +#ifdef HAVE_SANDBOX | |
7134 | + || sandbox != 0 | |
7135 | +#endif | |
7136 | + ) && (options[opt_idx].flags & P_SECURE)) | |
7137 | + return e_secure; | |
7083 | 7138 | |
7084 | 7139 | *pp = value; |
7085 | 7140 | #ifdef FEAT_EVAL |
7086 | 7141 | /* Remember where the option was set. */ |
7087 | 7142 | options[opt_idx].scriptID = current_SID; |
7088 | 7143 | #endif |
7144 | +#ifdef FEAT_GUI | |
7145 | + need_mouse_correct = TRUE; | |
7146 | +#endif | |
7089 | 7147 | |
7090 | 7148 | if (curbuf->b_p_sw <= 0) |
7091 | 7149 | { |
@@ -7690,10 +7748,12 @@ | ||
7690 | 7748 | #ifdef HAVE_SANDBOX |
7691 | 7749 | /* Disallow changing some options in the sandbox */ |
7692 | 7750 | if (sandbox > 0 && (flags & P_SECURE)) |
7751 | + { | |
7693 | 7752 | EMSG(_(e_sandbox)); |
7694 | - else | |
7695 | -#endif | |
7696 | - if (flags & P_STRING) | |
7753 | + return; | |
7754 | + } | |
7755 | +#endif | |
7756 | + if (flags & P_STRING) | |
7697 | 7757 | set_string_option(opt_idx, string, opt_flags); |
7698 | 7758 | else |
7699 | 7759 | { |
@@ -7704,7 +7764,8 @@ | ||
7704 | 7764 | (void)set_num_option(opt_idx, varp, number, |
7705 | 7765 | NULL, 0, opt_flags); |
7706 | 7766 | else |
7707 | - (void)set_bool_option(opt_idx, varp, (int)number, opt_flags); | |
7767 | + (void)set_bool_option(opt_idx, varp, (int)number, | |
7768 | + opt_flags); | |
7708 | 7769 | } |
7709 | 7770 | } |
7710 | 7771 | } |
@@ -18,7 +18,7 @@ | ||
18 | 18 | char_u *eval_to_string_skip __ARGS((char_u *arg, char_u **nextcmd, int skip)); |
19 | 19 | int skip_expr __ARGS((char_u **pp)); |
20 | 20 | char_u *eval_to_string __ARGS((char_u *arg, char_u **nextcmd)); |
21 | -char_u *eval_to_string_safe __ARGS((char_u *arg, char_u **nextcmd)); | |
21 | +char_u *eval_to_string_safe __ARGS((char_u *arg, char_u **nextcmd, int use_sandbox)); | |
22 | 22 | int eval_to_number __ARGS((char_u *expr)); |
23 | 23 | list_T *eval_spell_expr __ARGS((char_u *badword, char_u *expr)); |
24 | 24 | int get_spellword __ARGS((list_T *list, char_u **pp)); |
@@ -43,6 +43,7 @@ | ||
43 | 43 | void del_menutrans_vars __ARGS((void)); |
44 | 44 | char_u *get_user_var_name __ARGS((expand_T *xp, int idx)); |
45 | 45 | void list_unref __ARGS((list_T *l)); |
46 | +dictitem_T *dict_lookup __ARGS((hashitem_T *hi)); | |
46 | 47 | int list_append_dict __ARGS((list_T *list, dict_T *dict)); |
47 | 48 | int garbage_collect __ARGS((void)); |
48 | 49 | dict_T *dict_alloc __ARGS((void)); |
@@ -1880,7 +1880,7 @@ | ||
1880 | 1880 | set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); |
1881 | 1881 | set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix", |
1882 | 1882 | OPT_LOCAL); |
1883 | - set_option_value((char_u *)"bh", 0L, (char_u *)"delete", OPT_LOCAL); | |
1883 | + set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL); | |
1884 | 1884 | set_option_value((char_u *)"diff", 0L, (char_u *)"", OPT_LOCAL); |
1885 | 1885 | } |
1886 | 1886 | else if (buf != curbuf) |
@@ -182,7 +182,7 @@ | ||
182 | 182 | |
183 | 183 | /* Don't allow changes in the buffer while editing the cmdline. The |
184 | 184 | * caller of getcmdline() may get confused. */ |
185 | - if (cmdline_busy) | |
185 | + if (textlock != 0) | |
186 | 186 | { |
187 | 187 | EMSG(_(e_secure)); |
188 | 188 | return FALSE; |
@@ -36,5 +36,5 @@ | ||
36 | 36 | #define VIM_VERSION_NODOT "vim70aa" |
37 | 37 | #define VIM_VERSION_SHORT "7.0aa" |
38 | 38 | #define VIM_VERSION_MEDIUM "7.0aa ALPHA" |
39 | -#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2006 Jan 19)" | |
40 | -#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2006 Jan 19, compiled " | |
39 | +#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2006 Jan 20)" | |
40 | +#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2006 Jan 20, compiled " |