From 99ead577f795505d704df5d1b7580a80df1215e1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 28 Jul 2012 13:20:12 +0400 Subject: [PATCH 1/4] Ticket #2848: fixup of user-defined keymap load. Modify algorithm of keymap files load: 1) Unconditionally load /usr/share/mc/mc.keymap 2) Unconditionally load /etc/mc/mc.keymap Then load one of following user-defined keymaps, stop on success: 3) set via --keymap command line option 4) set via MC_KEYMAP environment variable 5) set via keymap key in config file 6) ~/.config/mc/mc.keymap Fix of double load of keymap file if name is same as name of system-wide keymap file. Update man pages. Signed-off-by: Andrew Borodin --- doc/man/mc.1.in | 15 ++++--- doc/man/ru/mc.1.in | 18 ++++---- src/setup.c | 108 +++++++++++++++++++++++++-------------------- 3 files changed, 76 insertions(+), 65 deletions(-) diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 26ae6c629..1ac90b0a5 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -66,7 +66,7 @@ Display configure options. Reset softkeys to their default from the termcap/terminfo database. Only useful on HP terminals when the function keys don't work. .TP -.I \-K file +.I \-K file, \-\-keymap=file Specify a name of keymap file in the command line. .TP .I \-\-nokeymap @@ -325,7 +325,13 @@ the input lines in the query dialogs. .\"NODE " Keys_redefine" .SH " Redefine hotkey bindings" Hotkey bindings may be read from external file (keymap\-file). -A keymap\-file is searched on the following algorithm (to the first one found): +Initially, Mignight Commander creates key bindings using keymap defined +in the source code. Then, two files +.B %prefix%/share/mc/mc.keymap +and +.B %sysconfdir%/mc/mc.keymap +are loaded always, sequentially reassigned key bindings defined earlier. +User\-defined keymap\-file is searched on the following algorithm (to the first one found): .IP .br 1) command line option @@ -345,11 +351,6 @@ of config file. 4) File .B ~/.config/mc/mc.keymap .br -5) File -.B %sysconfdir%/mc/mc.keymap -.br -6) File -.B %prefix%/share/mc/mc.keymap .PP Command line option, environment variable and parameter in config file may contain the absolute path to the keymap\-file (with the extension \.keymap diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in index c498e0cb9..30e6516c7 100644 --- a/doc/man/ru/mc.1.in +++ b/doc/man/ru/mc.1.in @@ -79,7 +79,7 @@ UNIX\-подобных операционных системах. termcap/terminfo. Этот ключ используется только на терминалах HP, где функциональные клавиши не работают. .TP -.I \-K файл +.I \-K файл, \-\-keymap=файл Задаёт файл клавиатурных команд для переопределения привязки клавиатурных комбинаций к действиям. .TP @@ -320,8 +320,14 @@ S\-<символ> означает, что нужно держать в нажа .\"NODE " Keys_redefine" .SH " Переопределение клавиатурных команд" Клавиатурные команды могут быть прочитаны из внешнего файла. -Поиск файла клавиатурных команд производится по следующему алгоритму -(до первого нахождения файла): +Сначала Midnight Commander создаёт карту клавиатурных команд из списка, +определённого в исходном коде. Затем всегда загружаются два файла +.B %sysconfdir%/mc/mc.keymap +и +.B %prefix%/share/mc/mc.keymap , +последовательно переопределяя ранее загруженные команды. +Поиск файла клавиатурных команд, определённого пользователем, производится +по следующему алгоритму (до первого нахождения файла): .IP .br 1) параметр командной строки @@ -341,12 +347,6 @@ S\-<символ> означает, что нужно держать в нажа 4) файл .B ~/.config/mc/mc.keymap .br -5) файл -.B %sysconfdir%/mc/mc.keymap -.br -6) файл -.B %prefix%/share/mc/mc.keymap - .PP Параметры в трёх первых случаях могут содержать абсолютный путь к файлу клавиатурных команд либо просто название схемы привязки (с расширением diff --git a/src/setup.c b/src/setup.c index 2b6c9bf74..062f6c2f8 100644 --- a/src/setup.c +++ b/src/setup.c @@ -371,22 +371,15 @@ static const struct /** Get name of config file. - \param subdir - if not NULL, then config also search into specified subdir. - - \param config_file_name - If specified filename is relative, then will search in standart patches. - - \return - Newly allocated path to config name or NULL if file not found. - - If config_file_name is a relative path, then search config in stantart paths. + @param subdir If not NULL, config is also searched in specified subdir. + @param config_file_name If relative, file if searched in standard paths. + @returns Newly allocated string with config name or NULL if file is not found. */ static char * load_setup_get_full_config_name (const char *subdir, const char *config_file_name) { /* - TODO: IMHO, in future this function must be placed into mc_config module. + TODO: IMHO, in future, this function shall be placed in mcconfig module. */ char *lc_basename, *ret; @@ -394,8 +387,11 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam return NULL; if (g_path_is_absolute (config_file_name)) - return g_strdup (config_file_name); - + { + ret = g_strdup (config_file_name); + canonicalize_pathname (ret); + return ret; + } lc_basename = g_path_get_basename (config_file_name); if (lc_basename == NULL) @@ -409,6 +405,7 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam if (exist_file (ret)) { g_free (lc_basename); + canonicalize_pathname (ret); return ret; } g_free (ret); @@ -421,6 +418,7 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam if (exist_file (ret)) { g_free (lc_basename); + canonicalize_pathname (ret); return ret; } g_free (ret); @@ -433,11 +431,13 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam g_free (lc_basename); if (exist_file (ret)) + { + canonicalize_pathname (ret); return ret; + } g_free (ret); return NULL; - } /* --------------------------------------------------------------------------------------------- */ @@ -519,7 +519,7 @@ static void load_setup_init_config_from_file (mc_config_t ** config, const char *fname) { /* - TODO: IMHO, in future this function must be placed into mc_config module. + TODO: IMHO, in future, this function shall be placed in mcconfig module. */ if (exist_file (fname)) { @@ -676,9 +676,10 @@ static mc_config_t * load_setup_get_keymap_profile_config (gboolean load_from_file) { /* - TODO: IMHO, in future this function must be placed into mc_config module. + TODO: IMHO, in future, this function shall be placed in mcconfig module. */ mc_config_t *keymap_config; + char *share_keymap, *sysconfig_keymap; char *fname, *fname2; /* 0) Create default keymap */ @@ -686,47 +687,56 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) if (!load_from_file) return keymap_config; + /* load and merge global keymaps */ + /* 1) /usr/share/mc (mc_global.share_data_dir) */ - fname = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file (&keymap_config, fname); - g_free (fname); + share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL); + load_setup_init_config_from_file (&keymap_config, share_keymap); /* 2) /etc/mc (mc_global.sysconfig_dir) */ - fname = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file (&keymap_config, fname); + sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); + load_setup_init_config_from_file (&keymap_config, sysconfig_keymap); + + /* then load and merge one of user-defined keymap */ + + /* 3) --keymap= */ + fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file); + if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) + { + load_setup_init_config_from_file (&keymap_config, fname); + goto done; + } g_free (fname); - /* 3) ${XDG_CONFIG_HOME}/mc */ + /* 4) getenv("MC_KEYMAP") */ + fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP")); + if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) + { + load_setup_init_config_from_file (&keymap_config, fname); + goto done; + } + g_free (fname); + + /* 5) main config; [Midnight Commander] -> keymap */ + fname2 = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", NULL); + if (fname2 != NULL && *fname2 != '\0') + fname = load_setup_get_full_config_name (NULL, fname2); + g_free (fname2); + if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) + { + load_setup_init_config_from_file (&keymap_config, fname); + goto done; + } + g_free (fname); + + /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */ fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE); load_setup_init_config_from_file (&keymap_config, fname); + + done: g_free (fname); - - /* 4) main config; [Midnight Commander] -> keymap */ - fname2 = - mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", GLOBAL_KEYMAP_FILE); - fname = load_setup_get_full_config_name (NULL, fname2); - if (fname != NULL) - { - load_setup_init_config_from_file (&keymap_config, fname); - g_free (fname); - } - g_free (fname2); - - /* 5) getenv("MC_KEYMAP") */ - fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP")); - if (fname != NULL) - { - load_setup_init_config_from_file (&keymap_config, fname); - g_free (fname); - } - - /* 6) --keymap= */ - fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file); - if (fname != NULL) - { - load_setup_init_config_from_file (&keymap_config, fname); - g_free (fname); - } + g_free (sysconfig_keymap); + g_free (share_keymap); return keymap_config; } From 09427eacadc8c726cb2b07d85e9961c6ca236bbe Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 28 Jul 2012 13:38:47 +0400 Subject: [PATCH 2/4] mc.keymap.default, mc.keymap.emacs: comment out unassigned commands. Signed-off-by: Andrew Borodin --- misc/mc.keymap.default | 146 +++++++++++++++++----------------- misc/mc.keymap.emacs | 175 ++++++++++++++++++++--------------------- 2 files changed, 160 insertions(+), 161 deletions(-) diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default index 20fb04c41..8eff1439e 100644 --- a/misc/mc.keymap.default +++ b/misc/mc.keymap.default @@ -2,9 +2,9 @@ Help = f1 UserMenu = f2 View = f3 -ViewFile = +# ViewFile = Edit = f4 -EditForceInternal = +# EditForceInternal = Copy = f5 Move = f6 MakeDir = f7 @@ -21,9 +21,9 @@ DirSize = ctrl-space Suspend = ctrl-z Swap = ctrl-u History = alt-h -PanelListing = +# PanelListing = PanelListingSwitch = alt-t -PanelListingChange = +# PanelListingChange = ShowHidden = alt-dot SplitVertHoriz = alt-comma SplitEqual = alt-equal @@ -37,20 +37,20 @@ Select = kpplus Unselect = kpminus SelectInvert = kpasterisk ScreenList = alt-prime -OptionsLayout = -OptionsPanel = -OptionsConfirm = -OptionsDisplayBits = -OptionsVfs = -LearnKeys = -SaveSetup = -EditExtensionsFile = -EditFileHighlightFile = -Filter = -ConnectFish = -ConnectFtp = -ConnectSmb = -Undelete = +# OptionsLayout = +# OptionsPanel = +# OptionsConfirm = +# OptionsDisplayBits = +# OptionsVfs = +# LearnKeys = +# SaveSetup = +# EditExtensionsFile = +# EditFileHighlightFile = +# Filter = +# ConnectFish = +# ConnectFtp = +# ConnectSmb = +# Undelete = ExtendedKeyMap = ctrl-x [main:xmap] @@ -80,8 +80,8 @@ Search = ctrl-s; alt-s Mark = insert; ctrl-t MarkUp = shift-up MarkDown = shift-down -MarkLeft = -MarkRight = +# MarkLeft = +# MarkRight = Down = down; ctrl-n Up = up; ctrl-p Left = left @@ -101,8 +101,8 @@ Unselect = alt-minus SelectInvert = alt-asterisk CdChild = ctrl-pgdn CdParent = ctrl-pgup -CdParentSmart = -Panelize = +# CdParentSmart = +# Panelize = History = alt-shift-h HistoryNext = alt-u HistoryPrev = alt-y @@ -113,16 +113,16 @@ PanelOtherSync = alt-i SelectCodepage = alt-e Top = alt-lt; home; a1 Bottom = alt-gt; end; c1 -Sort = -SortPrev = -SortNext = -SortReverse = -SortByName = -SortByExt = -SortBySize = -SortByMTime = -ScrollLeft = -ScrollRight = +# Sort = +# SortPrev = +# SortNext = +# SortReverse = +# SortByName = +# SortByExt = +# SortBySize = +# SortByMTime = +# ScrollLeft = +# ScrollRight = [dialog] Ok = enter @@ -149,18 +149,18 @@ Backspace = backspace; ctrl-h Delete = delete; ctrl-d DeleteToWordBegin = alt-backspace DeleteToWordEnd = alt-d -Mark = +# Mark = Remove = ctrl-w -Cut = +# Cut = Store = alt-w -Paste = +# Paste = Yank = ctrl-y DeleteToEnd = ctrl-k HistoryPrev = alt-p; ctrl-down HistoryNext = alt-n; ctrl-up History = alt-h Complete = alt-tab -Clear = +# Clear = MarkLeft = shift-left MarkRight = shift-right MarkToWordBegin = ctrl-shift-left @@ -247,26 +247,26 @@ DeleteToWordBegin = alt-backspace DeleteToWordEnd = alt-d DeleteLine = ctrl-y DeleteToEnd = ctrl-k -DeleteToHome = -ParagraphUp = -ParagraphDown = +# DeleteToHome = +# ParagraphUp = +# ParagraphDown = Save = f2 -EditFile = +# EditFile = EditNew = ctrl-n SaveAs = f12; ctrl-f2 -Close = +# Close = Mark = f3 Copy = f5 Move = f6 Remove = f8 -MarkLine = -MarkWord = -MarkAll = -Unmark = +# MarkLine = +# MarkWord = +# MarkAll = +# Unmark = Search = f7 SearchContinue = f17 -BlockShiftLeft = -BlockShiftRight = +# BlockShiftLeft = +# BlockShiftRight = MarkPageUp = shift-pgup MarkPageDown = shift-pgdn MarkLeft = shift-left @@ -283,18 +283,18 @@ MarkToPageBegin = ctrl-shift-pgup MarkToPageEnd = ctrl-shift-pgdn MarkScrollUp = ctrl-shift-up MarkScrollDown = ctrl-shift-down -MarkParagraphUp = -MarkParagraphDown = +# MarkParagraphUp = +# MarkParagraphDown = MarkColumnPageUp = alt-pgup MarkColumnPageDown = alt-pgdn MarkColumnLeft = alt-left MarkColumnRight = alt-right MarkColumnUp = alt-up MarkColumnDown = alt-down -MarkColumnScrollUp = -MarkColumnScrollDown = -MarkColumnParagraphUp = -MarkColumnParagraphDown = +# MarkColumnScrollUp = +# MarkColumnScrollDown = +# MarkColumnParagraphUp = +# MarkColumnParagraphDown = BlockSave = ctrl-f MarkColumn = f13 Replace = f4 @@ -304,7 +304,7 @@ InsertFile = f15 Quit = f10; esc InsertOverwrite = insert Help = f1 -Date = +# Date = Refresh = ctrl-l Goto = alt-l Sort = alt-t @@ -318,36 +318,36 @@ Bookmark = alt-k BookmarkFlush = alt-o BookmarkNext = alt-j BookmarkPrev = alt-i -History = +# History = Shell = ctrl-o InsertLiteral = ctrl-q -MacroStartRecord = -MacroStopRecord = +# MacroStartRecord = +# MacroStopRecord = MacroStartStopRecord = ctrl-r -MacroDelete = +# MacroDelete = ShowNumbers = alt-n ShowTabTws = alt-underline SyntaxOnOff = ctrl-s -SyntaxChoose = -ShowMargin = +# SyntaxChoose = +# ShowMargin = Find = alt-enter FilePrev = alt-minus FileNext = alt-plus -RepeatStartStopRecord = +# RepeatStartStopRecord = SelectCodepage = alt-e -Options = -OptionsSaveMode = -SpellCheck = +# Options = +# OptionsSaveMode = +# SpellCheck = SpellCheckCurrentWord = ctrl-p -SpellCheckSelectLang = -LearnKeys = -WindowMove = -WindowResize = -WindowFullscreen = -WindowList = -WindowNext = -WindowPrev = -ExtendedKeyMap = +# SpellCheckSelectLang = +# LearnKeys = +# WindowMove = +# WindowResize = +# WindowFullscreen = +# WindowList = +# WindowNext = +# WindowPrev = +# ExtendedKeyMap = [viewer] Help = f1 diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs index c50603c97..415ad713e 100644 --- a/misc/mc.keymap.emacs +++ b/misc/mc.keymap.emacs @@ -2,9 +2,9 @@ Help = f1 UserMenu = f2 View = f3 -ViewFile = +# ViewFile = Edit = f4 -EditForceInternal = +# EditForceInternal = Copy = f5 Move = f6 MakeDir = f7 @@ -21,9 +21,9 @@ DirSize = ctrl-space Suspend = ctrl-z Swap = ctrl-u History = alt-h -PanelListing = +# PanelListing = PanelListingSwitch = alt-t -PanelListingChange = +# PanelListingChange = ShowHidden = alt-dot SplitVertHoriz = alt-comma SplitEqual = alt-equal @@ -37,21 +37,20 @@ Select = kpplus Unselect = kpminus SelectInvert = kpasterisk ScreenList = alt-prime -Options = -OptionsLayout = -OptionsPanel = -OptionsConfirm = -OptionsDisplayBits = -OptionsVfs = -LearnKeys = -SaveSetup = -EditExtensionsFile = -EditFileHighlightFile = -Filter = -ConnectFish = -ConnectFtp = -ConnectSmb = -Undelete = +# OptionsLayout = +# OptionsPanel = +# OptionsConfirm = +# OptionsDisplayBits = +# OptionsVfs = +# LearnKeys = +# SaveSetup = +# EditExtensionsFile = +# EditFileHighlightFile = +# Filter = +# ConnectFish = +# ConnectFtp = +# ConnectSmb = +# Undelete = ExtendedKeyMap = ctrl-x [main:xmap] @@ -81,8 +80,8 @@ Search = ctrl-s; alt-s Mark = insert; ctrl-t MarkUp = shift-up MarkDown = shift-down -MarkLeft = -MarkRight = +# MarkLeft = +# MarkRight = Down = down; ctrl-n Up = up; ctrl-p Left = left @@ -102,8 +101,8 @@ Unselect = alt-minus SelectInvert = alt-asterisk CdChild = ctrl-pgdn CdParent = ctrl-pgup -Panelize = -CdParentSmart = +# CdParentSmart = +# Panelize = History = alt-shift-h HistoryNext = alt-u HistoryPrev = alt-y @@ -114,16 +113,16 @@ PanelOtherSync = alt-i SelectCodepage = alt-e Top = alt-lt; home; a1 Bottom = alt-gt; end; c1 -Sort = -SortPrev = -SortNext = -SortReverse = -SortByName = -SortByExt = -SortBySize = -SortByMTime = -ScrollLeft = -ScrollRight = +# Sort = +# SortPrev = +# SortNext = +# SortReverse = +# SortByName = +# SortByExt = +# SortBySize = +# SortByMTime = +# ScrollLeft = +# ScrollRight = [dialog] Ok = enter @@ -150,24 +149,24 @@ Backspace = backspace Delete = delete DeleteToWordBegin = alt-backspace DeleteToWordEnd = alt-d -Mark = +# Mark = Remove = ctrl-w -Cut = +# Cut = Store = alt-w -Paste = +# Paste = Yank = ctrl-y DeleteToEnd = ctrl-k HistoryPrev = alt-p; ctrl-down HistoryNext = alt-n; ctrl-up History = alt-h Complete = alt-tab -Clear = -MarkLeft = -MarkRight = -MarkToWordBegin = -MarkToWordEnd = -MarkToHome = -MarkToEnd = +# Clear = +# MarkLeft = +# MarkRight = +# MarkToWordBegin = +# MarkToWordEnd = +# MarkToHome = +# MarkToEnd = [listbox] Up = up; ctrl-p @@ -237,7 +236,7 @@ Home = home; ctrl-a End = end; ctrl-e Tab = tab Undo = ctrl-u -Redo = +# Redo = Top = ctrl-home; alt-lt Bottom = ctrl-end; alt-gt ScrollUp = ctrl-up @@ -248,25 +247,25 @@ DeleteToWordBegin = alt-backspace DeleteToWordEnd = alt-d DeleteLine = ctrl-y DeleteToEnd = ctrl-k -DeleteToHome = -ParagraphUp = -ParagraphDown = +# DeleteToHome = +# ParagraphUp = +# ParagraphDown = Save = f2 -EditFile = +# EditFile = SaveAs = f12; ctrl-f2 -Close = +# Close = Mark = f3; ctrl-at Copy = f5 Move = f6 Remove = f8 -MarkLine = -MarkWord = -MarkAll = -Unmark = +# MarkLine = +# MarkWord = +# MarkAll = +# Unmark = Search = f7; ctrl-s SearchContinue = f17 -BlockShiftLeft = -BlockShiftRight = +# BlockShiftLeft = +# BlockShiftRight = MarkPageUp = shift-pgup MarkPageDown = shift-pgdn MarkLeft = shift-left @@ -283,19 +282,19 @@ MarkToPageBegin = ctrl-shift-pgup MarkToPageEnd = ctrl-shift-pgdn MarkScrollUp = ctrl-shift-up MarkScrollDown = ctrl-shift-down -MarkParagraphUp = -MarkParagraphDown = +# MarkParagraphUp = +# MarkParagraphDown = MarkColumnPageUp = alt-pgup MarkColumnPageDown = alt-pgdn MarkColumnLeft = alt-left MarkColumnRight = alt-right MarkColumnUp = alt-up MarkColumnDown = alt-down -MarkColumnScrollUp = -MarkColumnScrollDown = -MarkColumnParagraphUp = -MarkColumnParagraphDown = -BlockSave = +# MarkColumnScrollUp = +# MarkColumnScrollDown = +# MarkColumnParagraphUp = +# MarkColumnParagraphDown = +# BlockSave = MarkColumn = f13 Replace = f4 ReplaceContinue = f14 @@ -304,49 +303,49 @@ InsertFile = f15 Quit = f10; esc InsertOverwrite = insert Help = f1 -Date = +# Date = Refresh = ctrl-l Goto = alt-l Sort = alt-t -Mail = +# Mail = ParagraphFormat = alt-p -MatchBracket = +# MatchBracket = ExternalCommand = alt-u UserMenu = f11 Menu = f9 -Bookmark = -BookmarkFlush = -BookmarkNext = -BookmarkPrev = -History = +# Bookmark = +# BookmarkFlush = +# BookmarkNext = +# BookmarkPrev = +# History = Shell = ctrl-o InsertLiteral = ctrl-q -MacroStartRecord = -MacroStopRecord = +# MacroStartRecord = +# MacroStopRecord = MacroStartStopRecord = ctrl-r -MacroDelete = +# MacroDelete = ShowNumbers = alt-n ShowTabTws = alt-underline SyntaxOnOff = ctrl-s -SyntaxChoose = -ShowMargin = +# SyntaxChoose = +# ShowMargin = Find = alt-enter FilePrev = alt-minus FileNext = alt-plus -RepeatStartStopRecord = +# RepeatStartStopRecord = SelectCodepage = alt-e -Options = -OptionsSaveMode = -SpellCheck = -SpellCheckCurrentWord = -SpellCheckSelectLang = -LearnKeys = -WindowMove = -WindowResize = -WindowFullscreen = -WindowList = -WindowNext = -WindowPrev = +# Options = +# OptionsSaveMode = +# SpellCheck = +# SpellCheckCurrentWord = +# SpellCheckSelectLang = +# LearnKeys = +# WindowMove = +# WindowResize = +# WindowFullscreen = +# WindowList = +# WindowNext = +# WindowPrev = ExtendedKeyMap = ctrl-x [editor:xmap] From 908e7478612a03c6884ecee019c1bab554a3d14c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 28 Jul 2012 14:19:27 +0400 Subject: [PATCH 3/4] Optimization of ini files load. Some ini files (keymaps, skins) are loaded in read-only mode. For those files, we don't need load and keep comments. Signed-off-by: Andrew Borodin --- lib/filehighlight/ini-file-read.c | 4 ++-- lib/mcconfig.h | 6 +++--- lib/mcconfig/common.c | 14 ++++++++++---- lib/serialize.c | 4 +++- lib/skin/ini-file.c | 8 ++++---- lib/vfs/path.c | 8 ++++++-- lib/widget/dialog.c | 4 ++-- lib/widget/history.c | 2 +- src/editor/editcmd.c | 6 +++--- src/filemanager/treestore.c | 2 +- src/keybind-defaults.c | 2 +- src/setup.c | 28 ++++++++++++++-------------- tests/lib/mcconfig/config_string.c | 8 ++++---- tests/lib/serialize.c | 2 +- 14 files changed, 55 insertions(+), 43 deletions(-) diff --git a/lib/filehighlight/ini-file-read.c b/lib/filehighlight/ini-file-read.c index bb7687d99..44faca42f 100644 --- a/lib/filehighlight/ini-file-read.c +++ b/lib/filehighlight/ini-file-read.c @@ -184,9 +184,9 @@ mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename) return FALSE; if (fhl->config != NULL) - return mc_config_read_file (fhl->config, filename, FALSE); + return mc_config_read_file (fhl->config, filename, TRUE, FALSE); - fhl->config = mc_config_init (filename); + fhl->config = mc_config_init (filename, TRUE); return (fhl->config != NULL); } diff --git a/lib/mcconfig.h b/lib/mcconfig.h index 0518ac152..d2e26375b 100644 --- a/lib/mcconfig.h +++ b/lib/mcconfig.h @@ -29,8 +29,8 @@ extern mc_config_t *mc_panels_config; /* mcconfig/common.c: */ -mc_config_t *mc_config_init (const gchar *); -void mc_config_deinit (mc_config_t *); +mc_config_t *mc_config_init (const gchar * ini_path, gboolean read_only); +void mc_config_deinit (mc_config_t * mc_config); gboolean mc_config_del_key (mc_config_t *, const char *, const gchar *); gboolean mc_config_del_group (mc_config_t *, const char *); @@ -38,7 +38,7 @@ gboolean mc_config_del_group (mc_config_t *, const char *); gboolean mc_config_has_param (const mc_config_t *, const char *, const gchar *); gboolean mc_config_has_group (mc_config_t *, const char *); -gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, +gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only, gboolean remove_empty); gboolean mc_config_save_file (mc_config_t * config, GError ** error); diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index 6d188771d..ea708df89 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -102,7 +102,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ mc_config_t * -mc_config_init (const gchar * ini_path) +mc_config_init (const gchar * ini_path, gboolean read_only) { mc_config_t *mc_config; struct stat st; @@ -128,8 +128,13 @@ mc_config_init (const gchar * ini_path) vpath = vfs_path_from_str (ini_path); if (mc_stat (vpath, &st) == 0 && st.st_size != 0) { + GKeyFileFlags flags = G_KEY_FILE_NONE; + + if (!read_only) + flags |= G_KEY_FILE_KEEP_COMMENTS; + /* file exists and not empty */ - g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL); + g_key_file_load_from_file (mc_config->handle, ini_path, flags, NULL); } vfs_path_free (vpath); } @@ -207,7 +212,8 @@ mc_config_del_group (mc_config_t * mc_config, const char *group) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ gboolean -mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean remove_empty) +mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only, + gboolean remove_empty) { mc_config_t *tmp_config; gchar **groups, **curr_grp; @@ -217,7 +223,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r if (mc_config == NULL) return FALSE; - tmp_config = mc_config_init (ini_path); + tmp_config = mc_config_init (ini_path, read_only); if (tmp_config == NULL) return FALSE; diff --git a/lib/serialize.c b/lib/serialize.c index c03dcd199..c47223e12 100644 --- a/lib/serialize.c +++ b/lib/serialize.c @@ -281,7 +281,7 @@ mc_deserialize_config (const char *data, GError ** error) { char *current_group = NULL, *current_param = NULL, *current_value = NULL; size_t current_position = 0; - mc_config_t *ret_data = mc_config_init (NULL); + mc_config_t *ret_data; enum automat_status { WAIT_GROUP, @@ -289,6 +289,8 @@ mc_deserialize_config (const char *data, GError ** error) WAIT_VALUE } current_status = WAIT_GROUP; + ret_data = mc_config_init (NULL, FALSE); + while (data != NULL) { if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL)) diff --git a/lib/skin/ini-file.c b/lib/skin/ini-file.c index 6e241017e..c4b5efa79 100644 --- a/lib/skin/ini-file.c +++ b/lib/skin/ini-file.c @@ -51,7 +51,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL); if (exist_file (file_name)) { - mc_skin->config = mc_config_init (file_name); + mc_skin->config = mc_config_init (file_name, TRUE); g_free (file_name); return (mc_skin->config != NULL); } @@ -63,7 +63,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir if (exist_file (file_name)) { - mc_skin->config = mc_config_init (file_name); + mc_skin->config = mc_config_init (file_name, TRUE); g_free (file_name); return (mc_skin->config != NULL); } @@ -89,7 +89,7 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin) g_free (file_name); if (!g_path_is_absolute (mc_skin->name)) return FALSE; - mc_skin->config = mc_config_init (mc_skin->name); + mc_skin->config = mc_config_init (mc_skin->name, TRUE); return (mc_skin->config != NULL); } g_free (file_name); @@ -127,7 +127,7 @@ mc_skin_ini_file_parse (mc_skin_t * mc_skin) void mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin) { - mc_skin->config = mc_config_init (NULL); + mc_skin->config = mc_config_init (NULL, TRUE); mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin"); diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 26aefd8e0..25696e1ea 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -1053,7 +1053,7 @@ vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element) char * vfs_path_serialize (const vfs_path_t * vpath, GError ** error) { - mc_config_t *cpath = mc_config_init (NULL); + mc_config_t *cpath; ssize_t element_index; char *ret_value; @@ -1063,6 +1063,9 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error) return NULL; } + + cpath = mc_config_init (NULL, FALSE); + for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++) { char *groupname; @@ -1106,10 +1109,11 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error) vfs_path_t * vfs_path_deserialize (const char *data, GError ** error) { - mc_config_t *cpath = mc_deserialize_config (data, error); + mc_config_t *cpath; size_t element_index = 0; vfs_path_t *vpath; + cpath = mc_deserialize_config (data, error); if (cpath == NULL) return NULL; diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 1ccda6907..6d51fef95 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -165,7 +165,7 @@ dlg_read_history (Dlg_head * h) return; profile = mc_config_get_full_path (MC_HISTORY_FILE); - event_data.cfg = mc_config_init (profile); + event_data.cfg = mc_config_init (profile, TRUE); event_data.receiver = NULL; /* create all histories in dialog */ @@ -1335,7 +1335,7 @@ dlg_save_history (Dlg_head * h) { ev_history_load_save_t event_data; - event_data.cfg = mc_config_init (profile); + event_data.cfg = mc_config_init (profile, FALSE); event_data.receiver = NULL; /* get all histories in dialog */ diff --git a/lib/widget/history.c b/lib/widget/history.c index 072ea989b..39b6dac3e 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -151,7 +151,7 @@ history_get (const char *input_name) return NULL; profile = mc_config_get_full_path (MC_HISTORY_FILE); - cfg = mc_config_init (profile); + cfg = mc_config_init (profile, TRUE); hist = history_load (cfg, input_name); diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index d3e53ca37..4ca6cee55 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1416,7 +1416,7 @@ edit_delete_macro (WEdit * edit, int hotkey) } macros_fname = mc_config_get_full_path (MC_MACRO_FILE); - macros_config = mc_config_init (macros_fname); + macros_config = mc_config_init (macros_fname, FALSE); g_free (macros_fname); if (macros_config == NULL) @@ -1835,7 +1835,7 @@ edit_store_macro_cmd (WEdit * edit) edit_delete_macro (edit, hotkey); macros_fname = mc_config_get_full_path (MC_MACRO_FILE); - macros_config = mc_config_init (macros_fname); + macros_config = mc_config_init (macros_fname, FALSE); g_free (macros_fname); if (macros_config == NULL) @@ -1939,7 +1939,7 @@ edit_load_macro_cmd (WEdit * edit) (void) edit; macros_fname = mc_config_get_full_path (MC_MACRO_FILE); - macros_config = mc_config_init (macros_fname); + macros_config = mc_config_init (macros_fname, TRUE); g_free (macros_fname); if (macros_config == NULL) diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 5faf6e199..25bb7ae51 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -565,7 +565,7 @@ process_special_dirs (GList ** special_dirs, char *file) mc_config_t *cfg; gsize buffers_len; - cfg = mc_config_init (file); + cfg = mc_config_init (file, TRUE); if (cfg == NULL) return; diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c index 75ae855cf..6fb79203f 100644 --- a/src/keybind-defaults.c +++ b/src/keybind-defaults.c @@ -578,7 +578,7 @@ create_default_keymap (void) { mc_config_t *keymap; - keymap = mc_config_init (NULL); + keymap = mc_config_init (NULL, TRUE); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap); diff --git a/src/setup.c b/src/setup.c index 062f6c2f8..c0f0c953e 100644 --- a/src/setup.c +++ b/src/setup.c @@ -464,7 +464,7 @@ setup__move_panels_config_into_separate_file (const char *profile) if (!exist_file (profile)) return; - tmp_cfg = mc_config_init (profile); + tmp_cfg = mc_config_init (profile, FALSE); if (!tmp_cfg) return; @@ -485,7 +485,7 @@ setup__move_panels_config_into_separate_file (const char *profile) mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL); mc_config_deinit (tmp_cfg); - tmp_cfg = mc_config_init (profile); + tmp_cfg = mc_config_init (profile, FALSE); if (!tmp_cfg) { g_strfreev (groups); @@ -516,7 +516,7 @@ setup__move_panels_config_into_separate_file (const char *profile) */ static void -load_setup_init_config_from_file (mc_config_t ** config, const char *fname) +load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only) { /* TODO: IMHO, in future, this function shall be placed in mcconfig module. @@ -524,9 +524,9 @@ load_setup_init_config_from_file (mc_config_t ** config, const char *fname) if (exist_file (fname)) { if (*config != NULL) - mc_config_read_file (*config, fname, TRUE); + mc_config_read_file (*config, fname, read_only, TRUE); else - *config = mc_config_init (fname); + *config = mc_config_init (fname, read_only); } } @@ -691,11 +691,11 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) /* 1) /usr/share/mc (mc_global.share_data_dir) */ share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file (&keymap_config, share_keymap); + load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE); /* 2) /etc/mc (mc_global.sysconfig_dir) */ sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); - load_setup_init_config_from_file (&keymap_config, sysconfig_keymap); + load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE); /* then load and merge one of user-defined keymap */ @@ -703,7 +703,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file); if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) { - load_setup_init_config_from_file (&keymap_config, fname); + load_setup_init_config_from_file (&keymap_config, fname, TRUE); goto done; } g_free (fname); @@ -712,7 +712,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP")); if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) { - load_setup_init_config_from_file (&keymap_config, fname); + load_setup_init_config_from_file (&keymap_config, fname, TRUE); goto done; } g_free (fname); @@ -724,14 +724,14 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) g_free (fname2); if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0) { - load_setup_init_config_from_file (&keymap_config, fname); + load_setup_init_config_from_file (&keymap_config, fname, TRUE); goto done; } g_free (fname); /* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */ fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE); - load_setup_init_config_from_file (&keymap_config, fname); + load_setup_init_config_from_file (&keymap_config, fname, TRUE); done: g_free (fname); @@ -890,12 +890,12 @@ load_setup (void) panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE); - mc_main_config = mc_config_init (profile); + mc_main_config = mc_config_init (profile, FALSE); if (!exist_file (panels_profile_name)) setup__move_panels_config_into_separate_file (profile); - mc_panels_config = mc_config_init (panels_profile_name); + mc_panels_config = mc_config_init (panels_profile_name, FALSE); /* Load integer boolean options */ for (i = 0; int_options[i].opt_name != NULL; i++) @@ -1154,7 +1154,7 @@ load_key_defs (void) */ mc_config_t *mc_global_config; - mc_global_config = mc_config_init (global_profile_name); + mc_global_config = mc_config_init (global_profile_name, FALSE); if (mc_global_config != NULL) { load_keys_from_section ("general", mc_global_config); diff --git a/tests/lib/mcconfig/config_string.c b/tests/lib/mcconfig/config_string.c index f243fdadb..500ae8dcc 100644 --- a/tests/lib/mcconfig/config_string.c +++ b/tests/lib/mcconfig/config_string.c @@ -69,7 +69,7 @@ START_TEST (create_ini_file) ini_filename = g_build_filename(WORKDIR, "test-create_ini_file.ini",NULL); unlink(ini_filename); - mc_config = mc_config_init (ini_filename); + mc_config = mc_config_init (ini_filename, FALSE); if (mc_config == NULL) { fail("unable to create mc_congif_t object!"); @@ -91,7 +91,7 @@ START_TEST (create_ini_file) } mc_config_deinit (mc_config); - mc_config = mc_config_init (ini_filename); + mc_config = mc_config_init (ini_filename, FALSE); actual_value = mc_config_get_string(mc_config, "group-not-exists", "param-not_exists", NULL); fail_unless(actual_value == NULL, "return value for nonexistent ini-parameters isn't NULL (default value)!"); @@ -139,7 +139,7 @@ START_TEST (emulate__learn_save) ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL); unlink(ini_filename); - mc_config = mc_config_init (ini_filename); + mc_config = mc_config_init (ini_filename, FALSE); if (mc_config == NULL) { fail("unable to create mc_congif_t object!"); @@ -157,7 +157,7 @@ START_TEST (emulate__learn_save) } mc_config_deinit (mc_config); - mc_config = mc_config_init (ini_filename); + mc_config = mc_config_init (ini_filename, FALSE); actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists"); fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G"); diff --git a/tests/lib/serialize.c b/tests/lib/serialize.c index fa6156cad..5bcf68ce7 100644 --- a/tests/lib/serialize.c +++ b/tests/lib/serialize.c @@ -117,7 +117,7 @@ START_TEST (test_serialize_config) GError *error = NULL; char *actual; - test_data = mc_config_init (NULL); + test_data = mc_config_init (NULL, FALSE); mc_config_set_string_raw (test_data, "group1", "param1", "some value"); mc_config_set_string (test_data, "group1", "param2", "some value "); From 98564b91a1787efa0e25c48d17d9421d90a98350 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 29 Jul 2012 12:29:19 +0400 Subject: [PATCH 4/4] Allow define keymap file without .keymap extension ...in the command line, environment variable and configuration file. Signed-off-by: Andrew Borodin --- src/setup.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/setup.c b/src/setup.c index c0f0c953e..524a4be2f 100644 --- a/src/setup.c +++ b/src/setup.c @@ -382,18 +382,25 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam TODO: IMHO, in future, this function shall be placed in mcconfig module. */ char *lc_basename, *ret; + char *file_name; if (config_file_name == NULL) return NULL; - if (g_path_is_absolute (config_file_name)) - { - ret = g_strdup (config_file_name); - canonicalize_pathname (ret); - return ret; - } + /* check for .keymap suffix */ + if (g_str_has_suffix (config_file_name, ".keymap")) + file_name = g_strdup (config_file_name); + else + file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL); + + canonicalize_pathname (file_name); + + if (g_path_is_absolute (file_name)) + return file_name; + + lc_basename = g_path_get_basename (file_name); + g_free (file_name); - lc_basename = g_path_get_basename (config_file_name); if (lc_basename == NULL) return NULL;