GNOME Bugzilla – Bug 312241
.lang files in homedir take priority over $prefix
Last modified: 2006-01-15 22:47:17 UTC
According to the TODO in gtksourceview/gtksourceview/gtksourcelanguagesmanager.c duplicated languages should be removed. I think we should keep the second file (the one from the user's home directory) because if a user changed a lang files into his home it's for work with his own version and not the system one. It will be easier to exchange the order in which the system dir and home dir are readed to have home first. The trivial way to do it will be to check the entire list before each insertion. The complexity of this is O(n²). Is it ok, or you want something more optimized?
Created attachment 50074 [details] [review] First patch to do that
*** This bug has been marked as a duplicate of 110978 ***
This is not a duplicated of 110978. Bug 110978 requires to implement a simple way for extending existing languages. For example a c_gtk.lang file that extends c.lang by adding support for the gtk+ functions and types.
Changing title to be more clear and to differentiate it from #110978. If you have 2 language files containing the same styles, one in $prefix and one in ~/.gnome2, gtksourceview should use the one in ~/.gnome2 (user override).
Created attachment 50310 [details] [review] same patch as before but read $HOME before to override $prefix
priority high due to the patch
Sorry for the very late reply. I think $HOME was already read before (we are using g_slist_prepend)... am I wrong? I'd like to include this patch in 1.4.1 (too late for 1.4.0, sorry).
the patch needs a bit of work because on head we changed the code to consider XDG_DATA_DIRS. I also agree with paolo that ~ was already searched before PREFIX/share.
Created attachment 56560 [details] [review] patch here is a different patch to achieve the same result. It uses an hashtable to avoid the dups without the inefficient list walking. It also fixes the leak of the filenames list, this is rather important indipendentely of the the rest of the patch. However note that I have not yet tested this patch well (just quickly started up gedit to see if it works), so handle with care.
Created attachment 56561 [details] [review] patch actually now that I tested it, it turns out that we owe Guillaume an apology :) If the ~/.gnome2/gtksourceview dir is first in the list of dirs to scan, it means that the files in that dir are considered *last*, since also when we collect the files list we prepend. This patch seems to work ok
Looks good. Minor comment below: - while (filenames != NULL) + lang_hash = g_hash_table_new (g_str_hash, g_str_equal); + + for (l = filenames; l != NULL; l = l->next) Why introduce a for loop here? Why not just l = filenames; while (l != NULL) etc.
the for loop is handy because we use 'continue' for (l = filenames; l != NULL; l = l->next) if (!foo) continue; ... with while you need l = l->next both at the end of the loop and before every 'continue' which is IMHO messy and error prone
committed (with a better comment and with the right for loop when adding xdg dirs)