[gedit] Load highlight mode from metadata for *.txt files



commit 24509405d2ff541013ede6ccb879570c108914e5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Nov 2 19:47:37 2013 +0100

    Load highlight mode from metadata for *.txt files
    
    guess_language() is called when the content type is modified. For a
    *.txt file, the content type has the same value as the init value, so
    the notify callback is not called, and the highlight mode is not
    changed. To fix the problem, we also call guess_language() when the
    document is loaded.
    
    For other files than *.txt, guess_language() is thus called two times in
    loaded(): when the content type is modified (via the notify callback),
    and when guess_language() is called directly.
    
    But it's better two times than zero.

 gedit/gedit-document.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 47e6f96..40bce93 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1502,6 +1502,16 @@ document_loader_loaded (GeditDocumentLoader *loader,
 
                        gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
                }
+
+               if (!doc->priv->language_set_by_user)
+               {
+                       GtkSourceLanguage *language = guess_language (doc, doc->priv->content_type);
+
+                       gedit_debug_message (DEBUG_DOCUMENT, "Language: %s",
+                                            language != NULL ? gtk_source_language_get_name (language) : 
"None");
+
+                       set_language (doc, language, FALSE);
+               }
        }
 
        /* special case creating a named new doc */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]