From dba4b278f81f7dfe94d5cc0dea4dcc849b531cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 18 May 2008 16:03:20 +0000 Subject: [PATCH] Force using tabs for indentation when opening Makefiles. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2596 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++++ src/document.c | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 016d510eb..c58e3ccc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-18 Enrico Tröger + + * src/document.c: + Force using tabs for indentation when opening Makefiles. + + 2008-05-16 Enrico Tröger * plugins/pluginmacros.h, plugins/vcdiff.c, src/build.c, diff --git a/src/document.c b/src/document.c index 87920fa54..a8360af58 100644 --- a/src/document.c +++ b/src/document.c @@ -946,6 +946,25 @@ static gboolean detect_use_tabs(ScintillaObject *sci) } +static void set_indentation(gint idx) +{ + /* force using tabs for indentation for Makefiles */ + if (FILETYPE_ID(doc_list[idx].file_type) == GEANY_FILETYPES_MAKE) + editor_set_use_tabs(idx, TRUE); + else if (! editor_prefs.detect_tab_mode) + editor_set_use_tabs(idx, editor_prefs.use_tabs); + else + { /* detect & set tabs/spaces */ + gboolean use_tabs = detect_use_tabs(doc_list[idx].sci); + + if (use_tabs != editor_prefs.use_tabs) + ui_set_statusbar(TRUE, _("Setting %s indentation mode."), + (use_tabs) ? _("Tabs") : _("Spaces")); + editor_set_use_tabs(idx, use_tabs); + } +} + + /* To open a new file, set idx to -1; filename should be locale encoded. * To reload a file, set the idx for the document to be reloaded; filename should be NULL. * pos is the cursor position, which can be overridden by --line and --column. @@ -1038,21 +1057,6 @@ gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean sci_set_eol_mode(doc_list[idx].sci, editor_mode); g_free(filedata.data); - if (reload) - editor_set_use_tabs(idx, doc_list[idx].use_tabs); /* resetup sci */ - else - if (! editor_prefs.detect_tab_mode) - editor_set_use_tabs(idx, editor_prefs.use_tabs); - else - { /* detect & set tabs/spaces */ - gboolean use_tabs = detect_use_tabs(doc_list[idx].sci); - - if (use_tabs != editor_prefs.use_tabs) - ui_set_statusbar(TRUE, _("Setting %s indentation mode."), - (use_tabs) ? _("Tabs") : _("Spaces")); - editor_set_use_tabs(idx, use_tabs); - } - sci_set_undo_collection(doc_list[idx].sci, TRUE); doc_list[idx].mtime = filedata.mtime; /* get the modification time from file and keep it */ @@ -1092,6 +1096,12 @@ gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean /* update taglist, typedef keywords and build menu if necessary */ document_set_filetype(idx, use_ft); + /* set indentation settings after setting the filetype */ + if (reload) + editor_set_use_tabs(idx, doc_list[idx].use_tabs); /* resetup sci */ + else + set_indentation(idx); + document_set_text_changed(idx); /* also updates tab state */ ui_document_show_hide(idx); /* update the document menu */ @@ -1414,8 +1424,9 @@ gboolean document_save_file(gint idx, gboolean force) return FALSE; } - /* replaces tabs by spaces */ - if (file_prefs.replace_tabs) editor_replace_tabs(idx); + /* replaces tabs by spaces but only if the current file is not a Makefile */ + if (file_prefs.replace_tabs && FILETYPE_ID(doc_list[idx].file_type) != GEANY_FILETYPES_MAKE) + editor_replace_tabs(idx); /* strip trailing spaces */ if (file_prefs.strip_trailing_spaces) editor_strip_trailing_spaces(idx); /* ensure the file has a newline at the end */