Revision: 1352 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1352&view=re... Author: frlan Date: 2010-05-15 20:08:03 +0000 (Sat, 15 May 2010)
Log Message: ----------- GeanyLaTeX: Add a feature which is inserting {} automaticly once a new line is entered and an command seems to don't have some.
Modified Paths: -------------- trunk/geanylatex/ChangeLog trunk/geanylatex/TODO trunk/geanylatex/doc/geanylatex.pdf trunk/geanylatex/doc/geanylatex.tex trunk/geanylatex/src/geanylatex.c trunk/geanylatex/src/latexutils.c trunk/geanylatex/src/latexutils.h
Modified: trunk/geanylatex/ChangeLog =================================================================== --- trunk/geanylatex/ChangeLog 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/ChangeLog 2010-05-15 20:08:03 UTC (rev 1352) @@ -1,3 +1,9 @@ +2010-05-15 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * Add a feature which is inserting {} automaticly once a new line is + entered and an command seems to don't have some. + + 2010-05-10 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Fix indention on inserting list environments.
Modified: trunk/geanylatex/TODO =================================================================== --- trunk/geanylatex/TODO 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/TODO 2010-05-15 20:08:03 UTC (rev 1352) @@ -25,5 +25,4 @@ * Code examples for very common problems * Make special characters extensible through files * Improve behaviour of levelup and leveldown of structures -* Autoinserting {} when typing \command+return * Adding a font size chooser to toolbar
Modified: trunk/geanylatex/doc/geanylatex.pdf =================================================================== (Binary files differ)
Modified: trunk/geanylatex/doc/geanylatex.tex =================================================================== --- trunk/geanylatex/doc/geanylatex.tex 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/doc/geanylatex.tex 2010-05-15 20:08:03 UTC (rev 1352) @@ -109,11 +109,13 @@ \item Autocompletion of \texttt{\textbackslash{}end{}} and \texttt{\textbackslash{}endgroup{}} \end{itemize} - \item Proceeded to Geany Plugin API v166 + \item Proceeded to Geany Plugin API v184 \item Made reference insertion configurable. \item Added an function to insert \textbackslash{}usepackage{} into header of file \item Automatic adding of {} after typing of _{} and \symbol{94} + \item Added automatic inserting of {} after typing a command and + hitting return in case of none pair is already present \end{itemize}
\subsection*{GeanyLaTeX{} 0.4 -- 2009-05-26} @@ -707,7 +709,7 @@
\subsubsection{Autocompletion of {} after _ and \symbol{94}} - +\label{sec:autoadding_of_braces} Geany\LaTeX{} is able to autocomplete {} after typing _ and \symbol{94}. This might by useful on typing mathematic text and formula. However, as this option is turn on by default and it might @@ -728,6 +730,17 @@ \textbf{Note:} The feature in general is only working, if \texttt{glatex_set_autocompletion=true} is also set to \texttt{true}.
+\subsubsection{Autoadding of {} after a command} + +The plugin can autoadd a pair of braces {} on hitting return after typing a +command. The function will search for a \textbackslash{} and will +stop once it founds a space, some {} or a second \textbackslash{} +as on \textbackslash{} \textbackslash{}. This can be configured also +by using the hidden preference \texttt{glatex_set_autobraces} +described in chapter \ref{sec:autoadding_of_braces}, page \pageref +{sec:autoadding_of_braces}. + + \section{Contribution to the plugin} If you like the plugin, there are a number of ways, how to contribute to the development of the plugin.
Modified: trunk/geanylatex/src/geanylatex.c =================================================================== --- trunk/geanylatex/src/geanylatex.c 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/src/geanylatex.c 2010-05-15 20:08:03 UTC (rev 1352) @@ -453,7 +453,7 @@ while (isspace(buf[start]) && buf[start] != '\0') start++;
- /* check for begin */ + /* check for begin for autocompletion of \end{} and \endgr*/ if (strncmp(buf + start, "\begin", 6) == 0) { gchar full_cmd[15]; @@ -523,13 +523,56 @@ construct = g_strdup_printf("\t\n\end%s{%s}", full_cmd, env); editor_insert_text_block(editor, construct, pos, 1, -1, TRUE); - /* ... and setting the indention */ + /* ... and setting the indention */ sci_set_line_indentation(sci, sci_get_current_line(sci) + 1, indent); g_free(construct); } } - break; + + /* Now we are handling the case, a new line has been inserted + * but no closing braces */ + else if (glatex_autobraces_active == TRUE) + { + gint line = sci_get_line_from_position(sci, pos - + (editor_get_eol_char_len (editor) + 1)); + gint line_len = sci_get_line_length(sci, line) - + editor_get_eol_char_len (editor); + gint i; + gchar *buf; + + /* Catching current line which has been 'finished'*/ + buf = sci_get_line(sci, line); + + /* Searching for either \ or " ", {, } from end of + * line back to start */ + for (i = line_len; i >= 0 ; i--) + { + if (buf[i] == '\') + { + if ((i > 0 && buf[i-1] != '\') || + (i == 0)) + { + sci_insert_text(sci, + pos - (editor_get_eol_char_len (editor)), "{}"); + } + /* We will stop here in any case */ + break; + } + /* Else we want to stop once we found a space, + * some closing braces somewhere before as we + * are assuming, manipulating something here + * would cause a bigger mass. */ + else if (buf[i] == ' ' || + buf[i] == '}' || + buf[i] == '{') + { + break; + } + } + g_free(buf); + } + break; } /* Closing case \r or \n */ case '_': case '^': @@ -769,7 +812,7 @@
cmd_str = g_strdup_printf("\%s{", cmd); glatex_insert_string(cmd_str, TRUE); - /* This shall put the cursor inside the braces */ + /* This shall put the cursor inside the braces */ glatex_insert_string("}", FALSE);
sci_end_undo_action(doc->editor->sci); @@ -781,7 +824,7 @@ }
- + void glatex_insert_ref_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata)
Modified: trunk/geanylatex/src/latexutils.c =================================================================== --- trunk/geanylatex/src/latexutils.c 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/src/latexutils.c 2010-05-15 20:08:03 UTC (rev 1352) @@ -118,3 +118,9 @@ editor_insert_text_block(doc->editor, string, pos, len, 0, TRUE); } } + + +void glatex_insert_braces() +{ + glatex_insert_string("{}", FALSE); +}
Modified: trunk/geanylatex/src/latexutils.h =================================================================== --- trunk/geanylatex/src/latexutils.h 2010-05-15 16:37:07 UTC (rev 1351) +++ trunk/geanylatex/src/latexutils.h 2010-05-15 20:08:03 UTC (rev 1352) @@ -27,5 +27,6 @@ void glatex_usepackage(const gchar *pkg, const gchar *options); void glatex_enter_key_pressed_in_entry(G_GNUC_UNUSED GtkWidget *widget, gpointer dialog); void glatex_insert_string(gchar *string, gboolean reset_position); +void glatex_insert_braces();
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org