Mercurial > vim
comparison src/vim9cmds.c @ 30083:a542dfb1c1a2 v9.0.0379
patch 9.0.0379: cleaning up after writefile() is a hassle
Commit: https://github.com/vim/vim/commit/806a273f3c84ecd475913d901890bb1929be9a0a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 4 15:40:36 2022 +0100
patch 9.0.0379: cleaning up after writefile() is a hassle
Problem: Cleaning up after writefile() is a hassle.
Solution: Add the 'D' flag to defer deleting the written file. Very useful
in tests.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Sep 2022 17:00:03 +0200 |
parents | 6cf788ab844c |
children | a5417ca098af |
comparison
equal
deleted
inserted
replaced
30082:3dc03a877e86 | 30083:a542dfb1c1a2 |
---|---|
1683 | 1683 |
1684 return skipwhite(p); | 1684 return skipwhite(p); |
1685 } | 1685 } |
1686 | 1686 |
1687 /* | 1687 /* |
1688 * Get the local variable index for deferred function calls. | |
1689 * Reserve it when not done already. | |
1690 * Returns zero for failure. | |
1691 */ | |
1692 int | |
1693 get_defer_var_idx(cctx_T *cctx) | |
1694 { | |
1695 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) | |
1696 + cctx->ctx_ufunc->uf_dfunc_idx; | |
1697 if (dfunc->df_defer_var_idx == 0) | |
1698 { | |
1699 lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, | |
1700 TRUE, &t_list_any); | |
1701 if (lvar == NULL) | |
1702 return 0; | |
1703 dfunc->df_defer_var_idx = lvar->lv_idx + 1; | |
1704 } | |
1705 return dfunc->df_defer_var_idx; | |
1706 } | |
1707 | |
1708 /* | |
1688 * Compile "defer func(arg)". | 1709 * Compile "defer func(arg)". |
1689 */ | 1710 */ |
1690 char_u * | 1711 char_u * |
1691 compile_defer(char_u *arg_start, cctx_T *cctx) | 1712 compile_defer(char_u *arg_start, cctx_T *cctx) |
1692 { | 1713 { |
1693 char_u *p; | 1714 char_u *p; |
1694 char_u *arg = arg_start; | 1715 char_u *arg = arg_start; |
1695 int argcount = 0; | 1716 int argcount = 0; |
1696 dfunc_T *dfunc; | 1717 int defer_var_idx; |
1697 type_T *type; | 1718 type_T *type; |
1698 int func_idx; | 1719 int func_idx; |
1699 | 1720 |
1700 // Get a funcref for the function name. | 1721 // Get a funcref for the function name. |
1701 // TODO: better way to find the "(". | 1722 // TODO: better way to find the "(". |
1728 if (compile_arguments(&arg, cctx, &argcount, CA_NOT_SPECIAL) == FAIL) | 1749 if (compile_arguments(&arg, cctx, &argcount, CA_NOT_SPECIAL) == FAIL) |
1729 return NULL; | 1750 return NULL; |
1730 | 1751 |
1731 // TODO: check argument count with "type" | 1752 // TODO: check argument count with "type" |
1732 | 1753 |
1733 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx; | 1754 defer_var_idx = get_defer_var_idx(cctx); |
1734 if (dfunc->df_defer_var_idx == 0) | 1755 if (defer_var_idx == 0) |
1735 { | 1756 return NULL; |
1736 lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, | 1757 if (generate_DEFER(cctx, defer_var_idx - 1, argcount) == FAIL) |
1737 TRUE, &t_list_any); | |
1738 if (lvar == NULL) | |
1739 return NULL; | |
1740 dfunc->df_defer_var_idx = lvar->lv_idx + 1; | |
1741 } | |
1742 if (generate_DEFER(cctx, dfunc->df_defer_var_idx - 1, argcount) == FAIL) | |
1743 return NULL; | 1758 return NULL; |
1744 | 1759 |
1745 return skipwhite(arg); | 1760 return skipwhite(arg); |
1746 } | 1761 } |
1747 | 1762 |