prefs: Remove some global state in keybinding-related code
[geany-mirror.git] / src / editor.h
blobebd6968f0d7c1e48e1e9cf3f2c8655567f4f7454
1 /*
2 * editor.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef GEANY_EDITOR_H
24 #define GEANY_EDITOR_H 1
26 #include "tm_tag.h" /* for TMTag */
28 #include "gtkcompat.h" /* Needed by ScintillaWidget.h */
29 #include "Scintilla.h" /* Needed by ScintillaWidget.h */
30 #include "ScintillaWidget.h" /* for ScintillaObject */
32 #include <glib.h>
35 G_BEGIN_DECLS
37 /* Forward-declared to avoid including document.h since it includes this header */
38 struct GeanyDocument;
40 /** Default character set to define which characters should be treated as part of a word. */
41 #define GEANY_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
42 #define GEANY_MAX_WORD_LENGTH 192
45 /** Whether to use tabs, spaces or both to indent. */
46 typedef enum
48 GEANY_INDENT_TYPE_SPACES, /**< Spaces. */
49 GEANY_INDENT_TYPE_TABS, /**< Tabs. */
50 GEANY_INDENT_TYPE_BOTH /**< Both. */
52 GeanyIndentType;
54 typedef enum
56 GEANY_AUTOINDENT_NONE = 0,
57 GEANY_AUTOINDENT_BASIC,
58 GEANY_AUTOINDENT_CURRENTCHARS,
59 GEANY_AUTOINDENT_MATCHBRACES
61 GeanyAutoIndent;
63 typedef enum
65 GEANY_VIRTUAL_SPACE_DISABLED = 0,
66 GEANY_VIRTUAL_SPACE_SELECTION = 1,
67 GEANY_VIRTUAL_SPACE_ALWAYS = 3
69 GeanyVirtualSpace;
72 /* Auto-close brackets/quotes */
73 enum {
74 GEANY_AC_PARENTHESIS = 1,
75 GEANY_AC_CBRACKET = 2,
76 GEANY_AC_SBRACKET = 4,
77 GEANY_AC_SQUOTE = 8,
78 GEANY_AC_DQUOTE = 16
81 /** Geany indicator types, can be used with Editor indicator functions to highlight
82 * text in the document. */
83 typedef enum
85 /** Indicator to highlight errors in the document text. This is a red squiggly underline. */
86 GEANY_INDICATOR_ERROR = 0,
87 /** Indicator used to highlight search results in the document. This is a
88 * rounded box around the text. */
89 /* start container indicator outside of lexer indicators (0..7), see Scintilla docs */
90 GEANY_INDICATOR_SEARCH = 8
92 GeanyIndicator;
94 /** Indentation prefs that might be different according to project or filetype.
95 * Use @c editor_get_indent_prefs() to lookup the prefs for a particular document.
97 * @since 0.15
98 **/
99 typedef struct GeanyIndentPrefs
101 gint width; /**< Indent width. */
102 GeanyIndentType type; /**< Whether to use tabs, spaces or both to indent. */
103 /** Width of a tab, but only when using GEANY_INDENT_TYPE_BOTH.
104 * To get the display tab width, use sci_get_tab_width(). */
105 gint hard_tab_width;
106 GeanyAutoIndent auto_indent_mode;
107 gboolean detect_type;
108 gboolean detect_width;
110 GeanyIndentPrefs;
113 /** Default prefs when creating a new editor window.
114 * Some of these can be overridden per document or per project. */
115 /* See editor_get_prefs(). */
116 typedef struct GeanyEditorPrefs
118 GeanyIndentPrefs *indentation; /* Default indentation prefs. Use editor_get_indent_prefs(). */
119 gboolean show_white_space;
120 gboolean show_indent_guide;
121 gboolean show_line_endings;
122 /* 0 - line, 1 - background, 2 - disabled.
123 * This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */
124 gint long_line_type;
125 /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */
126 gint long_line_column;
127 gchar *long_line_color;
128 gboolean show_markers_margin; /* view menu */
129 gboolean show_linenumber_margin; /* view menu */
130 gboolean show_scrollbars; /* hidden pref */
131 gboolean scroll_stop_at_last_line;
132 gboolean line_wrapping;
133 gboolean use_indicators;
134 gboolean folding;
135 gboolean unfold_all_children;
136 gboolean disable_dnd;
137 gboolean use_tab_to_indent; /* makes tab key indent instead of insert a tab char */
138 gboolean smart_home_key;
139 gboolean newline_strip;
140 gboolean auto_complete_symbols;
141 gboolean auto_close_xml_tags;
142 gboolean complete_snippets;
143 gint symbolcompletion_min_chars;
144 gint symbolcompletion_max_height;
145 gboolean brace_match_ltgt; /* whether to highlight < and > chars (hidden pref) */
146 gboolean use_gtk_word_boundaries; /* hidden pref */
147 gboolean complete_snippets_whilst_editing; /* hidden pref */
148 gint line_break_column;
149 gboolean auto_continue_multiline;
150 gchar *comment_toggle_mark;
151 guint autocompletion_max_entries;
152 guint autoclose_chars;
153 gboolean autocomplete_doc_words;
154 gboolean completion_drops_rest_of_word;
155 gchar *color_scheme;
156 gint show_virtual_space;
157 /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */
158 gboolean long_line_enabled;
159 gint autocompletion_update_freq;
161 GeanyEditorPrefs;
163 extern GeanyEditorPrefs editor_prefs;
166 /** Editor-owned fields for each document. */
167 typedef struct GeanyEditor
169 struct GeanyDocument *document; /**< The document associated with the editor. */
170 ScintillaObject *sci; /**< The Scintilla editor @c GtkWidget. */
171 gboolean line_wrapping; /**< @c TRUE if line wrapping is enabled. */
172 gboolean auto_indent; /**< @c TRUE if auto-indentation is enabled. */
173 /** Percentage to scroll view by on paint, if positive. */
174 gfloat scroll_percent;
175 GeanyIndentType indent_type; /* Use editor_get_indent_prefs() instead. */
176 gboolean line_breaking; /**< Whether to split long lines as you type. */
177 gint indent_width;
179 GeanyEditor;
182 typedef struct
184 gchar *current_word; /* holds word under the mouse or keyboard cursor */
185 gint click_pos; /* text position where the mouse was clicked */
186 } EditorInfo;
188 extern EditorInfo editor_info;
190 typedef struct SCNotification SCNotification;
193 void editor_init(void);
195 GeanyEditor *editor_create(struct GeanyDocument *doc);
197 void editor_destroy(GeanyEditor *editor);
199 ScintillaObject *editor_create_widget(GeanyEditor *editor);
201 void editor_sci_notify_cb(GtkWidget *widget, gint scn, gpointer scnt, gpointer data);
203 gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean force);
205 gboolean editor_complete_word_part(GeanyEditor *editor);
207 void editor_goto_next_snippet_cursor(GeanyEditor *editor);
209 gboolean editor_complete_snippet(GeanyEditor *editor, gint pos);
211 void editor_show_macro_list(GeanyEditor *editor);
213 gboolean editor_show_calltip(GeanyEditor *editor, gint pos);
215 void editor_do_comment_toggle(GeanyEditor *editor);
217 gint editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_lines, gboolean toggle,
218 gboolean single_comment);
220 gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle);
222 void editor_insert_multiline_comment(GeanyEditor *editor);
224 void editor_insert_alternative_whitespace(GeanyEditor *editor);
226 void editor_indent(GeanyEditor *editor, gboolean increase);
228 void editor_smart_line_indentation(GeanyEditor *editor, gint pos);
230 void editor_indentation_by_one_space(GeanyEditor *editor, gint pos, gboolean decrease);
232 gboolean editor_line_in_view(GeanyEditor *editor, gint line);
234 void editor_scroll_to_line(GeanyEditor *editor, gint line, gfloat percent_of_view);
236 void editor_display_current_line(GeanyEditor *editor, gfloat percent_of_view);
238 void editor_finalize(void);
240 void editor_snippets_init(void);
242 void editor_snippets_free(void);
244 const GeanyEditorPrefs *editor_get_prefs(GeanyEditor *editor);
247 /* General editing functions */
249 void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen,
250 const gchar *wc);
252 void editor_find_current_word_sciwc(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen);
254 gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars);
256 gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word, const gchar *wordchars);
259 void editor_select_word(GeanyEditor *editor);
261 void editor_select_lines(GeanyEditor *editor, gboolean extra_line);
263 void editor_select_paragraph(GeanyEditor *editor);
265 void editor_select_indent_block(GeanyEditor *editor);
268 void editor_set_font(GeanyEditor *editor, const gchar *font);
270 void editor_indicator_set_on_line(GeanyEditor *editor, gint indic, gint line);
272 void editor_indicator_clear_errors(GeanyEditor *editor);
274 void editor_indicator_set_on_range(GeanyEditor *editor, gint indic, gint start, gint end);
276 void editor_indicator_clear(GeanyEditor *editor, gint indic);
278 gint editor_get_eol_char_mode(GeanyEditor *editor);
280 const gchar *editor_get_eol_char_name(GeanyEditor *editor);
282 gint editor_get_eol_char_len(GeanyEditor *editor);
284 const gchar *editor_get_eol_char(GeanyEditor *editor);
286 void editor_fold_all(GeanyEditor *editor);
288 void editor_unfold_all(GeanyEditor *editor);
290 void editor_replace_tabs(GeanyEditor *editor);
292 void editor_replace_spaces(GeanyEditor *editor);
294 void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line);
296 void editor_strip_trailing_spaces(GeanyEditor *editor);
298 void editor_ensure_final_newline(GeanyEditor *editor);
300 void editor_insert_color(GeanyEditor *editor, const gchar *colour);
302 const GeanyIndentPrefs *editor_get_indent_prefs(GeanyEditor *editor);
304 void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type);
306 void editor_set_indent_width(GeanyEditor *editor, gint width);
308 void editor_set_indent(GeanyEditor *editor, GeanyIndentType type, gint width);
310 void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap);
312 gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark);
314 gboolean editor_goto_line(GeanyEditor *editor, gint line_no, gint offset);
316 void editor_set_indentation_guides(GeanyEditor *editor);
318 void editor_apply_update_prefs(GeanyEditor *editor);
320 gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag);
322 void editor_insert_text_block(GeanyEditor *editor, const gchar *text,
323 gint insert_pos, gint cursor_index,
324 gint newline_indent_size, gboolean replace_newlines);
326 void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers);
328 const gchar *editor_find_snippet(GeanyEditor *editor, const gchar *snippet_name);
330 void editor_insert_snippet(GeanyEditor *editor, gint pos, const gchar *snippet);
332 G_END_DECLS
334 #endif /* GEANY_EDITOR_H */