1 /* 2 * editor.h - this file is part of Geany, a fast and lightweight IDE 3 * 4 * Copyright 2005 The Geany contributors 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 */ 20 21 22 #ifndef GEANY_EDITOR_H 23 #define GEANY_EDITOR_H 1 24 25 #include "tm_tag.h" /* for TMTag */ 26 27 #include "gtkcompat.h" /* Needed by ScintillaWidget.h */ 28 #include "Scintilla.h" /* Needed by ScintillaWidget.h */ 29 #include "ScintillaWidget.h" /* for ScintillaObject */ 30 31 #include <glib.h> 32 33 34 G_BEGIN_DECLS 35 36 /* Forward-declared to avoid including document.h since it includes this header */ 37 struct GeanyDocument; 38 39 /** Default character set to define which characters should be treated as part of a word. */ 40 #define GEANY_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 41 #define GEANY_MAX_WORD_LENGTH 192 42 43 /** Whether to use tabs, spaces or both to indent. */ 44 typedef enum 45 { 46 GEANY_INDENT_TYPE_SPACES, /**< Spaces. */ 47 GEANY_INDENT_TYPE_TABS, /**< Tabs. */ 48 GEANY_INDENT_TYPE_BOTH /**< Both. */ 49 } 50 GeanyIndentType; 51 52 /** @gironly 53 * Auto indentation modes */ 54 typedef enum 55 { 56 GEANY_AUTOINDENT_NONE = 0, 57 GEANY_AUTOINDENT_BASIC, 58 GEANY_AUTOINDENT_CURRENTCHARS, 59 GEANY_AUTOINDENT_MATCHBRACES 60 } 61 GeanyAutoIndent; 62 63 /** Geany indicator types, can be used with Editor indicator functions to highlight 64 * text in the document. */ 65 typedef enum 66 { 67 /** Indicator to highlight errors in the document text. This is a red squiggly underline. */ 68 GEANY_INDICATOR_ERROR = 0, 69 /** Indicator used to highlight search results in the document. This is a 70 * rounded box around the text. */ 71 /* start container indicator outside of lexer indicators (0..7), see Scintilla docs */ 72 GEANY_INDICATOR_SEARCH = 8, 73 GEANY_INDICATOR_SNIPPET = 9 74 } 75 GeanyIndicator; 76 77 /** Indentation prefs that might be different according to project or filetype. 78 * Use @c editor_get_indent_prefs() to lookup the prefs for a particular document. 79 * 80 * @since 0.15 81 **/ 82 typedef struct GeanyIndentPrefs 83 { 84 gint width; /**< Indent width. */ 85 GeanyIndentType type; /**< Whether to use tabs, spaces or both to indent. */ 86 /** Width of a tab, but only when using GEANY_INDENT_TYPE_BOTH. 87 * To get the display tab width, use sci_get_tab_width(). */ 88 gint hard_tab_width; 89 GeanyAutoIndent auto_indent_mode; 90 gboolean detect_type; 91 gboolean detect_width; 92 } 93 GeanyIndentPrefs; 94 95 /** Default prefs when creating a new editor window. 96 * Some of these can be overridden per document or per project. */ 97 /* @warning Use @c editor_get_prefs() instead to include project overrides. */ 98 typedef struct GeanyEditorPrefs 99 { 100 GeanyIndentPrefs *indentation; /* Default indentation prefs. Use editor_get_indent_prefs(). */ 101 gboolean show_white_space; 102 gboolean show_indent_guide; 103 gboolean show_line_endings; 104 /* 0 - line, 1 - background, 2 - disabled. */ 105 gint long_line_type; 106 gint long_line_column; 107 gchar *long_line_color; 108 gboolean show_markers_margin; /* view menu */ 109 gboolean show_linenumber_margin; /* view menu */ 110 gboolean show_scrollbars; /* hidden pref */ 111 gboolean scroll_stop_at_last_line; 112 gboolean line_wrapping; 113 gboolean use_indicators; 114 gboolean folding; 115 gboolean unfold_all_children; 116 gboolean disable_dnd; 117 gboolean use_tab_to_indent; /* makes tab key indent instead of insert a tab char */ 118 gboolean smart_home_key; 119 gboolean newline_strip; 120 gboolean auto_complete_symbols; 121 gboolean auto_close_xml_tags; 122 gboolean complete_snippets; 123 gint symbolcompletion_min_chars; 124 gint symbolcompletion_max_height; 125 gboolean brace_match_ltgt; /* whether to highlight < and > chars (hidden pref) */ 126 gboolean use_gtk_word_boundaries; /* hidden pref */ 127 gboolean complete_snippets_whilst_editing; /* hidden pref */ 128 gint line_break_column; 129 gboolean auto_continue_multiline; 130 gchar *comment_toggle_mark; 131 guint autocompletion_max_entries; 132 guint autoclose_chars; 133 gboolean autocomplete_doc_words; 134 gboolean completion_drops_rest_of_word; 135 gchar *color_scheme; 136 gint show_virtual_space; 137 gboolean long_line_enabled; 138 gint autocompletion_update_freq; 139 gint scroll_lines_around_cursor; 140 gint ime_interaction; /* input method editor's candidate window behaviour */ 141 } 142 GeanyEditorPrefs; 143 144 145 #define GEANY_TYPE_EDITOR (editor_get_type()) 146 GType editor_get_type (void); 147 148 /** Editor-owned fields for each document. */ 149 typedef struct GeanyEditor 150 { 151 struct GeanyDocument *document; /**< The document associated with the editor. */ 152 ScintillaObject *sci; /**< The Scintilla editor @c GtkWidget. */ 153 gboolean line_wrapping; /**< @c TRUE if line wrapping is enabled. */ 154 gboolean auto_indent; /**< @c TRUE if auto-indentation is enabled. */ 155 /** Percentage to scroll view by on paint, if positive. */ 156 gfloat scroll_percent; 157 GeanyIndentType indent_type; /* Use editor_get_indent_prefs() instead. */ 158 gboolean line_breaking; /**< Whether to split long lines as you type. */ 159 gint indent_width; 160 } 161 GeanyEditor; 162 163 164 const GeanyIndentPrefs *editor_get_indent_prefs(GeanyEditor *editor); 165 166 ScintillaObject *editor_create_widget(GeanyEditor *editor); 167 168 void editor_indicator_set_on_range(GeanyEditor *editor, gint indic, gint start, gint end); 169 170 void editor_indicator_set_on_line(GeanyEditor *editor, gint indic, gint line); 171 172 void editor_indicator_clear(GeanyEditor *editor, gint indic); 173 174 void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type); 175 176 void editor_set_indent_width(GeanyEditor *editor, gint width); 177 178 gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars); 179 180 const gchar *editor_get_eol_char_name(GeanyEditor *editor); 181 182 gint editor_get_eol_char_len(GeanyEditor *editor); 183 184 const gchar *editor_get_eol_char(GeanyEditor *editor); 185 186 void editor_insert_text_block(GeanyEditor *editor, const gchar *text, 187 gint insert_pos, gint cursor_index, 188 gint newline_indent_size, gboolean replace_newlines); 189 190 gint editor_get_eol_char_mode(GeanyEditor *editor); 191 192 gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark); 193 194 const gchar *editor_find_snippet(GeanyEditor *editor, const gchar *snippet_name); 195 196 void editor_insert_snippet(GeanyEditor *editor, gint pos, const gchar *snippet); 197 198 199 #ifdef GEANY_PRIVATE 200 201 extern GeanyEditorPrefs editor_prefs; 202 203 typedef enum 204 { 205 GEANY_VIRTUAL_SPACE_DISABLED = 0, 206 GEANY_VIRTUAL_SPACE_SELECTION = 1, 207 GEANY_VIRTUAL_SPACE_ALWAYS = 3 208 } 209 GeanyVirtualSpace; 210 211 /* Auto-close brackets/quotes */ 212 enum { 213 GEANY_AC_PARENTHESIS = 1, 214 GEANY_AC_CBRACKET = 2, 215 GEANY_AC_SBRACKET = 4, 216 GEANY_AC_SQUOTE = 8, 217 GEANY_AC_DQUOTE = 16 218 }; 219 220 typedef struct 221 { 222 gchar *current_word; /* holds word under the mouse or keyboard cursor */ 223 gint click_pos; /* text position where the mouse was clicked */ 224 } EditorInfo; 225 226 extern EditorInfo editor_info; 227 228 229 void editor_init(void); 230 231 GeanyEditor *editor_create(struct GeanyDocument *doc); 232 233 void editor_destroy(GeanyEditor *editor); 234 235 void editor_sci_notify_cb(GtkWidget *widget, gint scn, gpointer scnt, gpointer data); 236 237 gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean force); 238 239 gboolean editor_complete_word_part(GeanyEditor *editor); 240 241 gboolean editor_goto_next_snippet_cursor(GeanyEditor *editor); 242 243 gboolean editor_complete_snippet(GeanyEditor *editor, gint pos); 244 245 gboolean editor_show_calltip(GeanyEditor *editor, gint pos); 246 247 void editor_do_comment_toggle(GeanyEditor *editor); 248 249 gint editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_lines, gboolean toggle, 250 gboolean single_comment); 251 252 gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle); 253 254 void editor_insert_multiline_comment(GeanyEditor *editor); 255 256 void editor_insert_alternative_whitespace(GeanyEditor *editor); 257 258 void editor_indent(GeanyEditor *editor, gboolean increase); 259 260 void editor_smart_line_indentation(GeanyEditor *editor); 261 262 void editor_indentation_by_one_space(GeanyEditor *editor, gint pos, gboolean decrease); 263 264 gboolean editor_line_in_view(GeanyEditor *editor, gint line); 265 266 void editor_scroll_to_line(GeanyEditor *editor, gint line, gfloat percent_of_view); 267 268 void editor_display_current_line(GeanyEditor *editor, gfloat percent_of_view); 269 270 void editor_finalize(void); 271 272 void editor_snippets_init(void); 273 274 void editor_snippets_free(void); 275 276 const GeanyEditorPrefs *editor_get_prefs(GeanyEditor *editor); 277 278 279 /* General editing functions */ 280 281 void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen, 282 const gchar *wc); 283 284 void editor_find_current_word_sciwc(GeanyEditor *editor, gint pos, gchar *word, gsize wordlen); 285 286 gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word, const gchar *wordchars); 287 288 289 void editor_select_word(GeanyEditor *editor); 290 291 void editor_select_lines(GeanyEditor *editor, gboolean extra_line); 292 293 void editor_select_paragraph(GeanyEditor *editor); 294 295 void editor_select_indent_block(GeanyEditor *editor); 296 297 298 void editor_set_font(GeanyEditor *editor, const gchar *font); 299 300 void editor_indicator_clear_errors(GeanyEditor *editor); 301 302 void editor_fold_all(GeanyEditor *editor); 303 304 void editor_unfold_all(GeanyEditor *editor); 305 306 void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection); 307 308 void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection); 309 310 void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line); 311 312 void editor_strip_trailing_spaces(GeanyEditor *editor, gboolean ignore_selection); 313 314 void editor_ensure_final_newline(GeanyEditor *editor); 315 316 void editor_insert_color(GeanyEditor *editor, const gchar *colour); 317 318 void editor_set_indent(GeanyEditor *editor, GeanyIndentType type, gint width); 319 320 void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap); 321 322 gboolean editor_goto_line(GeanyEditor *editor, gint line_no, gint offset); 323 324 void editor_set_indentation_guides(GeanyEditor *editor); 325 326 void editor_apply_update_prefs(GeanyEditor *editor); 327 328 gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag); 329 330 void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers); 331 332 #endif /* GEANY_PRIVATE */ 333 334 G_END_DECLS 335 336 #endif /* GEANY_EDITOR_H */ 337