This MR migrates the feature to insert any environment over to Geany's snippets workflow. Hence we don't need to bother about indention, like breaks etc. this much anymore. Also due to the cursor-feature it ensures to position the cursor at the right place , independent from the line break, indention etc.
Due to this rework it makes the code also a little more readable and fixes #1071 You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/1330
-- Commit Summary --
* LaTeX: Switch handling of insert (list) envioronment over to snippets workflow
-- File Changes --
M latex/src/latexenvironments.c (58) M latex/src/latexutils.c (12) M latex/src/latexutils.h (1)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/1330.patch https://github.com/geany/geany-plugins/pull/1330.diff
@eht16 commented on this pull request.
Looks good.
As you know I'm not LaTeX expert and so I'm wondering if it is on purpose that different environments produce quite different stylings:
``` \begin{block}{} _ \end{block}
\begin{itemize} \item _ \end{itemize}
\begin{table} _ \end{table} ```
For "table" and "itemize" there is a trailing space after the cursor marker. Is this intended?
"block" uses no indentation at all, "itemize" uses a tab resp. spaces and "table" uses a single space only.
@@ -103,6 +114,7 @@ glatex_insert_string(const gchar *string, gboolean reset_position)
doc = document_get_current();
+
Was this on purpose?
@eht16 commented on this pull request.
if (utils_str_equal(environment, "block") == TRUE)
{ - g_string_append(tmpstring, "}{}"); + tmpstring = g_strdup_printf("\begin{%s}{}\n%%cursor%%\n\end{%s}", environment, environment);
It might be more readable using "g_strconcat" like above in https://github.com/geany/geany-plugins/pull/1330/files#diff-44b2e13e0c1bd775...
@frlan commented on this pull request.
if (utils_str_equal(environment, "block") == TRUE)
{ - g_string_append(tmpstring, "}{}"); + tmpstring = g_strdup_printf("\begin{%s}{}\n%%cursor%%\n\end{%s}", environment, environment);
True. Should be better now (even though not sure about the line breaks inside the call as it's a very long string …"
@frlan pushed 1 commit.
6728529322b028c0e0791ba8ecec968042ac8c6d LaTeX: Switch handling of insert (list) environments over to snippets workflow
Looks good.
As you know I'm not LaTeX expert and so I'm wondering if it is on purpose that different environments produce quite different stylings:
\begin{block}{} _ \end{block} \begin{itemize} \item _ \end{itemize} \begin{table} _ \end{table}
For "table" and "itemize" there is a trailing space after the cursor marker. Is this intended?
"block" uses no indentation at all, "itemize" uses a tab resp. spaces and "table" uses a single space only.
This is fixed. I tried to re-sync the indentions
@eht16 commented on this pull request.
tmp = g_strdup_printf("\n\\end{%s}", environment);
- glatex_insert_string(tmp, FALSE); - g_free(tmp); - - indention_prefs = editor_get_indent_prefs(doc->editor); - if (type == GLATEX_ENVIRONMENT_TYPE_LIST) - { - sci_set_line_indentation(doc->editor->sci, - sci_get_current_line(doc->editor->sci), - indent + indention_prefs->width); + if (type == GLATEX_ENVIRONMENT_TYPE_LIST) + { + tmpstring = g_strconcat( + "\begin{", + environment, + "}\n\t\item %cursor% \n\end{",
There is still a trailing space.
For "table" and "itemize" there is a trailing space after the cursor marker. Is this intended? "block" uses no indentation at all, "itemize" uses a tab resp. spaces and "table" uses a single space only.
This is fixed. I tried to re-sync the indentions
I cannot verify as I do not know what is the purposed variant. To me it looks inconsistent: ![Screenshot_2024-04-26_18-38-28](https://github.com/geany/geany-plugins/assets/617017/47d46203-5f95-4454-a03b...)
More importantly, the rubbisch after the "block" environment is because `g_strconcat()` must always be NULL-terminated which it is not in the newly added code.
@frlan pushed 1 commit.
5fb3c82fa0c7024cfa78586afa4da0f3b279f019 Propper NULL-terminate strings and fix an trailing space inside a template
Looks good now.
As said before, I cannot judge whether the result of the snippets is as desired. To me it feels a little confusing that the element in the "itemize" environment is indented while for the other ones the cursor position is not indented. Maybe it's ok.
In the end it's a little matter of taste, but compare it to HTML's ```html <ul> <li>...</li> </ul> ``` and ```html <body> … </body>
@eht16 approved this pull request.
Merged #1330 into master.
github-comments@lists.geany.org