dte test coverage


Directory: ./
File: src/options.h
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 3 4 75.0%

Line Branch Exec Source
1 #ifndef OPTIONS_H
2 #define OPTIONS_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include "command/error.h"
7 #include "regexp.h"
8 #include "util/debug.h"
9 #include "util/macros.h"
10 #include "util/ptr-array.h"
11 #include "util/string.h"
12
13 enum {
14 INDENT_WIDTH_MAX = 8,
15 TAB_WIDTH_MAX = 8,
16 TEXT_WIDTH_MAX = 1000,
17 };
18
19 // Note: this must be kept in sync with ws_error_values[]
20 typedef enum {
21 WSE_SPACE_INDENT = 1 << 0, // Spaces in indent (except WSE_SPACE_ALIGN)
22 WSE_SPACE_ALIGN = 1 << 1, // Less than tab-width spaces at end of indent
23 WSE_TAB_INDENT = 1 << 2, // Tab in indent
24 WSE_TAB_AFTER_INDENT = 1 << 3, // Tab anywhere but indent
25 WSE_SPECIAL = 1 << 4, // Special whitespace characters
26 WSE_AUTO_INDENT = 1 << 5, // expand-tab ? WSE_TAB_AFTER_INDENT | WSE_TAB_INDENT : WSE_SPACE_INDENT
27 WSE_TRAILING = 1 << 6, // Trailing whitespace
28 WSE_ALL_TRAILING = 1 << 7, // Like WSE_TRAILING, but including around cursor
29 } WhitespaceErrorFlags;
30
31 // Note: this must be kept in sync with save_unmodified_enum[]
32 typedef enum {
33 SAVE_NONE,
34 SAVE_TOUCH,
35 SAVE_FULL,
36 } SaveUnmodifiedType;
37
38 #define COMMON_OPTIONS \
39 unsigned int detect_indent; \
40 unsigned int indent_width; \
41 unsigned int save_unmodified; \
42 unsigned int tab_width; \
43 unsigned int text_width; \
44 unsigned int ws_error; \
45 bool auto_indent; \
46 bool editorconfig; \
47 bool emulate_tab; \
48 bool expand_tab; \
49 bool file_history; \
50 bool fsync; \
51 bool overwrite; \
52 bool syntax
53
54 typedef struct {
55 COMMON_OPTIONS;
56 } CommonOptions;
57
58 // Note: all members should be initialized in buffer_new()
59 typedef struct {
60 COMMON_OPTIONS;
61 // Only local
62 bool brace_indent;
63 const char *filetype;
64 const InternedRegexp *indent_regex;
65 } LocalOptions;
66
67 typedef struct {
68 COMMON_OPTIONS;
69 // Only global
70 bool display_special;
71 bool lock_files;
72 bool optimize_true_color;
73 bool select_cursor_char;
74 bool set_window_title;
75 bool show_line_numbers;
76 bool tab_bar;
77 bool utf8_bom; // Default value for new files
78 unsigned int esc_timeout;
79 unsigned int filesize_limit;
80 unsigned int scroll_margin;
81 unsigned int crlf_newlines; // Default value for new files
82 unsigned int case_sensitive_search; // SearchCaseSensitivity
83 unsigned int window_separator; // WindowSeparatorType
84 const char *statusline_left;
85 const char *statusline_right;
86 } GlobalOptions;
87
88 #undef COMMON_OPTIONS
89
90 110 static inline bool use_spaces_for_indent(const LocalOptions *opt)
91 {
92
3/4
✓ Branch 0 (2→3) taken 12 times.
✓ Branch 1 (2→5) taken 98 times.
✓ Branch 2 (3→4) taken 12 times.
✗ Branch 3 (3→5) not taken.
110 return opt->expand_tab || opt->indent_width != opt->tab_width;
93 }
94
95 struct EditorState;
96
97 bool set_option(struct EditorState *e, const char *name, const char *value, bool local, bool global);
98 bool set_bool_option(struct EditorState *e, const char *name, bool local, bool global);
99 bool toggle_option(struct EditorState *e, const char *name, bool global, bool verbose);
100 bool toggle_option_values(struct EditorState *e, const char *name, bool global, bool verbose, char **values, size_t count);
101 bool validate_local_options(ErrorBuffer *ebuf, char **strs);
102 void collect_options(PointerArray *a, const char *prefix, bool local, bool global);
103 void collect_auto_options(PointerArray *a, const char *prefix);
104 void collect_toggleable_options(PointerArray *a, const char *prefix, bool global);
105 void collect_option_values(struct EditorState *e, PointerArray *a, const char *option, const char *prefix);
106 String dump_options(GlobalOptions *gopts, LocalOptions *lopts);
107 const char *get_option_value_string(struct EditorState *e, const char *name);
108
109 #if DEBUG >= 1
110 void sanity_check_global_options(ErrorBuffer *ebuf, const GlobalOptions *opts);
111 void sanity_check_local_options(ErrorBuffer *ebuf, const LocalOptions *lopts);
112 #else
113 static inline void sanity_check_global_options(ErrorBuffer* UNUSED_ARG(ebuf), const GlobalOptions* UNUSED_ARG(gopts)) {}
114 static inline void sanity_check_local_options(ErrorBuffer* UNUSED_ARG(ebuf), const LocalOptions* UNUSED_ARG(lopts)) {}
115 #endif
116
117 #endif
118