Geany dev
Data Structures | Macros | Typedefs | Enumerations | Functions
editor.h File Reference

Editor-related functions for GeanyEditor. More...

Data Structures

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

Macros

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

Typedefs

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

ScintillaObject * editor_create_widget (GeanyEditor *editor)
 Creates a new Scintilla GtkWidget based on the settings for editor. More...
 
const gchar * editor_find_snippet (GeanyEditor *editor, const gchar *snippet_name)
 Gets snippet by name. 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...
 
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...
 
gint editor_get_eol_char_mode (GeanyEditor *editor)
 Retrieves the end of line characters mode (LF, CR/LF, CR) in the given editor. 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...
 
const GeanyIndentPrefseditor_get_indent_prefs (GeanyEditor *editor)
 Gets the indentation prefs for the 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...
 
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...
 
void editor_indicator_clear (GeanyEditor *editor, gint indic)
 Deletes all currently set indicators matching indic in the editor window. More...
 
void editor_indicator_set_on_line (GeanyEditor *editor, gint indic, gint line)
 Sets an indicator indic on line. 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_insert_snippet (GeanyEditor *editor, gint pos, const gchar *snippet)
 Replaces all special sequences in snippet and inserts it at pos. 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...
 
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...
 

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.

Typedef Documentation

◆ 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

◆ 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.

◆ 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.

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

◆ 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.

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

◆ 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.

◆ 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

◆ 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)