• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisiona1396a35444c566bf908778affb3b340ff81cdab (tree)
Time2019-09-16 04:15:03
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.1.2042: the evalfunc.c file is too big

Commit: https://github.com/vim/vim/commit/9c658c9eacbd97e2c071f652a0155f71db94c0f3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 15 21:00:54 2019 +0200

patch 8.1.2042: the evalfunc.c file is too big
Problem: The evalfunc.c file is too big.
Solution: Move getchar() and parse_queued_messages() to getchar.c.

Change Summary

Incremental Difference

diff -r 18c77f2ec0d9 -r a1396a35444c src/evalfunc.c
--- a/src/evalfunc.c Sun Sep 15 19:45:04 2019 +0200
+++ b/src/evalfunc.c Sun Sep 15 21:15:03 2019 +0200
@@ -90,8 +90,6 @@
9090 static void f_garbagecollect(typval_T *argvars, typval_T *rettv);
9191 static void f_get(typval_T *argvars, typval_T *rettv);
9292 static void f_getchangelist(typval_T *argvars, typval_T *rettv);
93-static void f_getchar(typval_T *argvars, typval_T *rettv);
94-static void f_getcharmod(typval_T *argvars, typval_T *rettv);
9593 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
9694 static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
9795 static void f_getenv(typval_T *argvars, typval_T *rettv);
@@ -2857,125 +2855,6 @@
28572855 }
28582856 #endif
28592857 }
2860-/*
2861- * "getchar()" function
2862- */
2863- static void
2864-f_getchar(typval_T *argvars, typval_T *rettv)
2865-{
2866- varnumber_T n;
2867- int error = FALSE;
2868-
2869-#ifdef MESSAGE_QUEUE
2870- // vpeekc() used to check for messages, but that caused problems, invoking
2871- // a callback where it was not expected. Some plugins use getchar(1) in a
2872- // loop to await a message, therefore make sure we check for messages here.
2873- parse_queued_messages();
2874-#endif
2875-
2876- /* Position the cursor. Needed after a message that ends in a space. */
2877- windgoto(msg_row, msg_col);
2878-
2879- ++no_mapping;
2880- ++allow_keys;
2881- for (;;)
2882- {
2883- if (argvars[0].v_type == VAR_UNKNOWN)
2884- /* getchar(): blocking wait. */
2885- n = plain_vgetc();
2886- else if (tv_get_number_chk(&argvars[0], &error) == 1)
2887- /* getchar(1): only check if char avail */
2888- n = vpeekc_any();
2889- else if (error || vpeekc_any() == NUL)
2890- /* illegal argument or getchar(0) and no char avail: return zero */
2891- n = 0;
2892- else
2893- /* getchar(0) and char avail: return char */
2894- n = plain_vgetc();
2895-
2896- if (n == K_IGNORE)
2897- continue;
2898- break;
2899- }
2900- --no_mapping;
2901- --allow_keys;
2902-
2903- set_vim_var_nr(VV_MOUSE_WIN, 0);
2904- set_vim_var_nr(VV_MOUSE_WINID, 0);
2905- set_vim_var_nr(VV_MOUSE_LNUM, 0);
2906- set_vim_var_nr(VV_MOUSE_COL, 0);
2907-
2908- rettv->vval.v_number = n;
2909- if (IS_SPECIAL(n) || mod_mask != 0)
2910- {
2911- char_u temp[10]; /* modifier: 3, mbyte-char: 6, NUL: 1 */
2912- int i = 0;
2913-
2914- /* Turn a special key into three bytes, plus modifier. */
2915- if (mod_mask != 0)
2916- {
2917- temp[i++] = K_SPECIAL;
2918- temp[i++] = KS_MODIFIER;
2919- temp[i++] = mod_mask;
2920- }
2921- if (IS_SPECIAL(n))
2922- {
2923- temp[i++] = K_SPECIAL;
2924- temp[i++] = K_SECOND(n);
2925- temp[i++] = K_THIRD(n);
2926- }
2927- else if (has_mbyte)
2928- i += (*mb_char2bytes)(n, temp + i);
2929- else
2930- temp[i++] = n;
2931- temp[i++] = NUL;
2932- rettv->v_type = VAR_STRING;
2933- rettv->vval.v_string = vim_strsave(temp);
2934-
2935-#ifdef FEAT_MOUSE
2936- if (is_mouse_key(n))
2937- {
2938- int row = mouse_row;
2939- int col = mouse_col;
2940- win_T *win;
2941- linenr_T lnum;
2942- win_T *wp;
2943- int winnr = 1;
2944-
2945- if (row >= 0 && col >= 0)
2946- {
2947- /* Find the window at the mouse coordinates and compute the
2948- * text position. */
2949- win = mouse_find_win(&row, &col, FIND_POPUP);
2950- if (win == NULL)
2951- return;
2952- (void)mouse_comp_pos(win, &row, &col, &lnum, NULL);
2953-# ifdef FEAT_TEXT_PROP
2954- if (WIN_IS_POPUP(win))
2955- winnr = 0;
2956- else
2957-# endif
2958- for (wp = firstwin; wp != win && wp != NULL;
2959- wp = wp->w_next)
2960- ++winnr;
2961- set_vim_var_nr(VV_MOUSE_WIN, winnr);
2962- set_vim_var_nr(VV_MOUSE_WINID, win->w_id);
2963- set_vim_var_nr(VV_MOUSE_LNUM, lnum);
2964- set_vim_var_nr(VV_MOUSE_COL, col + 1);
2965- }
2966- }
2967-#endif
2968- }
2969-}
2970-
2971-/*
2972- * "getcharmod()" function
2973- */
2974- static void
2975-f_getcharmod(typval_T *argvars UNUSED, typval_T *rettv)
2976-{
2977- rettv->vval.v_number = mod_mask;
2978-}
29792858
29802859 /*
29812860 * "getcharsearch()" function
diff -r 18c77f2ec0d9 -r a1396a35444c src/getchar.c
--- a/src/getchar.c Sun Sep 15 19:45:04 2019 +0200
+++ b/src/getchar.c Sun Sep 15 21:15:03 2019 +0200
@@ -1901,6 +1901,205 @@
19011901 return (retval != NUL);
19021902 }
19031903
1904+#if defined(FEAT_EVAL) || defined(PROTO)
1905+/*
1906+ * "getchar()" function
1907+ */
1908+ void
1909+f_getchar(typval_T *argvars, typval_T *rettv)
1910+{
1911+ varnumber_T n;
1912+ int error = FALSE;
1913+
1914+#ifdef MESSAGE_QUEUE
1915+ // vpeekc() used to check for messages, but that caused problems, invoking
1916+ // a callback where it was not expected. Some plugins use getchar(1) in a
1917+ // loop to await a message, therefore make sure we check for messages here.
1918+ parse_queued_messages();
1919+#endif
1920+
1921+ /* Position the cursor. Needed after a message that ends in a space. */
1922+ windgoto(msg_row, msg_col);
1923+
1924+ ++no_mapping;
1925+ ++allow_keys;
1926+ for (;;)
1927+ {
1928+ if (argvars[0].v_type == VAR_UNKNOWN)
1929+ /* getchar(): blocking wait. */
1930+ n = plain_vgetc();
1931+ else if (tv_get_number_chk(&argvars[0], &error) == 1)
1932+ /* getchar(1): only check if char avail */
1933+ n = vpeekc_any();
1934+ else if (error || vpeekc_any() == NUL)
1935+ /* illegal argument or getchar(0) and no char avail: return zero */
1936+ n = 0;
1937+ else
1938+ /* getchar(0) and char avail: return char */
1939+ n = plain_vgetc();
1940+
1941+ if (n == K_IGNORE)
1942+ continue;
1943+ break;
1944+ }
1945+ --no_mapping;
1946+ --allow_keys;
1947+
1948+ set_vim_var_nr(VV_MOUSE_WIN, 0);
1949+ set_vim_var_nr(VV_MOUSE_WINID, 0);
1950+ set_vim_var_nr(VV_MOUSE_LNUM, 0);
1951+ set_vim_var_nr(VV_MOUSE_COL, 0);
1952+
1953+ rettv->vval.v_number = n;
1954+ if (IS_SPECIAL(n) || mod_mask != 0)
1955+ {
1956+ char_u temp[10]; /* modifier: 3, mbyte-char: 6, NUL: 1 */
1957+ int i = 0;
1958+
1959+ /* Turn a special key into three bytes, plus modifier. */
1960+ if (mod_mask != 0)
1961+ {
1962+ temp[i++] = K_SPECIAL;
1963+ temp[i++] = KS_MODIFIER;
1964+ temp[i++] = mod_mask;
1965+ }
1966+ if (IS_SPECIAL(n))
1967+ {
1968+ temp[i++] = K_SPECIAL;
1969+ temp[i++] = K_SECOND(n);
1970+ temp[i++] = K_THIRD(n);
1971+ }
1972+ else if (has_mbyte)
1973+ i += (*mb_char2bytes)(n, temp + i);
1974+ else
1975+ temp[i++] = n;
1976+ temp[i++] = NUL;
1977+ rettv->v_type = VAR_STRING;
1978+ rettv->vval.v_string = vim_strsave(temp);
1979+
1980+#ifdef FEAT_MOUSE
1981+ if (is_mouse_key(n))
1982+ {
1983+ int row = mouse_row;
1984+ int col = mouse_col;
1985+ win_T *win;
1986+ linenr_T lnum;
1987+ win_T *wp;
1988+ int winnr = 1;
1989+
1990+ if (row >= 0 && col >= 0)
1991+ {
1992+ /* Find the window at the mouse coordinates and compute the
1993+ * text position. */
1994+ win = mouse_find_win(&row, &col, FIND_POPUP);
1995+ if (win == NULL)
1996+ return;
1997+ (void)mouse_comp_pos(win, &row, &col, &lnum, NULL);
1998+# ifdef FEAT_TEXT_PROP
1999+ if (WIN_IS_POPUP(win))
2000+ winnr = 0;
2001+ else
2002+# endif
2003+ for (wp = firstwin; wp != win && wp != NULL;
2004+ wp = wp->w_next)
2005+ ++winnr;
2006+ set_vim_var_nr(VV_MOUSE_WIN, winnr);
2007+ set_vim_var_nr(VV_MOUSE_WINID, win->w_id);
2008+ set_vim_var_nr(VV_MOUSE_LNUM, lnum);
2009+ set_vim_var_nr(VV_MOUSE_COL, col + 1);
2010+ }
2011+ }
2012+#endif
2013+ }
2014+}
2015+
2016+/*
2017+ * "getcharmod()" function
2018+ */
2019+ void
2020+f_getcharmod(typval_T *argvars UNUSED, typval_T *rettv)
2021+{
2022+ rettv->vval.v_number = mod_mask;
2023+}
2024+#endif // FEAT_EVAL
2025+
2026+#if defined(MESSAGE_QUEUE) || defined(PROTO)
2027+# define MAX_REPEAT_PARSE 8
2028+
2029+/*
2030+ * Process messages that have been queued for netbeans or clientserver.
2031+ * Also check if any jobs have ended.
2032+ * These functions can call arbitrary vimscript and should only be called when
2033+ * it is safe to do so.
2034+ */
2035+ void
2036+parse_queued_messages(void)
2037+{
2038+ int old_curwin_id = curwin->w_id;
2039+ int old_curbuf_fnum = curbuf->b_fnum;
2040+ int i;
2041+ int save_may_garbage_collect = may_garbage_collect;
2042+
2043+ // Do not handle messages while redrawing, because it may cause buffers to
2044+ // change or be wiped while they are being redrawn.
2045+ if (updating_screen)
2046+ return;
2047+
2048+ // may_garbage_collect is set in main_loop() to do garbage collection when
2049+ // blocking to wait on a character. We don't want that while parsing
2050+ // messages, a callback may invoke vgetc() while lists and dicts are in use
2051+ // in the call stack.
2052+ may_garbage_collect = FALSE;
2053+
2054+ // Loop when a job ended, but don't keep looping forever.
2055+ for (i = 0; i < MAX_REPEAT_PARSE; ++i)
2056+ {
2057+ // For Win32 mch_breakcheck() does not check for input, do it here.
2058+# if defined(MSWIN) && defined(FEAT_JOB_CHANNEL)
2059+ channel_handle_events(FALSE);
2060+# endif
2061+
2062+# ifdef FEAT_NETBEANS_INTG
2063+ // Process the queued netbeans messages.
2064+ netbeans_parse_messages();
2065+# endif
2066+# ifdef FEAT_JOB_CHANNEL
2067+ // Write any buffer lines still to be written.
2068+ channel_write_any_lines();
2069+
2070+ // Process the messages queued on channels.
2071+ channel_parse_messages();
2072+# endif
2073+# if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
2074+ // Process the queued clientserver messages.
2075+ server_parse_messages();
2076+# endif
2077+# ifdef FEAT_JOB_CHANNEL
2078+ // Check if any jobs have ended. If so, repeat the above to handle
2079+ // changes, e.g. stdin may have been closed.
2080+ if (job_check_ended())
2081+ continue;
2082+# endif
2083+# ifdef FEAT_TERMINAL
2084+ free_unused_terminals();
2085+# endif
2086+# ifdef FEAT_SOUND_CANBERRA
2087+ if (has_sound_callback_in_queue())
2088+ invoke_sound_callback();
2089+# endif
2090+ break;
2091+ }
2092+
2093+ may_garbage_collect = save_may_garbage_collect;
2094+
2095+ // If the current window or buffer changed we need to bail out of the
2096+ // waiting loop. E.g. when a job exit callback closes the terminal window.
2097+ if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum)
2098+ ins_char_typebuf(K_IGNORE);
2099+}
2100+#endif
2101+
2102+
19042103 typedef enum {
19052104 map_result_fail, // failed, break loop
19062105 map_result_get, // get a character from typeahead
@@ -3016,7 +3215,6 @@
30163215 #endif
30173216 )
30183217 {
3019-
30203218 #ifdef MESSAGE_QUEUE
30213219 parse_queued_messages();
30223220 #endif
diff -r 18c77f2ec0d9 -r a1396a35444c src/misc2.c
--- a/src/misc2.c Sun Sep 15 19:45:04 2019 +0200
+++ b/src/misc2.c Sun Sep 15 21:15:03 2019 +0200
@@ -4349,82 +4349,6 @@
43494349 }
43504350 #endif
43514351
4352-#if defined(MESSAGE_QUEUE) || defined(PROTO)
4353-# define MAX_REPEAT_PARSE 8
4354-
4355-/*
4356- * Process messages that have been queued for netbeans or clientserver.
4357- * Also check if any jobs have ended.
4358- * These functions can call arbitrary vimscript and should only be called when
4359- * it is safe to do so.
4360- */
4361- void
4362-parse_queued_messages(void)
4363-{
4364- int old_curwin_id = curwin->w_id;
4365- int old_curbuf_fnum = curbuf->b_fnum;
4366- int i;
4367- int save_may_garbage_collect = may_garbage_collect;
4368-
4369- // Do not handle messages while redrawing, because it may cause buffers to
4370- // change or be wiped while they are being redrawn.
4371- if (updating_screen)
4372- return;
4373-
4374- // may_garbage_collect is set in main_loop() to do garbage collection when
4375- // blocking to wait on a character. We don't want that while parsing
4376- // messages, a callback may invoke vgetc() while lists and dicts are in use
4377- // in the call stack.
4378- may_garbage_collect = FALSE;
4379-
4380- // Loop when a job ended, but don't keep looping forever.
4381- for (i = 0; i < MAX_REPEAT_PARSE; ++i)
4382- {
4383- // For Win32 mch_breakcheck() does not check for input, do it here.
4384-# if defined(MSWIN) && defined(FEAT_JOB_CHANNEL)
4385- channel_handle_events(FALSE);
4386-# endif
4387-
4388-# ifdef FEAT_NETBEANS_INTG
4389- // Process the queued netbeans messages.
4390- netbeans_parse_messages();
4391-# endif
4392-# ifdef FEAT_JOB_CHANNEL
4393- // Write any buffer lines still to be written.
4394- channel_write_any_lines();
4395-
4396- // Process the messages queued on channels.
4397- channel_parse_messages();
4398-# endif
4399-# if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
4400- // Process the queued clientserver messages.
4401- server_parse_messages();
4402-# endif
4403-# ifdef FEAT_JOB_CHANNEL
4404- // Check if any jobs have ended. If so, repeat the above to handle
4405- // changes, e.g. stdin may have been closed.
4406- if (job_check_ended())
4407- continue;
4408-# endif
4409-# ifdef FEAT_TERMINAL
4410- free_unused_terminals();
4411-# endif
4412-# ifdef FEAT_SOUND_CANBERRA
4413- if (has_sound_callback_in_queue())
4414- invoke_sound_callback();
4415-# endif
4416- break;
4417- }
4418-
4419- may_garbage_collect = save_may_garbage_collect;
4420-
4421- // If the current window or buffer changed we need to bail out of the
4422- // waiting loop. E.g. when a job exit callback closes the terminal window.
4423- if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum)
4424- ins_char_typebuf(K_IGNORE);
4425-}
4426-#endif
4427-
44284352 #ifndef PROTO /* proto is defined in vim.h */
44294353 # ifdef ELAPSED_TIMEVAL
44304354 /*
diff -r 18c77f2ec0d9 -r a1396a35444c src/proto/getchar.pro
--- a/src/proto/getchar.pro Sun Sep 15 19:45:04 2019 +0200
+++ b/src/proto/getchar.pro Sun Sep 15 21:15:03 2019 +0200
@@ -44,6 +44,9 @@
4444 int vpeekc_nomap(void);
4545 int vpeekc_any(void);
4646 int char_avail(void);
47+void f_getchar(typval_T *argvars, typval_T *rettv);
48+void f_getcharmod(typval_T *argvars, typval_T *rettv);
49+void parse_queued_messages(void);
4750 void vungetc(int c);
4851 int fix_input_buffer(char_u *buf, int len);
4952 int input_available(void);
diff -r 18c77f2ec0d9 -r a1396a35444c src/proto/misc2.pro
--- a/src/proto/misc2.pro Sun Sep 15 19:45:04 2019 +0200
+++ b/src/proto/misc2.pro Sun Sep 15 21:15:03 2019 +0200
@@ -102,7 +102,6 @@
102102 int put_time(FILE *fd, time_T the_time);
103103 void time_to_bytes(time_T the_time, char_u *buf);
104104 int has_non_ascii(char_u *s);
105-void parse_queued_messages(void);
106105 int mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc);
107106 int build_argv_from_string(char_u *cmd, char ***argv, int *argc);
108107 int build_argv_from_list(list_T *l, char ***argv, int *argc);
diff -r 18c77f2ec0d9 -r a1396a35444c src/version.c
--- a/src/version.c Sun Sep 15 19:45:04 2019 +0200
+++ b/src/version.c Sun Sep 15 21:15:03 2019 +0200
@@ -758,6 +758,8 @@
758758 static int included_patches[] =
759759 { /* Add new patch number below this line */
760760 /**/
761+ 2042,
762+/**/
761763 2041,
762764 /**/
763765 2040,
Show on old repository browser