Skip to content

Commit ae7e926

Browse files
committed
cleanup logging
ensure translation setup was done fixed tempfile writes for %a tools added CMakeLists.txt as a template for clang-tidy runs
1 parent 14a0127 commit ae7e926

5 files changed

Lines changed: 199 additions & 123 deletions

File tree

autorun/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.27)
2+
3+
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4+
5+
project(
6+
autorun
7+
VERSION 0.0.1
8+
LANGUAGES C
9+
DESCRIPTION "Geany action interceptor plugin")
10+
11+
# the `pkg_check_modules` function is created with this call
12+
find_package(PkgConfig REQUIRED)
13+
# these calls create special `PkgConfig::<MODULE>` variables
14+
pkg_check_modules(geany REQUIRED IMPORTED_TARGET GLOBAL geany)
15+
16+
add_library(${PROJECT_NAME} SHARED src/plugin_main.c src/autorun.c src/utils.c
17+
src/spawn.c)
18+
# prevent cmake from prefixing the shared library
19+
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
20+
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::geany)
21+
# install to users bin
22+
install(TARGETS ${PROJECT_NAME} DESTINATION plugins)

autorun/src/autorun.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,38 @@ AUTORUN_CMD* autorun_cmd_new() {
3838
void autorun_cmd_free(AUTORUN_CMD* cmd) {
3939
/* do not check for cmd->invalid because it could be a partial command
4040
* or invalidated after assembly. */
41-
if (cmd == NULL) {
41+
if (!cmd) {
4242
// who are you and why are you in my attic?
4343
return;
4444
}
4545
// free the command
46-
if (cmd->file_type != NULL) {
46+
if (cmd->file_type) {
4747
cmd->file_type = NULL;
4848
}
49-
if (cmd->interceptor != NULL) {
49+
if (cmd->interceptor) {
5050
g_free(cmd->interceptor);
5151
cmd->interceptor = NULL;
5252
}
53-
if (cmd->command != NULL) {
53+
if (cmd->command) {
5454
g_free(cmd->command);
5555
cmd->command = NULL;
5656
}
57-
if (cmd->working_dir != NULL) {
57+
if (cmd->working_dir) {
5858
g_free(cmd->working_dir);
5959
cmd->working_dir = NULL;
6060
}
6161
}
6262

6363
void autorun_cmd_list_free(GSList* command_list) {
64-
if (command_list == NULL) {
64+
if (!command_list) {
6565
// why are you naked?
6666
return;
6767
}
68-
g_message("command list had %i", g_slist_length(command_list));
6968
g_slist_free_full(command_list, (GDestroyNotify)autorun_cmd_free);
7069
}
7170

7271
void autorun_globals_init(GeanyPlugin* plugin) {
73-
if (!autorun_globals || autorun_globals == NULL) {
72+
if (!autorun_globals) {
7473
autorun_globals = g_new0(AUTORUN_GLOBALS, 1);
7574
autorun_globals->plugin = plugin;
7675
autorun_globals->data = plugin->geany_data;
@@ -80,12 +79,12 @@ void autorun_globals_init(GeanyPlugin* plugin) {
8079
}
8180

8281
void autorun_globals_free(void) {
83-
if (autorun_globals != NULL) {
84-
if (autorun_globals->filedef_commands != NULL) {
82+
if (autorun_globals) {
83+
if (autorun_globals->filedef_commands) {
8584
autorun_cmd_list_free(autorun_globals->filedef_commands);
8685
autorun_globals->filedef_commands = NULL;
8786
}
88-
if (autorun_globals->project_commands != NULL) {
87+
if (autorun_globals->project_commands) {
8988
autorun_cmd_list_free(autorun_globals->project_commands);
9089
autorun_globals->project_commands = NULL;
9190
}
@@ -114,21 +113,16 @@ void load_filedefs(void) {
114113
GError* gerr = NULL;
115114
gchar** handlers = g_key_file_get_keys(config, "autorun", &key_len, &gerr);
116115
// if the keyfile has an [autorun] section
117-
if (gerr == NULL) {
118-
g_message("found %s autorun", (gchar*)node->data);
116+
if (!gerr) {
119117
gchar** handler_key;
120118
foreach_strv(handler_key, handlers) {
121-
g_message(" %s", *handler_key);
122119
if (g_str_has_suffix(*handler_key, "CM")) {
123120
AUTORUN_CMD* cmd = autorun_cmd_new();
124121
cmd->file_type = filetypes_detect_from_file(node->data);
125-
g_message("filetype was %s", filetypes_get_display_name(cmd->file_type));
126122
parse_intercept_actions(*handler_key, config, cmd);
127123
if (!cmd->invalid) {
128124
// add the command
129125
autorun_globals->filedef_commands = g_slist_prepend(autorun_globals->filedef_commands, cmd);
130-
g_message("filedef list is %i", g_slist_length(autorun_globals->filedef_commands));
131-
132126
} else {
133127
// free the command
134128
autorun_cmd_free(cmd);
@@ -157,13 +151,11 @@ void load_projectdefs(GKeyFile* config) {
157151
GError* gerr = NULL;
158152
gchar** handlers = g_key_file_get_keys(config, "autorun", &key_len, &gerr);
159153
// if the keyfile has an [autorun] section
160-
if (gerr == NULL) {
161-
g_message("found project autorun");
154+
if (!gerr) {
162155
gchar** handler_key;
163156
// load any handlers
164157
foreach_strv(handler_key, handlers) {
165158
// over any existing [autorun] handlers
166-
g_message(" %s", *handler_key);
167159
if (g_str_has_suffix(*handler_key, "CM")) {
168160
AUTORUN_CMD* cmd = autorun_cmd_new();
169161
parse_intercept_actions(*handler_key, config, cmd);
@@ -178,7 +170,6 @@ void load_projectdefs(GKeyFile* config) {
178170
}
179171
// flip it around
180172
autorun_globals->project_commands = g_slist_reverse(autorun_globals->project_commands);
181-
g_message("proj command list is %i", g_slist_length(autorun_globals->project_commands));
182173
} else {
183174
g_free(gerr);
184175
}

autorun/src/plugin_main.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,64 @@
2424

2525
/* Handler to read any Project declared Auto-run configs */
2626
static void on_project_open(G_GNUC_UNUSED GObject* obj, GKeyFile* config, G_GNUC_UNUSED gpointer user_data) {
27-
g_message("on_project_open start");
28-
// TODO make this more smarter
29-
if (autorun_globals->project_commands == NULL) {
27+
if (!autorun_globals->project_commands) {
3028
load_projectdefs(config);
3129
}
32-
g_message("on_project_open end");
3330
}
3431

3532
// this handler is currently disconnected due to geany/geany#4603
3633
/* Handler to read any Project declared Auto-run configs */
3734
// static void on_project_save(G_GNUC_UNUSED GObject* obj, GKeyFile* config, G_GNUC_UNUSED gpointer user_data){
38-
// g_message("on_project_save");
3935
// load_projectdefs(config);
4036
// }
4137

4238
/* Handler to clear any old Project declared Auto-run configs */
4339
static void on_project_close(G_GNUC_UNUSED GObject* obj, G_GNUC_UNUSED gpointer user_data) {
44-
g_message("project close start");
4540
// unload project handlers
4641
autorun_cmd_list_free(autorun_globals->project_commands);
4742
autorun_globals->project_commands = NULL;
48-
g_message("project close end");
4943
}
5044

5145
/* Handler to run any applicable Auto-run configs after a write*/
52-
void on_doc_save(G_GNUC_UNUSED GObject* obj, GeanyDocument* doc, G_GNUC_UNUSED gpointer user_data) {
53-
g_message("on save start");
46+
static void on_doc_save(G_GNUC_UNUSED GObject* obj, GeanyDocument* doc, G_GNUC_UNUSED gpointer user_data) {
5447
/* disabled because geany/geany#4604 never sets doc->changed
5548
if(!doc->changed)
5649
{
57-
g_message("doc not changed?");
5850
return;
5951
}
6052
*/
53+
if (sci_get_length(doc->editor->sci) < 1) {
54+
// no point in processing a file so short
55+
return;
56+
}
6157
ui_progress_bar_start(NULL);
58+
/*
59+
* dont reset the msgwin here, as document-save
60+
* is the second stage of document-before-save
61+
* and the messages will all be logically related
62+
* to the user selecting File>Save
63+
*/
6264
dispatch_run("OS", doc);
6365
ui_progress_bar_stop();
64-
g_message("on save end");
6566
}
6667

6768
/* Handler to run any applicable Auto-run configs before a write*/
68-
void on_doc_before_save(G_GNUC_UNUSED GObject* obj, GeanyDocument* doc, G_GNUC_UNUSED gpointer user_data) {
69-
g_message("before save start");
69+
static void on_doc_before_save(G_GNUC_UNUSED GObject* obj, GeanyDocument* doc, G_GNUC_UNUSED gpointer user_data) {
7070
if (!doc->changed) {
71-
g_message("doc not changed?");
71+
return;
72+
}
73+
if (sci_get_length(doc->editor->sci) < 1) {
74+
// no point in processing a file so short
7275
return;
7376
}
7477
ui_progress_bar_start(NULL);
78+
// status is used for return codes, so dont clear that one
79+
// messages is used for stdout
80+
msgwin_clear_tab(MSG_MESSAGE);
81+
// compiler is used for stderr
82+
msgwin_clear_tab(MSG_COMPILER);
7583
dispatch_run("BS", doc);
7684
ui_progress_bar_stop();
77-
g_message("before save end");
7885
}
7986

8087
// clang-format off
@@ -90,38 +97,31 @@ PluginCallback plugin_callbacks[] = {
9097

9198
/* Bring up plugin and load filetypes.FILE that exist for Auto-run */
9299
static gboolean autorun_init(GeanyPlugin* plugin, gpointer pdata) {
93-
g_message("autorun_init start");
94-
if (!autorun_globals || autorun_globals == NULL) {
100+
if (!autorun_globals) {
95101
autorun_globals_init(plugin);
96102
load_filedefs();
97-
g_message("filedef command list is %i", g_slist_length(autorun_globals->filedef_commands));
98103

99104
// if initialized while a project is already open, manually ingest the project
100105
if (autorun_globals->data->app && autorun_globals->data->app->project) {
101106
// force a GKeyFile
102107
GKeyFile* config = g_key_file_new();
103108
g_key_file_load_from_file(config, autorun_globals->data->app->project->file_name, G_KEY_FILE_NONE, NULL);
104109
load_projectdefs(config);
105-
g_message("proj command list is %i", g_slist_length(autorun_globals->project_commands));
106110
g_free(config);
107111
}
108112
}
109-
g_message("autorun_init end");
110113
return TRUE;
111114
}
112115

113116
/* ensure destruction of any Auto-run objects */
114117
static void autorun_cleanup(GeanyPlugin* plugin, gpointer pdata) {
115-
g_message("autorun_cleanup start");
116-
if (autorun_globals != NULL) {
118+
if (autorun_globals) {
117119
autorun_globals_free();
118120
}
119-
g_message("autorun_cleanup end");
120121
}
121122

122123
G_MODULE_EXPORT
123124
void geany_load_module(GeanyPlugin* plugin) {
124-
g_message("load_module start");
125125
// who am we?
126126
plugin->info->name = "Auto-run";
127127
plugin->info->description = _("Geany action interceptor plugin");
@@ -138,5 +138,4 @@ void geany_load_module(GeanyPlugin* plugin) {
138138

139139
// go forth and come fifth.
140140
GEANY_PLUGIN_REGISTER(plugin, 225);
141-
g_message("load_module end");
142141
}

0 commit comments

Comments
 (0)