Patch 9.0.1673

82 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 7, 2023, 1:58:17 PM7/7/23
to vim...@googlegroups.com

Patch 9.0.1673
Problem: Cannot produce a status 418 or 503 message.
Solution: Add err_teapot().
Files: runtime/doc/builtin.txt, src/errors.h, src/evalfunc.c,
src/testdir/test_functions.vim


*** ../vim-9.0.1672/runtime/doc/builtin.txt 2023-06-14 13:10:09.799148187 +0100
--- runtime/doc/builtin.txt 2023-07-07 18:28:34.726592448 +0100
***************
*** 154,159 ****
--- 154,160 ----
digraph_set({chars}, {digraph}) Boolean register |digraph|
digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
echoraw({expr}) none output {expr} as-is
+ err_teapot() Number produce error 418
empty({expr}) Number |TRUE| if {expr} is empty
environ() Dict return environment variables
escape({string}, {chars}) String escape {chars} in {string} with '\'
***************
*** 2176,2181 ****
--- 2177,2190 ----
< Use with care, you can mess up the terminal this way.


+ err_teapot([{expr}]) *err_teapot()*
+ Produce an error with number 418, needed for implementation of
+ RFC 2325.
+ If {expr} is present and it is TRUE error 503 is given,
+ indicating that coffee is temporarily not available.
+ If {expr} is present it must be a String.
+
+
empty({expr}) *empty()*
Return the Number 1 if {expr} is empty, zero otherwise.
- A |List| or |Dictionary| is empty when it does not have any
*** ../vim-9.0.1672/src/errors.h 2023-05-31 17:12:07.884535632 +0100
--- src/errors.h 2023-07-07 18:11:36.427706851 +0100
***************
*** 1037,1042 ****
--- 1037,1044 ----
INIT(= N_("E417: Missing argument: %s"));
EXTERN char e_illegal_value_str[]
INIT(= N_("E418: Illegal value: %s"));
+ EXTERN char e_im_a_teapot[]
+ INIT(= N_("E418: I'm a teapot"));
EXTERN char e_fg_color_unknown[]
INIT(= N_("E419: FG color unknown"));
EXTERN char e_bg_color_unknown[]
***************
*** 1270,1275 ****
--- 1272,1279 ----
INIT(= N_("is not a file or writable device"));
EXTERN char e_str_is_not_file_or_writable_device[]
INIT(= N_("E503: \"%s\" is not a file or writable device"));
+ EXTERN char e_coffee_currently_not_available[]
+ INIT(= N_("E503: Coffee is currently not available"));
// E504
EXTERN char e_is_read_only_cannot_override_W_in_cpoptions[]
INIT(= N_("is read-only (cannot override: \"W\" in 'cpoptions')"));
*** ../vim-9.0.1672/src/evalfunc.c 2023-06-24 16:42:22.158719360 +0100
--- src/evalfunc.c 2023-07-07 18:55:11.501897399 +0100
***************
*** 45,50 ****
--- 45,51 ----
static void f_echoraw(typval_T *argvars, typval_T *rettv);
static void f_empty(typval_T *argvars, typval_T *rettv);
static void f_environ(typval_T *argvars, typval_T *rettv);
+ static void f_err_teapot(typval_T *argvars, typval_T *rettv);
static void f_escape(typval_T *argvars, typval_T *rettv);
static void f_eval(typval_T *argvars, typval_T *rettv);
static void f_eventhandler(typval_T *argvars, typval_T *rettv);
***************
*** 1881,1886 ****
--- 1882,1889 ----
ret_number_bool, f_empty},
{"environ", 0, 0, 0, NULL,
ret_dict_string, f_environ},
+ {"err_teapot", 0, 1, 0, NULL,
+ ret_number_bool, f_err_teapot},
{"escape", 2, 2, FEARG_1, arg2_string,
ret_string, f_escape},
{"eval", 1, 1, FEARG_1, arg1_string,
***************
*** 3923,3928 ****
--- 3926,3958 ----
}

/*
+ * "err_teapot()" function
+ */
+ static void
+ f_err_teapot(typval_T *argvars, typval_T *rettv UNUSED)
+ {
+ if (argvars[0].v_type != VAR_UNKNOWN)
+ {
+ if (argvars[0].v_type == VAR_STRING)
+ {
+ char_u *s = tv_get_string_strict(&argvars[0]);
+ if (s == NULL || *skipwhite(s) == NUL)
+ return;
+ }
+
+ int err = FALSE;
+ int do_503 = eval_expr_to_bool(&argvars[0], &err);
+ if (!err && do_503)
+ {
+ emsg(_(e_coffee_currently_not_available));
+ return;
+ }
+ }
+
+ emsg(_(e_im_a_teapot));
+ }
+
+ /*
* "escape({string}, {chars})" function
*/
static void
***************
*** 6456,6461 ****
--- 6486,6499 ----
1
#else
0
+ #endif
+ },
+ {":tearoff",
+ // same #ifdef as used for ex_tearoff().
+ #if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
+ 1
+ #else
+ 0
#endif
},
{NULL, 0}
*** ../vim-9.0.1672/src/testdir/test_functions.vim 2023-06-14 13:10:09.803148193 +0100
--- src/testdir/test_functions.vim 2023-07-07 18:42:09.138377511 +0100
***************
*** 30,39 ****
--- 30,42 ----
call assert_equal(1, or(has('ttyin'), 1))
call assert_equal(0, and(has('ttyout'), 0))
call assert_equal(1, has('multi_byte_encoding'))
+ call assert_equal(0, has(':tearoff'))
endif
call assert_equal(1, has('vcon', 1))
call assert_equal(1, has('mouse_gpm_enabled', 1))

+ call assert_equal(has('gui_win32') && has('menu'), has(':tearoff'))
+
call assert_equal(0, has('nonexistent'))
call assert_equal(0, has('nonexistent', 1))

***************
*** 86,91 ****
--- 89,105 ----
call assert_fails("call empty(test_unknown())", ['E340:', 'E685:'])
endfunc

+ func Test_err_teapot()
+ call assert_fails('call err_teapot()', "E418: I'm a teapot")
+ call assert_fails('call err_teapot(0)', "E418: I'm a teapot")
+ call assert_fails('call err_teapot(v:false)', "E418: I'm a teapot")
+
+ call assert_fails('call err_teapot("1")', "E503: Coffee is currently not available")
+ call assert_fails('call err_teapot(v:true)', "E503: Coffee is currently not available")
+ let expr = 1
+ call assert_fails('call err_teapot(expr)', "E503: Coffee is currently not available")
+ endfunc
+
func Test_test_void()
call assert_fails('echo 1 == test_void()', 'E1031:')
call assert_fails('echo 1.0 == test_void()', 'E1031:')
*** ../vim-9.0.1672/src/version.c 2023-07-01 20:24:36.105801444 +0100
--- src/version.c 2023-07-07 17:48:49.425056765 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1673,
/**/

--
GALAHAD: Camelot ...
LAUNCELOT: Camelot ...
GAWAIN: It's only a model.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Dominique Pellé

unread,
Jul 8, 2023, 2:51:30 AM7/8/23
to vim...@googlegroups.com
On Fri, Jul 7, 2023 at 7:58 PM Bram Moolenaar wrote:

> + err_teapot([{expr}]) *err_teapot()*
> + Produce an error with number 418, needed for implementation of
> + RFC 2325.
> + If {expr} is present and it is TRUE error 503 is given,
> + indicating that coffee is temporarily not available.
> + If {expr} is present it must be a String.

It looks like a joke, but I don't get it.

Dominique

Christ van Willegen

unread,
Jul 8, 2023, 6:09:32 AM7/8/23
to vim...@googlegroups.com


Op za 8 jul. 2023 08:51 schreef Dominique Pellé <dominiq...@gmail.com>:


1998-04-01
(System) RFC published

So, it's a joke alright...

Christ van Willegen

Bram Moolenaar

unread,
Jul 8, 2023, 9:37:04 PM7/8/23
to vim...@googlegroups.com, Dominique Pellé
The RFC was published on April 1st:
https://datatracker.ietf.org/doc/html/rfc2325

I was reading that Emacs could control a coffee maker. For Vim I would
expect a plugin to be able to do that. The specification is here:
https://datatracker.ietf.org/doc/html/rfc2324
Updated by: https://datatracker.ietf.org/doc/html/rfc7168

The error messages were missing though, thus I added them with this
patch. Now waiting for a volunteer to write the plugin.

--
GOD: That is your purpose Arthur ... the Quest for the Holy Grail ...
Reply all
Reply to author
Forward
0 new messages