From d82a586a9e39f1d346c1aea78167a85c586ed3f4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 18 Dec 2023 06:18:11 +0800 Subject: [PATCH] refactor: move some anonymous enums back to non-defs headers (#26622) It isn't really useful to put anonymous enums only used as arguments to functions calls in _defs.h headers, as they will only be used by a file that calls those functions, which requires including a non-defs header. Also move os_msg() and os_errmsg() back to message.h, as on Windows they are actual functions instead of macros. Also remove gettext.h and globals.h from private/helpers.h. --- Makefile | 1 - src/clint.py | 3 --- src/nvim/api/private/helpers.h | 4 +-- src/nvim/channel_defs.h | 9 +------ src/nvim/ex_cmds.h | 18 +++++++++++++ src/nvim/ex_cmds_defs.h | 18 ------------- src/nvim/generators/gen_api_dispatch.lua | 2 ++ src/nvim/log.h | 1 + src/nvim/message.h | 34 ++++++++++++++++++++++++ src/nvim/message_defs.h | 34 ------------------------ src/nvim/option.h | 1 + src/nvim/os/lang.c | 1 + 12 files changed, 60 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index 6176f3a7bf..c1b8518838 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,6 @@ iwyu: build/.ran-cmake |src/nvim/buffer.h\ |src/nvim/buffer_defs.h\ |src/nvim/channel.h\ - |src/nvim/channel_defs.h\ |src/nvim/charset.h\ |src/nvim/drawline.h\ |src/nvim/eval.h\ diff --git a/src/clint.py b/src/clint.py index 537406cd24..446593303b 100755 --- a/src/clint.py +++ b/src/clint.py @@ -905,7 +905,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/buffer.h", "src/nvim/buffer_defs.h", "src/nvim/channel.h", - "src/nvim/channel_defs.h", "src/nvim/charset.h", "src/nvim/drawline.h", "src/nvim/eval.h", @@ -950,8 +949,6 @@ def CheckIncludes(filename, lines, error): "klib/klist.h", "klib/kvec.h", "nvim/func_attr.h", - "nvim/gettext.h", - "nvim/globals.h" ] for i in check_includes_ignore: diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 64558f0410..701ce91257 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -5,9 +5,9 @@ #include "klib/kvec.h" #include "nvim/api/private/defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep +#include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/ex_eval_defs.h" -#include "nvim/gettext.h" -#include "nvim/globals.h" #include "nvim/macros_defs.h" #include "nvim/map_defs.h" #include "nvim/message_defs.h" // IWYU pragma: keep diff --git a/src/nvim/channel_defs.h b/src/nvim/channel_defs.h index 1af4c2de59..f6475129ff 100644 --- a/src/nvim/channel_defs.h +++ b/src/nvim/channel_defs.h @@ -4,18 +4,11 @@ #include #include "nvim/eval/typval_defs.h" -#include "nvim/event/libuv_process.h" -#include "nvim/event/multiqueue.h" -#include "nvim/event/process.h" -#include "nvim/event/socket.h" -#include "nvim/event/stream.h" +#include "nvim/event/defs.h" #include "nvim/garray_defs.h" #include "nvim/macros_defs.h" -#include "nvim/main.h" #include "nvim/map_defs.h" #include "nvim/msgpack_rpc/channel_defs.h" -#include "nvim/os/pty_process.h" -#include "nvim/terminal.h" #include "nvim/types_defs.h" #define CHAN_STDIO 1 diff --git a/src/nvim/ex_cmds.h b/src/nvim/ex_cmds.h index 2f576731f4..c3e4a799b5 100644 --- a/src/nvim/ex_cmds.h +++ b/src/nvim/ex_cmds.h @@ -2,6 +2,24 @@ #include "nvim/ex_cmds_defs.h" // IWYU pragma: export +/// flags for do_ecmd() +enum { + ECMD_HIDE = 0x01, ///< don't free the current buffer + ECMD_SET_HELP = 0x02, ///< set b_help flag of (new) buffer before opening file + ECMD_OLDBUF = 0x04, ///< use existing buffer if it exists + ECMD_FORCEIT = 0x08, ///< ! used in Ex command + ECMD_ADDBUF = 0x10, ///< don't edit, just add to buffer list + ECMD_ALTBUF = 0x20, ///< like ECMD_ADDBUF and set the alternate file + ECMD_NOWINENTER = 0x40, ///< do not trigger BufWinEnter +}; + +/// for lnum argument in do_ecmd() +enum { + ECMD_LASTL = 0, ///< use last position in loaded file + ECMD_LAST = -1, ///< use last position in all files + ECMD_ONE = 1, ///< use first line +}; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_cmds.h.generated.h" #endif diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 5ece6db8e9..cf6282ad06 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -230,24 +230,6 @@ typedef struct { } magic; } CmdParseInfo; -/// flags for do_ecmd() -enum { - ECMD_HIDE = 0x01, ///< don't free the current buffer - ECMD_SET_HELP = 0x02, ///< set b_help flag of (new) buffer before opening file - ECMD_OLDBUF = 0x04, ///< use existing buffer if it exists - ECMD_FORCEIT = 0x08, ///< ! used in Ex command - ECMD_ADDBUF = 0x10, ///< don't edit, just add to buffer list - ECMD_ALTBUF = 0x20, ///< like ECMD_ADDBUF and set the alternate file - ECMD_NOWINENTER = 0x40, ///< do not trigger BufWinEnter -}; - -/// for lnum argument in do_ecmd() -enum { - ECMD_LASTL = 0, ///< use last position in loaded file - ECMD_LAST = -1, ///< use last position in all files - ECMD_ONE = 1, ///< use first line -}; - /// Previous :substitute replacement string definition typedef struct { char *sub; ///< Previous replacement string. diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index 7cec118243..5928999967 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -236,6 +236,7 @@ local keysets_defs = io.open(keysets_outputf, 'wb') output:write([[ #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" +#include "nvim/globals.h" #include "nvim/log.h" #include "nvim/map_defs.h" #include "nvim/msgpack_rpc/helpers.h" @@ -662,6 +663,7 @@ output:write([[ #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/func_attr.h" +#include "nvim/globals.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/dispatch.h" diff --git a/src/nvim/log.h b/src/nvim/log.h index 0a9a86c905..c6a033c634 100644 --- a/src/nvim/log.h +++ b/src/nvim/log.h @@ -1,5 +1,6 @@ #pragma once +#include "auto/config.h" #include "nvim/log_defs.h" // IWYU pragma: export #include "nvim/macros_defs.h" diff --git a/src/nvim/message.h b/src/nvim/message.h index 15a83fca2c..63d43fe47e 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -1,13 +1,36 @@ #pragma once +#include #include #include // IWYU pragma: keep +#include #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep #include "nvim/grid_defs.h" #include "nvim/macros_defs.h" #include "nvim/message_defs.h" // IWYU pragma: export +/// Types of dialogs passed to do_dialog(). +enum { + VIM_GENERIC = 0, + VIM_ERROR = 1, + VIM_WARNING = 2, + VIM_INFO = 3, + VIM_QUESTION = 4, + VIM_LAST_TYPE = 4, ///< sentinel value +}; + +/// Return values for functions like vim_dialogyesno() +enum { + VIM_YES = 2, + VIM_NO = 3, + VIM_CANCEL = 4, + VIM_ALL = 5, + VIM_DISCARDALL = 6, +}; + +enum { MSG_HIST = 0x1000, }; ///< special attribute addition: Put message in history + /// First message extern MessageHistoryEntry *first_msg_hist; /// Last message @@ -38,3 +61,14 @@ EXTERN int msg_listdo_overwrite INIT( = 0); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "message.h.generated.h" #endif + +// Prefer using semsg(), because perror() may send the output to the wrong +// destination and mess up the screen. +#define PERROR(msg) (void)semsg("%s: %s", (msg), strerror(errno)) + +#ifndef MSWIN +/// Headless (no UI) error message handler. +# define os_errmsg(str) fprintf(stderr, "%s", (str)) +/// Headless (no UI) message handler. +# define os_msg(str) printf("%s", (str)) +#endif diff --git a/src/nvim/message_defs.h b/src/nvim/message_defs.h index a0237ea78f..67e037fc0f 100644 --- a/src/nvim/message_defs.h +++ b/src/nvim/message_defs.h @@ -1,35 +1,12 @@ #pragma once -#include #include -#include #include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/grid_defs.h" #include "nvim/macros_defs.h" -/// Types of dialogs passed to do_dialog(). -enum { - VIM_GENERIC = 0, - VIM_ERROR = 1, - VIM_WARNING = 2, - VIM_INFO = 3, - VIM_QUESTION = 4, - VIM_LAST_TYPE = 4, ///< sentinel value -}; - -/// Return values for functions like vim_dialogyesno() -enum { - VIM_YES = 2, - VIM_NO = 3, - VIM_CANCEL = 4, - VIM_ALL = 5, - VIM_DISCARDALL = 6, -}; - -enum { MSG_HIST = 0x1000, }; ///< special attribute addition: Put message in history - typedef struct { String text; int attr; @@ -46,14 +23,3 @@ typedef struct msg_hist { bool multiline; ///< Multiline message. HlMessage multiattr; ///< multiattr message. } MessageHistoryEntry; - -// Prefer using semsg(), because perror() may send the output to the wrong -// destination and mess up the screen. -#define PERROR(msg) (void)semsg("%s: %s", (msg), strerror(errno)) - -#ifndef MSWIN -/// Headless (no UI) error message handler. -# define os_errmsg(str) fprintf(stderr, "%s", (str)) -/// Headless (no UI) message handler. -# define os_msg(str) printf("%s", (str)) -#endif diff --git a/src/nvim/option.h b/src/nvim/option.h index 44cba70302..2e4186fe7f 100644 --- a/src/nvim/option.h +++ b/src/nvim/option.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include // IWYU pragma: keep diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 17d179a56a..20b60150ee 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -20,6 +20,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/garray.h" #include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h"