Revision: 3776 http://geany.svn.sourceforge.net/geany/?rev=3776&view=rev Author: eht16 Date: 2009-05-10 17:44:28 +0000 (Sun, 10 May 2009)
Log Message: ----------- Refactor some multiple used code into get_multiline_comment_style().
Modified Paths: -------------- trunk/ChangeLog trunk/src/editor.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-05-10 17:44:14 UTC (rev 3775) +++ trunk/ChangeLog 2009-05-10 17:44:28 UTC (rev 3776) @@ -3,6 +3,8 @@ * src/ui_utils.c: Make the clear icon of entry fields act on the release event, not on the press event like for other buttons. + * src/editor.c: + Refactor some multiple used code into get_multiline_comment_style().
2009-05-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2009-05-10 17:44:14 UTC (rev 3775) +++ trunk/src/editor.c 2009-05-10 17:44:28 UTC (rev 3776) @@ -2371,6 +2371,37 @@ }
+static gint get_multiline_comment_style(GeanyEditor *editor, gint line_start) +{ + gint lexer = SSM(editor->sci, SCI_GETLEXER, 0, 0); + gint style_comment; + + /* List only those lexers which support multi line comments */ + switch (lexer) + { + case SCLEX_XML: + case SCLEX_HTML: + { + if (is_style_php(sci_get_style_at(editor->sci, line_start))) + style_comment = SCE_HPHP_COMMENT; + else + style_comment = SCE_H_COMMENT; + break; + } + case SCLEX_HASKELL: style_comment = SCE_HA_COMMENTBLOCK; break; + case SCLEX_LUA: style_comment = SCE_LUA_COMMENT; break; + case SCLEX_CSS: style_comment = SCE_CSS_COMMENT; break; + case SCLEX_SQL: style_comment = SCE_SQL_COMMENT; break; + case SCLEX_CAML: style_comment = SCE_CAML_COMMENT; break; + case SCLEX_D: style_comment = SCE_D_COMMENT; break; + case SCLEX_PASCAL: style_comment = SCE_PAS_COMMENT; break; + default: style_comment = SCE_C_COMMENT; + } + + return style_comment; +} + + /* set toggle to TRUE if the caller is the toggle function, FALSE otherwise * returns the amount of uncommented single comment lines, in case of multi line uncomment * it returns just 1 */ @@ -2472,26 +2503,9 @@ else { gint style_comment; - gint lexer = SSM(editor->sci, SCI_GETLEXER, 0, 0);
- /* process only lines which are already comments */ - switch (lexer) - { /* I will list only those lexers which support multi line comments */ - case SCLEX_XML: - case SCLEX_HTML: - { - if (is_style_php(sci_get_style_at(editor->sci, line_start))) - style_comment = SCE_HPHP_COMMENT; - else style_comment = SCE_H_COMMENT; - break; - } - case SCLEX_CSS: style_comment = SCE_CSS_COMMENT; break; - case SCLEX_SQL: style_comment = SCE_SQL_COMMENT; break; - case SCLEX_CAML: style_comment = SCE_CAML_COMMENT; break; - case SCLEX_D: style_comment = SCE_D_COMMENT; break; - case SCLEX_PASCAL: style_comment = SCE_PAS_COMMENT; break; - default: style_comment = SCE_C_COMMENT; - } + /* skip lines which are already comments */ + style_comment = get_multiline_comment_style(editor, line_start); if (sci_get_style_at(editor->sci, line_start + x) == style_comment) { real_uncomment_multiline(editor); @@ -2618,28 +2632,9 @@ else { gint style_comment; - gint lexer = SSM(editor->sci, SCI_GETLEXER, 0, 0);
/* skip lines which are already comments */ - switch (lexer) - { /* I will list only those lexers which support multi line comments */ - case SCLEX_XML: - case SCLEX_HTML: - { - if (is_style_php(sci_get_style_at(editor->sci, line_start))) - style_comment = SCE_HPHP_COMMENT; - else style_comment = SCE_H_COMMENT; - break; - } - case SCLEX_CSS: style_comment = SCE_CSS_COMMENT; break; - case SCLEX_SQL: style_comment = SCE_SQL_COMMENT; break; - case SCLEX_CAML: style_comment = SCE_CAML_COMMENT; break; - case SCLEX_D: style_comment = SCE_D_COMMENT; break; - case SCLEX_RUBY: style_comment = SCE_RB_POD; break; - case SCLEX_PERL: style_comment = SCE_PL_POD; break; - case SCLEX_PASCAL: style_comment = SCE_PAS_COMMENT; break; - default: style_comment = SCE_C_COMMENT; - } + style_comment = get_multiline_comment_style(editor, line_start); if (sci_get_style_at(editor->sci, line_start + x) == style_comment) { real_uncomment_multiline(editor); @@ -2790,29 +2785,11 @@ else { gint style_comment; - gint lexer = SSM(editor->sci, SCI_GETLEXER, 0, 0);
/* skip lines which are already comments */ - switch (lexer) - { /* I will list only those lexers which support multi line comments */ - /* FIXME Update the list of filetypes and move this switch into a separate - * function to avoid duplicate code. */ - case SCLEX_XML: - case SCLEX_HTML: - { - if (is_style_php(sci_get_style_at(editor->sci, line_start))) - style_comment = SCE_HPHP_COMMENT; - else style_comment = SCE_H_COMMENT; - break; - } - case SCLEX_CSS: style_comment = SCE_CSS_COMMENT; break; - case SCLEX_SQL: style_comment = SCE_SQL_COMMENT; break; - case SCLEX_CAML: style_comment = SCE_CAML_COMMENT; break; - case SCLEX_D: style_comment = SCE_D_COMMENT; break; - case SCLEX_PASCAL: style_comment = SCE_PAS_COMMENT; break; - default: style_comment = SCE_C_COMMENT; - } - if (sci_get_style_at(editor->sci, line_start + x) == style_comment) continue; + style_comment = get_multiline_comment_style(editor, line_start); + if (sci_get_style_at(editor->sci, line_start + x) == style_comment) + continue;
real_comment_multiline(editor, line_start, last_line);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.