diff --git a/ChangeLog b/ChangeLog index 14ad78aa..8b175abb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * src/callbacks.c, THANKS: Cancel autocompletion on Undo/Redo (based on a patch by Jason Oster, thanks; #2102715). + * src/sciwrappers.c, src/document.c: + Apply patch (with minor changes) from Jason Oster to improve showing + brace indent guides on empty lines when appropriate (thanks, + #2105982). 2008-09-16 Nick Treleaven diff --git a/src/document.c b/src/document.c index 7e2f4176..942f0232 100644 --- a/src/document.c +++ b/src/document.c @@ -2167,6 +2167,7 @@ void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type) doc->tm_file = NULL; } highlighting_set_styles(doc->editor->sci, type->id); + sci_set_indentation_guides(doc->editor->sci, editor_prefs.show_indent_guide); build_menu_update(doc); queue_colourise(doc); } diff --git a/src/sciwrappers.c b/src/sciwrappers.c index a9341842..3eb9a778 100644 --- a/src/sciwrappers.c +++ b/src/sciwrappers.c @@ -32,6 +32,7 @@ #include "geany.h" +#include "SciLexer.h" #include "sciwrappers.h" #include "utils.h" @@ -373,7 +374,7 @@ gint sci_marker_previous(ScintillaObject* sci, gint line, gint marker_mask, gboo /** Get line number from position. * @param sci Scintilla widget. - * @param position Position. */ + * @param position Position. */ gint sci_get_line_from_position(ScintillaObject* sci, gint position ) { return SSM(sci, SCI_LINEFROMPOSITION, position, 0); @@ -382,7 +383,7 @@ gint sci_get_line_from_position(ScintillaObject* sci, gint position ) /** Get column number relative to the start of the line that @a position is on. * @param sci Scintilla widget. - * @param position Position. */ + * @param position Position. */ gint sci_get_col_from_position(ScintillaObject* sci, gint position ) { return SSM(sci, SCI_GETCOLUMN, position, 0); @@ -706,10 +707,49 @@ void sci_set_savepoint(ScintillaObject *sci) SSM(sci, SCI_SETSAVEPOINT, 0, 0); } +/* Should these be user-defined instead of hard-coded? */ +static gint get_indent_guides_from_lexer(gint lexer) +{ + switch (lexer) + { + /* These languages use indentation for control blocks; the "look forward" method works best here */ + case SCLEX_PYTHON: + case SCLEX_HASKELL: + case SCLEX_MAKEFILE: + case SCLEX_ASM: + case SCLEX_SQL: + case SCLEX_PROPERTIES: + case SCLEX_FORTRAN: /* Is this the best option for Fortran? */ + case SCLEX_CAML: + return SC_IV_LOOKFORWARD; + + /* C-like (structured) languages benefit from the "look both" method */ + case SCLEX_CPP: + case SCLEX_HTML: + case SCLEX_XML: + case SCLEX_PERL: + case SCLEX_LATEX: + case SCLEX_LUA: + case SCLEX_PASCAL: + case SCLEX_RUBY: + case SCLEX_TCL: + case SCLEX_F77: + case SCLEX_CSS: + case SCLEX_BASH: + case SCLEX_VHDL: + case SCLEX_FREEBASIC: + case SCLEX_D: + case SCLEX_OMS: + return SC_IV_LOOKBOTH; + } + + return SC_IV_REAL; +} void sci_set_indentation_guides(ScintillaObject *sci, gboolean enable) { - SSM(sci, SCI_SETINDENTATIONGUIDES, enable, 0); + gint lexer = sci_get_lexer(sci); + SSM(sci, SCI_SETINDENTATIONGUIDES, (enable ? get_indent_guides_from_lexer(lexer) : SC_IV_NONE), 0); }