| 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 ws_error; \ | ||
| 41 | unsigned int text_width; \ | ||
| 42 | uint8_t indent_width; \ | ||
| 43 | uint8_t tab_width; \ | ||
| 44 | uint8_t save_unmodified; \ | ||
| 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 | uint8_t scroll_margin; | ||
| 79 | uint8_t crlf_newlines; // Default value for new files | ||
| 80 | uint8_t case_sensitive_search; // SearchCaseSensitivity | ||
| 81 | uint8_t window_separator; // WindowSeparatorType | ||
| 82 | uint8_t msg_compile; // Default EditorState::messages[] index for `compile` | ||
| 83 | uint8_t msg_tag; // Default EditorState::messages[] index for `tag` | ||
| 84 | unsigned int esc_timeout; // See term_read_input() | ||
| 85 | unsigned int filesize_limit; // Size limit imposed by load_buffer() (in MiB) | ||
| 86 | const char *statusline_left; | ||
| 87 | const char *statusline_right; | ||
| 88 | } GlobalOptions; | ||
| 89 | |||
| 90 | #undef COMMON_OPTIONS | ||
| 91 | |||
| 92 | 110 | static inline bool use_spaces_for_indent(const LocalOptions *opt) | |
| 93 | { | ||
| 94 |
3/4✓ Branch 2 → 3 taken 12 times.
✓ Branch 2 → 5 taken 98 times.
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 5 not taken.
|
110 | return opt->expand_tab || opt->indent_width != opt->tab_width; |
| 95 | } | ||
| 96 | |||
| 97 | struct EditorState; | ||
| 98 | |||
| 99 | bool set_option(struct EditorState *e, const char *name, const char *value, bool local, bool global); | ||
| 100 | bool set_bool_option(struct EditorState *e, const char *name, bool local, bool global); | ||
| 101 | bool toggle_option(struct EditorState *e, const char *name, bool global, bool verbose); | ||
| 102 | bool toggle_option_values(struct EditorState *e, const char *name, bool global, bool verbose, char **values, size_t count); | ||
| 103 | bool validate_local_options(ErrorBuffer *ebuf, char **strs); | ||
| 104 | void collect_options(PointerArray *a, const char *prefix, bool local, bool global); | ||
| 105 | void collect_auto_options(PointerArray *a, const char *prefix); | ||
| 106 | void collect_toggleable_options(PointerArray *a, const char *prefix, bool global); | ||
| 107 | void collect_option_values(struct EditorState *e, PointerArray *a, const char *option, const char *prefix); | ||
| 108 | String dump_options(GlobalOptions *gopts, LocalOptions *lopts); | ||
| 109 | const char *get_option_value_string(struct EditorState *e, const char *name); | ||
| 110 | |||
| 111 | #if DEBUG_ASSERTIONS_ENABLED | ||
| 112 | void sanity_check_global_options(ErrorBuffer *ebuf, const GlobalOptions *opts); | ||
| 113 | void sanity_check_local_options(ErrorBuffer *ebuf, const LocalOptions *lopts); | ||
| 114 | #else | ||
| 115 | static inline void sanity_check_global_options(ErrorBuffer* UNUSED_ARG(ebuf), const GlobalOptions* UNUSED_ARG(gopts)) {} | ||
| 116 | static inline void sanity_check_local_options(ErrorBuffer* UNUSED_ARG(ebuf), const LocalOptions* UNUSED_ARG(lopts)) {} | ||
| 117 | #endif | ||
| 118 | |||
| 119 | #endif | ||
| 120 |