Version bump.
[geany-mirror.git] / src / editor.h
blob70b3c0ed3e4a4719fc569f22dfe53f04bee29a08
1 /*
2 * editor.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2010 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * $Id$
25 #ifndef GEANY_EDITOR_H
26 #define GEANY_EDITOR_H 1
28 #include "Scintilla.h"
29 #include "ScintillaWidget.h"
31 /** Default character set to define which characters should be treated as part of a word. */
32 #define GEANY_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
33 #define GEANY_MAX_WORD_LENGTH 192
36 /** Whether to use tabs, spaces or both to indent. */
37 typedef enum
39 GEANY_INDENT_TYPE_SPACES, /**< Spaces. */
40 GEANY_INDENT_TYPE_TABS, /**< Tabs. */
41 GEANY_INDENT_TYPE_BOTH /**< Both. */
43 GeanyIndentType;
45 typedef enum
47 GEANY_AUTOINDENT_NONE = 0,
48 GEANY_AUTOINDENT_BASIC,
49 GEANY_AUTOINDENT_CURRENTCHARS,
50 GEANY_AUTOINDENT_MATCHBRACES
52 GeanyAutoIndent;
54 typedef enum
56 GEANY_VIRTUAL_SPACE_DISABLED = 0,
57 GEANY_VIRTUAL_SPACE_SELECTION = 1,
58 GEANY_VIRTUAL_SPACE_ALWAYS = 3
60 GeanyVirtualSpace;
63 /* Auto-close brackets/quotes */
64 enum {
65 GEANY_AC_PARENTHESIS = 1,
66 GEANY_AC_CBRACKET = 2,
67 GEANY_AC_SBRACKET = 4,
68 GEANY_AC_SQUOTE = 8,
69 GEANY_AC_DQUOTE = 16
72 /** Geany indicator types, can be used with Editor indicator functions to highlight
73 * text in the document. */
74 typedef enum
76 /** Indicator to highlight errors in the document text. This is a red squiggly underline. */
77 GEANY_INDICATOR_ERROR = 0,
78 /** Indicator used to highlight search results in the document. This is a
79 * rounded box around the text. */
80 /* start container indicator outside of lexer indicators (0..7), see Scintilla docs */
81 GEANY_INDICATOR_SEARCH = 8
83 GeanyIndicator;
85 /** Indentation prefs that might be different according to project or filetype.
86 * Use @c editor_get_indent_prefs() to lookup the prefs for a particular document.
88 * @since 0.15
89 **/
90 typedef struct GeanyIndentPrefs
92 gint width; /**< Indent width. */
93 GeanyIndentType type; /**< Whether to use tabs, spaces or both to indent. */
94 /** Width of a tab, but only when using GEANY_INDENT_TYPE_BOTH.
95 * To get the display tab width, use sci_get_tab_width(). */
96 gint hard_tab_width;
97 GeanyAutoIndent auto_indent_mode;
98 gboolean detect_type;
100 GeanyIndentPrefs;
103 /** Default prefs when creating a new editor window.
104 * Some of these can be overridden per document or per project. */
105 typedef struct GeanyEditorPrefs
107 GeanyIndentPrefs *indentation; /*< Default indentation prefs. @see editor_get_indent_prefs(). */
108 gboolean show_white_space;
109 gboolean show_indent_guide;
110 gboolean show_line_endings;
111 /* 0 - line, 1 - background. This setting may be overriden when a project is opened. Use
112 * @c editor_get_long_line_type(). */
113 gint long_line_global_type;
114 /* This setting may be overriden when a project is opened. Use @c editor_get_long_line_column(). */
115 gint long_line_global_column;
116 gchar *long_line_color;
117 gboolean show_markers_margin; /* view menu */
118 gboolean show_linenumber_margin; /* view menu */
119 gboolean show_scrollbars; /* hidden pref */
120 gboolean scroll_stop_at_last_line;
121 gboolean line_wrapping;
122 gboolean use_indicators;
123 gboolean folding;
124 gboolean unfold_all_children;
125 gboolean disable_dnd;
126 gboolean use_tab_to_indent; /* makes tab key indent instead of insert a tab char */
127 gboolean smart_home_key;
128 gboolean newline_strip;
129 gboolean auto_complete_symbols;
130 gboolean auto_close_xml_tags;
131 gboolean complete_snippets;
132 gint symbolcompletion_min_chars;
133 gint symbolcompletion_max_height;
134 gboolean brace_match_ltgt; /* whether to highlight < and > chars (hidden pref) */
135 gboolean use_gtk_word_boundaries; /* hidden pref */
136 gboolean complete_snippets_whilst_editing; /* hidden pref */
137 gint line_break_column;
138 gboolean auto_continue_multiline;
139 gchar *comment_toggle_mark;
140 guint autocompletion_max_entries;
141 guint autoclose_chars;
142 gboolean autocomplete_doc_words;
143 gboolean completion_drops_rest_of_word;
144 gchar *color_scheme;
145 gint show_virtual_space;
146 /* This setting may be overriden when a project is opened. Use @c editor_get_long_line_type(). */
147 gboolean long_line_global_enabled;
149 GeanyEditorPrefs;
151 extern GeanyEditorPrefs editor_prefs;
154 /** Editor-owned fields for each document. */
155 struct GeanyEditor
157 GeanyDocument *document; /**< The document associated with the editor. */
158 ScintillaObject *sci; /**< The Scintilla editor @c GtkWidget. */
159 gboolean line_wrapping; /**< @c TRUE if line wrapping is enabled. */
160 gboolean auto_indent; /**< @c TRUE if auto-indentation is enabled. */
161 /** Percentage to scroll view by on paint, if positive. */
162 gfloat scroll_percent;
163 GeanyIndentType indent_type; /* Use editor_get_indent_prefs() instead. */
164 gboolean line_breaking; /**< Whether to split long lines as you type. */
168 typedef struct
170 gchar *current_word; /* holds word under the mouse or keyboard cursor */
171 gint click_pos; /* text position where the mouse was clicked */
172 } EditorInfo;
174 extern EditorInfo editor_info;
176 typedef struct SCNotification SCNotification;
179 void editor_init(void);
181 GeanyEditor *editor_create(GeanyDocument *doc);
183 void editor_destroy(GeanyEditor *editor);
185 ScintillaObject *editor_create_widget(GeanyEditor *editor);
187 void editor_sci_notify_cb(GtkWidget *widget, gint scn, gpointer scnt, gpointer data);
189 gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean force);
191 gboolean editor_complete_word_part(GeanyEditor *editor);
193 void editor_goto_next_snippet_cursor(GeanyEditor *editor);
195 gboolean editor_complete_snippet(GeanyEditor *editor, gint pos);
197 void editor_show_macro_list(GeanyEditor *editor);
199 gboolean editor_show_calltip(GeanyEditor *editor, gint pos);
201 void editor_do_comment_toggle(GeanyEditor *editor);
203 void editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_lines, gboolean toggle);
205 gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle);
207 gint editor_lexer_get_type_keyword_idx(gint lexer);
209 void editor_insert_multiline_comment(GeanyEditor *editor);
211 void editor_insert_alternative_whitespace(GeanyEditor *editor);
213 void editor_indent(GeanyEditor *editor, gboolean increase);
215 void editor_smart_line_indentation(GeanyEditor *editor, gint pos);
217 void editor_indentation_by_one_space(GeanyEditor *editor, gint pos, gboolean decrease);
219 gboolean editor_line_in_view(GeanyEditor *editor, gint line);
221 void editor_scroll_to_line(GeanyEditor *editor, gint line, gfloat percent_of_view);
223 void editor_display_current_line(GeanyEditor *editor, gfloat percent_of_view);
225 void editor_finalize(void);
227 void editor_snippets_init(void);
229 void editor_snippets_free(void);
231 /* 0 - line, 1 - background, 2 - disabled */
232 gint editor_get_long_line_type(void);
234 gint editor_get_long_line_column(void);
236 /* General editing functions */
238 void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, size_t wordlen,
239 const gchar *wc);
241 gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars);
243 gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word, const gchar *wordchars);
245 void editor_select_word(GeanyEditor *editor);
247 void editor_select_lines(GeanyEditor *editor, gboolean extra_line);
249 void editor_select_paragraph(GeanyEditor *editor);
251 void editor_set_font(GeanyEditor *editor, const gchar *font);
253 void editor_indicator_set_on_line(GeanyEditor *editor, gint indic, gint line);
255 void editor_indicator_clear_errors(GeanyEditor *editor);
257 void editor_indicator_set_on_range(GeanyEditor *editor, gint indic, gint start, gint end);
259 void editor_indicator_clear(GeanyEditor *editor, gint indic);
261 const gchar *editor_get_eol_char_name(GeanyEditor *editor);
263 gint editor_get_eol_char_len(GeanyEditor *editor);
265 const gchar *editor_get_eol_char(GeanyEditor *editor);
267 void editor_fold_all(GeanyEditor *editor);
269 void editor_unfold_all(GeanyEditor *editor);
271 void editor_replace_tabs(GeanyEditor *editor);
273 void editor_replace_spaces(GeanyEditor *editor);
275 void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line);
277 void editor_strip_trailing_spaces(GeanyEditor *editor);
279 void editor_ensure_final_newline(GeanyEditor *editor);
281 void editor_insert_color(GeanyEditor *editor, const gchar *colour);
283 const GeanyIndentPrefs *editor_get_indent_prefs(GeanyEditor *editor);
285 void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type);
287 void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap);
289 gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark);
291 gboolean editor_goto_line(GeanyEditor *editor, gint line_no, gint offset);
293 void editor_set_indentation_guides(GeanyEditor *editor);
295 void editor_apply_update_prefs(GeanyEditor *editor);
297 gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag);
299 void editor_insert_text_block(GeanyEditor *editor, const gchar *text,
300 gint insert_pos, gint cursor_index,
301 gint newline_indent_size, gboolean replace_newlines);
303 void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers);
305 #endif