geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

editor.h File Reference

Editor-related functions for GeanyEditor. More...

#include "tm_tag.h"
#include "gtkcompat.h"
#include "Scintilla.h"
#include "ScintillaWidget.h"
#include <glib.h>
Include dependency graph for editor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GeanyIndentPrefs
 Indentation prefs that might be different according to project or filetype. More...
 
struct  GeanyEditorPrefs
 Default prefs when creating a new editor window. More...
 
struct  GeanyEditor
 Editor-owned fields for each document. More...
 

Macros

#define GEANY_WORDCHARS   "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 Default character set to define which characters should be treated as part of a word. More...
 
#define GEANY_MAX_WORD_LENGTH   192
 
#define GEANY_TYPE_EDITOR   (editor_get_type())
 

Typedefs

typedef struct GeanyIndentPrefs GeanyIndentPrefs
 Indentation prefs that might be different according to project or filetype. More...
 
typedef struct GeanyEditorPrefs GeanyEditorPrefs
 Default prefs when creating a new editor window. More...
 
typedef struct GeanyEditor GeanyEditor
 Editor-owned fields for each document. More...
 

Enumerations

enum  GeanyIndentType { GEANY_INDENT_TYPE_SPACES , GEANY_INDENT_TYPE_TABS , GEANY_INDENT_TYPE_BOTH }
 Whether to use tabs, spaces or both to indent. More...
 
enum  GeanyAutoIndent { GEANY_AUTOINDENT_NONE = 0 , GEANY_AUTOINDENT_BASIC , GEANY_AUTOINDENT_CURRENTCHARS , GEANY_AUTOINDENT_MATCHBRACES }
 
enum  GeanyIndicator { GEANY_INDICATOR_ERROR = 0 , GEANY_INDICATOR_SEARCH = 8 , GEANY_INDICATOR_SNIPPET = 9 }
 Geany indicator types, can be used with Editor indicator functions to highlight text in the document. More...
 

Functions

GType editor_get_type (void)
 
const GeanyIndentPrefseditor_get_indent_prefs (GeanyEditor *editor)
 Gets the indentation prefs for the editor. More...
 
ScintillaObject * editor_create_widget (GeanyEditor *editor)
 Creates a new Scintilla GtkWidget based on the settings for editor. More...
 
void editor_indicator_set_on_range (GeanyEditor *editor, gint indic, gint start, gint end)
 Sets an indicator on the range specified by start and end. More...
 
void editor_indicator_set_on_line (GeanyEditor *editor, gint indic, gint line)
 Sets an indicator indic on line. More...
 
void editor_indicator_clear (GeanyEditor *editor, gint indic)
 Deletes all currently set indicators matching indic in the editor window. More...
 
void editor_set_indent_type (GeanyEditor *editor, GeanyIndentType type)
 Sets the indent type for editor. More...
 
void editor_set_indent_width (GeanyEditor *editor, gint width)
 Sets the indent width for editor. More...
 
gchar * editor_get_word_at_pos (GeanyEditor *editor, gint pos, const gchar *wordchars)
 Finds the word at the position specified by pos. More...
 
const gchar * editor_get_eol_char_name (GeanyEditor *editor)
 Retrieves the localized name (for displaying) of the used end of line characters (LF, CR/LF, CR) in the given editor. More...
 
gint editor_get_eol_char_len (GeanyEditor *editor)
 Retrieves the length of the used end of line characters (LF, CR/LF, CR) in the given editor. More...
 
const gchar * editor_get_eol_char (GeanyEditor *editor)
 Retrieves the used end of line characters (LF, CR/LF, CR) in the given editor. More...
 
void editor_insert_text_block (GeanyEditor *editor, const gchar *text, gint insert_pos, gint cursor_index, gint newline_indent_size, gboolean replace_newlines)
 Inserts text, replacing \t tab chars (0x9) and \n newline chars (0xA) accordingly for the document. More...
 
gint editor_get_eol_char_mode (GeanyEditor *editor)
 Retrieves the end of line characters mode (LF, CR/LF, CR) in the given editor. More...
 
gboolean editor_goto_pos (GeanyEditor *editor, gint pos, gboolean mark)
 Moves to position pos, switching to the document if necessary, setting a marker if mark is set. More...
 
const gchar * editor_find_snippet (GeanyEditor *editor, const gchar *snippet_name)
 Gets snippet by name. More...
 
void editor_insert_snippet (GeanyEditor *editor, gint pos, const gchar *snippet)
 Replaces all special sequences in snippet and inserts it at pos. More...
 

Detailed Description

Editor-related functions for GeanyEditor.

Geany uses the Scintilla editing widget, and this file is mostly built around Scintilla's functionality.

See also
sciwrappers.h.

Definition in file editor.h.

Macro Definition Documentation

◆ GEANY_MAX_WORD_LENGTH

#define GEANY_MAX_WORD_LENGTH   192

Definition at line 41 of file editor.h.

◆ GEANY_TYPE_EDITOR

#define GEANY_TYPE_EDITOR   (editor_get_type())

Definition at line 145 of file editor.h.

◆ GEANY_WORDCHARS

#define GEANY_WORDCHARS   "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Default character set to define which characters should be treated as part of a word.

Definition at line 40 of file editor.h.

Typedef Documentation

◆ GeanyEditor

typedef struct GeanyEditor GeanyEditor

Editor-owned fields for each document.

◆ GeanyEditorPrefs

Default prefs when creating a new editor window.

Some of these can be overridden per document or per project.

◆ GeanyIndentPrefs

Indentation prefs that might be different according to project or filetype.

Use editor_get_indent_prefs() to lookup the prefs for a particular document.

Since
0.15

Enumeration Type Documentation

◆ GeanyAutoIndent

Enumerator
GEANY_AUTOINDENT_NONE 
GEANY_AUTOINDENT_BASIC 
GEANY_AUTOINDENT_CURRENTCHARS 
GEANY_AUTOINDENT_MATCHBRACES 

Definition at line 54 of file editor.h.

◆ GeanyIndentType

Whether to use tabs, spaces or both to indent.

Enumerator
GEANY_INDENT_TYPE_SPACES 

Spaces.

GEANY_INDENT_TYPE_TABS 

Tabs.

GEANY_INDENT_TYPE_BOTH 

Both.

Definition at line 44 of file editor.h.

◆ GeanyIndicator

Geany indicator types, can be used with Editor indicator functions to highlight text in the document.

Enumerator
GEANY_INDICATOR_ERROR 

Indicator to highlight errors in the document text.

This is a red squiggly underline.

GEANY_INDICATOR_SEARCH 

Indicator used to highlight search results in the document.

This is a rounded box around the text.

GEANY_INDICATOR_SNIPPET 

Definition at line 65 of file editor.h.

Function Documentation

◆ editor_create_widget()

ScintillaObject * editor_create_widget ( GeanyEditor editor)

Creates a new Scintilla GtkWidget based on the settings for editor.

Parameters
editorEditor settings.
Returns
(transfer: floating) The new widget.
Since
0.15

Definition at line 4984 of file editor.c.

References create_new_sci(), editor_apply_update_prefs(), GeanyInterfacePrefs::editor_font, editor_set_indent(), get_default_indent_prefs(), GeanyEditor::indent_type, GeanyEditor::indent_width, interface_prefs, sci, GeanyEditor::sci, set_font(), GeanyIndentPrefs::type, and GeanyIndentPrefs::width.

Referenced by begin_print(), editor_create(), and set_editor().

◆ editor_find_snippet()

const gchar * editor_find_snippet ( GeanyEditor editor,
const gchar *  snippet_name 
)

Gets snippet by name.

If editor is passed, returns a snippet specific to the document filetype. If editor is NULL, returns a snippet from the default set.

Parameters
editor Editor or NULL.
snippet_nameSnippet name.
Returns
snippet or NULL if it was not found. Must not be freed.

Definition at line 5322 of file editor.c.

References GeanyEditor::document, GeanyDocument::file_type, GeanyFiletype::name, NULL, and snippet_hash.

◆ editor_get_eol_char()

const gchar * editor_get_eol_char ( GeanyEditor editor)

Retrieves the used end of line characters (LF, CR/LF, CR) in the given editor.

If editor is NULL, the default end of line characters are used. The returned value is either "\n", "\r\n" or "\r".

Parameters
editor The editor to operate on, or NULL to query the default value.
Returns
The end of line characters.
Since
0.19

Definition at line 4349 of file editor.c.

References GeanyFilePrefs::default_eol_character, file_prefs, NULL, GeanyEditor::sci, sci_get_eol_mode(), and utils_get_eol_char().

Referenced by editor_ensure_final_newline(), editor_insert_text_block(), real_comment_multiline(), and split_line().

◆ editor_get_eol_char_len()

gint editor_get_eol_char_len ( GeanyEditor editor)

Retrieves the length of the used end of line characters (LF, CR/LF, CR) in the given editor.

If editor is NULL, the default end of line characters are used. The returned value is 1 for CR and LF and 2 for CR/LF.

Parameters
editor The editor to operate on, or NULL to query the default value.
Returns
The length of the end of line characters.
Since
0.19

Definition at line 4323 of file editor.c.

References GeanyFilePrefs::default_eol_character, file_prefs, NULL, SC_EOL_CRLF, GeanyEditor::sci, and sci_get_eol_mode().

Referenced by document_replace_sel(), editor_do_comment(), editor_do_comment_toggle(), editor_do_uncomment(), editor_indentation_by_one_space(), and editor_smart_line_indentation().

◆ editor_get_eol_char_mode()

gint editor_get_eol_char_mode ( GeanyEditor editor)

Retrieves the end of line characters mode (LF, CR/LF, CR) in the given editor.

If editor is NULL, the default end of line characters are used.

Parameters
editor The editor to operate on, or NULL to query the default value.
Returns
The used end of line characters mode.
Since
0.20

Definition at line 4279 of file editor.c.

References GeanyFilePrefs::default_eol_character, file_prefs, NULL, GeanyEditor::sci, and sci_get_eol_mode().

Referenced by convert_eol_characters(), document_open_file_full(), document_redo(), and document_undo().

◆ editor_get_eol_char_name()

const gchar * editor_get_eol_char_name ( GeanyEditor editor)

Retrieves the localized name (for displaying) of the used end of line characters (LF, CR/LF, CR) in the given editor.

If editor is NULL, the default end of line characters are used.

Parameters
editor The editor to operate on, or NULL to query the default value.
Returns
The name of the end of line characters.
Since
0.19

Definition at line 4301 of file editor.c.

References GeanyFilePrefs::default_eol_character, file_prefs, NULL, GeanyEditor::sci, sci_get_eol_mode(), and utils_get_eol_name().

◆ editor_get_indent_prefs()

const GeanyIndentPrefs * editor_get_indent_prefs ( GeanyEditor editor)

Gets the indentation prefs for the editor.

Prefs can be different according to project or document.

Warning
Always get a fresh result instead of keeping a pointer to it if the editor/project settings may have changed, or if this function has been called for a different editor.
Parameters
editor The editor, or NULL to get the default indent prefs.
Returns
The indent prefs.

Definition at line 1267 of file editor.c.

References GeanyEditor::auto_indent, GeanyIndentPrefs::auto_indent_mode, GEANY_AUTOINDENT_BASIC, GEANY_AUTOINDENT_NONE, get_default_indent_prefs(), GeanyEditor::indent_type, GeanyEditor::indent_width, NULL, GeanyIndentPrefs::type, and GeanyIndentPrefs::width.

Referenced by auto_multiline(), change_tab_indentation(), close_block(), create_statusbar_statistics(), detect_indent_width(), detect_tabs_and_spaces(), document_apply_indent_settings(), document_set_filetype(), editor_change_line_indent(), editor_get_prefs(), editor_insert_alternative_whitespace(), editor_set_indent(), fix_indentation(), get_default_prefs(), get_indent_size_after_line(), init_stash_prefs(), insert_indent_after_line(), and ui_document_show_hide().

◆ editor_get_type()

GType editor_get_type ( void  )

◆ editor_get_word_at_pos()

gchar * editor_get_word_at_pos ( GeanyEditor editor,
gint  pos,
const gchar *  wordchars 
)

Finds the word at the position specified by pos.

If any word is found, it is returned. Otherwise NULL is returned. Additional wordchars can be specified to define what to consider as a word.

Parameters
editorThe editor to operate on.
posThe position where the word should be read from. May be -1 to use the current position.
wordcharsThe wordchars to separate words. wordchars mean all characters to count as part of a word. May be NULL to use the default wordchars, see GEANY_WORDCHARS.
Returns
A newly-allocated string containing the word at the given pos or NULL. Should be freed when no longer needed.
Since
0.16

Definition at line 1791 of file editor.c.

References GEANY_MAX_WORD_LENGTH, NULL, pos, read_current_word(), and wordchars.

Referenced by autocomplete_scope().

◆ editor_goto_pos()

gboolean editor_goto_pos ( GeanyEditor editor,
gint  pos,
gboolean  mark 
)

Moves to position pos, switching to the document if necessary, setting a marker if mark is set.

Parameters
editorEditor.
posThe position.
markWhether to set a mark on the position.
Returns
TRUE if action has been performed, otherwise FALSE.
Since
0.20

Definition at line 4732 of file editor.c.

References GeanyEditor::document, document_show_tab(), line, pos, GeanyEditor::sci, sci_get_line_from_position(), sci_goto_pos(), sci_marker_delete_all(), sci_set_marker_at_line(), and GeanyEditor::scroll_percent.

Referenced by document_new_file(), document_open_file_full(), editor_goto_line(), goto_file_pos(), and navqueue_goto_line().

◆ editor_indicator_clear()

void editor_indicator_clear ( GeanyEditor editor,
gint  indic 
)

Deletes all currently set indicators matching indic in the editor window.

Parameters
editorThe editor to operate on.
indicThe indicator number to clear, this is a value of GeanyIndicator.
Since
0.16

Definition at line 4149 of file editor.c.

References NULL, GeanyEditor::sci, sci_get_length(), sci_indicator_clear(), and sci_indicator_set().

Referenced by editor_indicator_clear_errors(), on_menu_remove_indicators1_activate(), on_remove_markers1_activate(), and search_mark_all().

◆ editor_indicator_set_on_line()

void editor_indicator_set_on_line ( GeanyEditor editor,
gint  indic,
gint  line 
)

Sets an indicator indic on line.

Whitespace at the start and the end of the line is not marked.

Parameters
editorThe editor to operate on.
indicThe indicator number to use, this is a value of GeanyIndicator.
lineThe line number which should be marked.
Since
0.16

Definition at line 4175 of file editor.c.

References editor_indicator_set_on_range(), line, NULL, GeanyEditor::sci, sci_get_line(), sci_get_line_end_position(), and sci_get_position_from_line().

Referenced by goto_compiler_file_line(), and process_build_output_line().

◆ editor_indicator_set_on_range()

void editor_indicator_set_on_range ( GeanyEditor editor,
gint  indic,
gint  start,
gint  end 
)

Sets an indicator on the range specified by start and end.

No error checking or whitespace removal is performed, this should be done by the calling function if necessary.

Parameters
editorThe editor to operate on.
indicThe indicator number to use, this is a value of GeanyIndicator.
startThe starting position for the marker.
endThe ending position for the marker.
Since
0.16

Definition at line 4225 of file editor.c.

References NULL, GeanyEditor::sci, sci_indicator_fill(), and sci_indicator_set().

Referenced by editor_indicator_set_on_line(), editor_insert_text_block(), and search_mark_all().

◆ editor_insert_snippet()

void editor_insert_snippet ( GeanyEditor editor,
gint  pos,
const gchar *  snippet 
)

Replaces all special sequences in snippet and inserts it at pos.

If you insert at the current position, consider calling sci_scroll_caret() after this function.

Parameters
editor.
pos.
snippet.

Definition at line 5339 of file editor.c.

References editor_insert_text_block(), pos, and snippets_make_replacements().

Referenced by on_snippet_keybinding_activate(), and snippets_complete_constructs().

◆ editor_insert_text_block()

void editor_insert_text_block ( GeanyEditor editor,
const gchar *  text,
gint  insert_pos,
gint  cursor_index,
gint  newline_indent_size,
gboolean  replace_newlines 
)

Inserts text, replacing \t tab chars (0x9) and \n newline chars (0xA) accordingly for the document.

  • Leading tabs are replaced with the correct indentation.
  • Non-leading tabs are replaced with spaces (except when using 'Tabs' indent type).
  • Newline chars are replaced with the correct line ending string. This is very useful for inserting code without having to handle the indent type yourself (Tabs & Spaces mode can be tricky).
    Parameters
    editorEditor.
    textIntended as e.g. "if (foo)\n\tbar();".
    insert_posDocument position to insert text at.
    cursor_indexIf >= 0, the index into text to place the cursor.
    newline_indent_sizeIndentation size (in spaces) to insert for each newline; use -1 to read the indent size from the line with insert_pos on it.
    replace_newlinesWhether to replace newlines. If newlines have been replaced already, this should be false, to avoid errors e.g. on Windows.
    Warning
    Make sure all \t tab chars in text are intended as indent widths or alignment, not hard tabs, as those won't be preserved.
    Note
    This doesn't scroll the cursor in view afterwards.

Definition at line 2456 of file editor.c.

References count_indent_size(), editor_get_eol_char(), editor_indicator_set_on_range(), fix_indentation(), foreach_list, geany_cursor_marker, GEANY_INDICATOR_SNIPPET, SelectionRange::len, NULL, replace_cursor_markers(), sci, GeanyEditor::sci, sci_get_line(), sci_get_line_from_position(), sci_get_position_from_line(), sci_insert_text(), sci_set_current_position(), sci_set_selection(), SETPTR, SelectionRange::start, text, and utils_string_replace_all().

Referenced by editor_insert_snippet().

◆ editor_set_indent_type()

void editor_set_indent_type ( GeanyEditor editor,
GeanyIndentType  type 
)

Sets the indent type for editor.

Parameters
editorEditor.
typeIndent type.
Since
0.16

Definition at line 4649 of file editor.c.

References editor_set_indent(), and GeanyEditor::indent_width.

Referenced by on_detect_type_from_file_activate().

◆ editor_set_indent_width()

void editor_set_indent_width ( GeanyEditor editor,
gint  width 
)

Sets the indent width for editor.

Parameters
editorEditor.
widthNew indent width.
Since
1.27 (API 227)

Definition at line 4662 of file editor.c.

References editor_set_indent(), and GeanyEditor::indent_type.

Referenced by on_detect_width_from_file_activate(), and on_indent_width_activate().