1
1
/*
2
2
* latexenvironments.c
3
3
*
4
- * Copyright 2009-2012 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
4
+ * Copyright 2009-2024 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
5
5
*
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
@@ -69,6 +69,7 @@ void glatex_insert_environment(const gchar *environment, gint type)
69
69
/* Only do anything if it is realy needed to */
70
70
if (doc != NULL && environment != NULL )
71
71
{
72
+ /* Checking whether we do have a selection */
72
73
if (sci_has_selection (doc -> editor -> sci ))
73
74
{
74
75
gchar * selection = NULL ;
@@ -92,12 +93,9 @@ void glatex_insert_environment(const gchar *environment, gint type)
92
93
g_free (replacement );
93
94
94
95
}
95
- else
96
+ else /* No selection found*/
96
97
{
97
- gint indent , pos ;
98
- GString * tmpstring = NULL ;
99
- gchar * tmp = NULL ;
100
- static const GeanyIndentPrefs * indention_prefs = NULL ;
98
+ gchar * tmpstring = NULL ;
101
99
102
100
if (type == -1 )
103
101
{
@@ -114,49 +112,40 @@ void glatex_insert_environment(const gchar *environment, gint type)
114
112
}
115
113
}
116
114
}
117
- pos = sci_get_current_position (doc -> editor -> sci );
118
-
119
115
sci_start_undo_action (doc -> editor -> sci );
120
116
121
- tmpstring = g_string_new ("\\begin{" );
122
- g_string_append (tmpstring , environment );
123
-
124
117
if (utils_str_equal (environment , "block" ) == TRUE)
125
118
{
126
- g_string_append (tmpstring , "}{}" );
119
+ tmpstring = g_strconcat (
120
+ "\\begin{" ,
121
+ environment ,
122
+ "}{}\n%cursor%\n\\end{" ,
123
+ environment ,
124
+ "}" );
127
125
}
128
- else
126
+ else /* We don't have a block-like environment */
129
127
{
130
- g_string_append (tmpstring , "}" );
131
- }
132
- g_string_append (tmpstring , "\n" );
133
-
134
-
135
- if (type == GLATEX_ENVIRONMENT_TYPE_LIST )
136
- {
137
- g_string_append (tmpstring , "\t\\item " );
138
- }
139
-
140
- tmp = g_string_free (tmpstring , FALSE);
141
- glatex_insert_string (tmp , TRUE);
142
- g_free (tmp );
143
-
144
- indent = sci_get_line_indentation (doc -> editor -> sci ,
145
- sci_get_line_from_position (doc -> editor -> sci , pos ));
146
-
147
- tmp = g_strdup_printf ("\n\\end{%s}" , environment );
148
- glatex_insert_string (tmp , FALSE);
149
- g_free (tmp );
150
-
151
- indention_prefs = editor_get_indent_prefs (doc -> editor );
152
- if (type == GLATEX_ENVIRONMENT_TYPE_LIST )
153
- {
154
- sci_set_line_indentation (doc -> editor -> sci ,
155
- sci_get_current_line (doc -> editor -> sci ),
156
- indent + indention_prefs -> width );
128
+ if (type == GLATEX_ENVIRONMENT_TYPE_LIST )
129
+ {
130
+ tmpstring = g_strconcat (
131
+ "\\begin{" ,
132
+ environment ,
133
+ "}\n\t\\item %cursor% \n\\end{" ,
134
+ environment ,
135
+ "}" );
136
+ }
137
+ else
138
+ {
139
+ tmpstring = g_strconcat (
140
+ "\\begin{" ,
141
+ environment ,
142
+ "}\n%cursor%\n\\end{" ,
143
+ environment ,
144
+ "}" );
145
+ }
157
146
}
158
- sci_set_line_indentation ( doc -> editor -> sci ,
159
- sci_get_current_line ( doc -> editor -> sci ) + 1 , indent );
147
+ glatex_insert_snippet ( tmpstring );
148
+ g_free ( tmpstring );
160
149
sci_end_undo_action (doc -> editor -> sci );
161
150
}
162
151
}
0 commit comments