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