2424
2525/* Handler to read any Project declared Auto-run configs */
2626static 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 */
4339static 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 */
9299static 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 */
114117static 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
122123G_MODULE_EXPORT
123124void 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