Manual pages: mcmcdiffmceditmcview

root/src/keymap.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. create_default_keymap_section
  2. create_default_keymap
  3. load_keymap_from_section
  4. load_setup_get_full_config_name
  5. load_setup_init_config_from_file
  6. load_setup_get_keymap_profile_config
  7. keymap_load
  8. keymap_free

   1 /*
   2    Default values and initialization of keybinding engine
   3 
   4    Copyright (C) 2009-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Vitja Makarov, 2005
   9    Ilia Maslakov <il.smind@gmail.com>, 2009, 2010
  10    Andrew Borodin <aborodin@vmail.ru>, 2010-2021
  11 
  12    This file is part of the Midnight Commander.
  13 
  14    The Midnight Commander is free software: you can redistribute it
  15    and/or modify it under the terms of the GNU General Public License as
  16    published by the Free Software Foundation, either version 3 of the License,
  17    or (at your option) any later version.
  18 
  19    The Midnight Commander is distributed in the hope that it will be useful,
  20    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22    GNU General Public License for more details.
  23 
  24    You should have received a copy of the GNU General Public License
  25    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  26  */
  27 
  28 #include <config.h>
  29 
  30 #include "lib/global.h"
  31 
  32 #include "lib/fileloc.h"
  33 #include "lib/keybind.h"
  34 #include "lib/mcconfig.h"  // mc_config_t
  35 #include "lib/util.h"
  36 #include "lib/widget.h"  // dialog_map, input_map, listbox_map, menu_map, radio_map
  37 
  38 #include "args.h"  // mc_args__keymap_file
  39 
  40 #include "keymap.h"
  41 
  42 /*** global variables ****************************************************************************/
  43 
  44 GArray *filemanager_keymap = NULL;
  45 GArray *filemanager_x_keymap = NULL;
  46 GArray *panel_keymap = NULL;
  47 GArray *dialog_keymap = NULL;
  48 GArray *menu_keymap = NULL;
  49 GArray *input_keymap = NULL;
  50 GArray *listbox_keymap = NULL;
  51 GArray *radio_keymap = NULL;
  52 GArray *tree_keymap = NULL;
  53 GArray *help_keymap = NULL;
  54 #ifdef ENABLE_EXT2FS_ATTR
  55 GArray *chattr_keymap = NULL;
  56 #endif
  57 #ifdef USE_INTERNAL_EDIT
  58 GArray *editor_keymap = NULL;
  59 GArray *editor_x_keymap = NULL;
  60 #endif
  61 GArray *viewer_keymap = NULL;
  62 GArray *viewer_hex_keymap = NULL;
  63 #ifdef USE_DIFF_VIEW
  64 GArray *diff_keymap = NULL;
  65 #endif
  66 
  67 const global_keymap_t *filemanager_map = NULL;
  68 const global_keymap_t *filemanager_x_map = NULL;
  69 const global_keymap_t *panel_map = NULL;
  70 const global_keymap_t *tree_map = NULL;
  71 const global_keymap_t *help_map = NULL;
  72 #ifdef ENABLE_EXT2FS_ATTR
  73 const global_keymap_t *chattr_map = NULL;
  74 #endif
  75 #ifdef USE_INTERNAL_EDIT
  76 const global_keymap_t *editor_map = NULL;
  77 const global_keymap_t *editor_x_map = NULL;
  78 #endif
  79 const global_keymap_t *viewer_map = NULL;
  80 const global_keymap_t *viewer_hex_map = NULL;
  81 #ifdef USE_DIFF_VIEW
  82 const global_keymap_t *diff_map = NULL;
  83 #endif
  84 
  85 /*** file scope macro definitions ****************************************************************/
  86 
  87 /*** file scope type declarations ****************************************************************/
  88 
  89 /* default keymaps in ini (key=value) format */
  90 typedef struct global_keymap_ini_t
  91 {
  92     const char *key;
  93     const char *value;
  94 } global_keymap_ini_t;
  95 
  96 /*** forward declarations (file scope functions) *************************************************/
  97 
  98 /*** file scope variables ************************************************************************/
  99 
 100 /* midnight */
 101 static const global_keymap_ini_t default_filemanager_keymap[] = {
 102     { "ChangePanel", "tab; ctrl-i" },
 103     { "Help", "f1" },
 104     { "UserMenu", "f2" },
 105     { "View", "f3" },
 106     { "Edit", "f4" },
 107     { "Copy", "f5" },
 108     { "Move", "f6" },
 109     { "MakeDir", "f7" },
 110     { "Delete", "f8" },
 111     { "Menu", "f9" },
 112     { "Quit", "f10" },
 113     { "MenuLastSelected", "f19" },
 114     { "QuitQuiet", "f20" },
 115     { "History", "alt-h" },
 116     { "EditorViewerHistory", "alt-shift-e" },
 117     { "DirSize", "ctrl-space" },
 118     // Copy useful information to the command line
 119     { "PutCurrentPath", "alt-a" },
 120     { "PutOtherPath", "alt-shift-a" },
 121     { "PutCurrentSelected", "alt-enter; ctrl-enter" },
 122     { "PutCurrentFullSelected", "ctrl-shift-enter" },
 123     { "CdQuick", "alt-c" },
 124     // To access the directory hotlist
 125     { "HotList", "ctrl-backslash" },
 126     // Suspend
 127     { "Suspend", "ctrl-z" },
 128     // The filtered view command
 129     { "ViewFiltered", "alt-exclamation" },
 130     // Find file
 131     { "Find", "alt-question" },
 132     // Panel refresh
 133     { "Reread", "ctrl-r" },
 134     // Switch listing between long, user defined and full formats
 135     // Swap panels
 136     { "Swap", "ctrl-u" },
 137     // Resize panels
 138     { "SplitEqual", "alt-equal" },
 139     { "SplitMore", "alt-shift-right" },
 140     { "SplitLess", "alt-shift-left" },
 141     // View output
 142     { "Shell", "ctrl-o" },
 143     { "ShowHidden", "alt-dot" },
 144     { "SplitVertHoriz", "alt-comma" },
 145     { "ExtendedKeyMap", "ctrl-x" },
 146     // Select/unselect group
 147     { "Select", "kpplus" },
 148     { "Unselect", "kpminus" },
 149     { "SelectInvert", "kpasterisk" },
 150     // List of screens
 151     { "ScreenList", "alt-prime" },
 152     {
 153         NULL,
 154         NULL,
 155     },
 156 };
 157 
 158 static const global_keymap_ini_t default_filemanager_x_keymap[] = {
 159     { "CompareDirs", "d" },
 160 #ifdef USE_DIFF_VIEW
 161     { "CompareFiles", "ctrl-d" },
 162 #endif
 163 #ifdef ENABLE_VFS
 164     { "VfsList", "a" },
 165 #endif
 166     { "PutCurrentPath", "p" },
 167     { "PutOtherPath", "ctrl-p" },
 168     { "PutCurrentTagged", "t" },
 169     { "PutOtherTagged", "ctrl-t" },
 170     { "ChangeMode", "c" },
 171     { "ChangeOwn", "o" },
 172 #ifdef ENABLE_EXT2FS_ATTR
 173     { "ChangeAttributes", "e" },
 174 #endif
 175     { "PutCurrentLink", "r" },
 176     { "PutOtherLink", "ctrl-r" },
 177     { "Link", "l" },
 178     { "LinkSymbolic", "s" },
 179     { "LinkSymbolicRelative", "v" },
 180     { "LinkSymbolicEdit", "ctrl-s" },
 181     { "PanelInfo", "i" },
 182     { "PanelQuickView", "q" },
 183     { "HotListAdd", "h" },
 184 #ifdef ENABLE_BACKGROUND
 185     { "Jobs", "j" },
 186 #endif
 187     { "ExternalPanelize", "!" },
 188     {
 189         NULL,
 190         NULL,
 191     },
 192 };
 193 
 194 /* panel */
 195 static const global_keymap_ini_t default_panel_keymap[] = {
 196     { "CycleListingFormat", "alt-t" },
 197     { "PanelOtherCd", "alt-o" },
 198     { "PanelOtherCdLink", "alt-l" },
 199     { "CopySingle", "f15" },
 200     { "DeleteSingle", "f18" },
 201     { "Enter", "enter" },
 202     { "EditNew", "f14" },
 203     { "MoveSingle", "f16" },
 204     { "SelectInvert", "alt-asterisk" },
 205     { "Select", "alt-plus" },
 206     { "Unselect", "alt-minus" },
 207     { "ViewRaw", "f13" },
 208     { "CdChild", "ctrl-pgdn" },
 209     { "CdParent", "ctrl-pgup" },
 210     { "History", "alt-shift-h" },
 211     { "HistoryNext", "alt-u" },
 212     { "HistoryPrev", "alt-y" },
 213     { "BottomOnScreen", "alt-j" },
 214     { "MiddleOnScreen", "alt-r" },
 215     { "TopOnScreen", "alt-g" },
 216     { "Mark", "insert; ctrl-t" },
 217     { "MarkDown", "shift-down" },
 218     { "MarkUp", "shift-up" },
 219     { "Up", "up; ctrl-p" },
 220     { "Down", "down; ctrl-n" },
 221     { "Left", "left" },
 222     { "Right", "right" },
 223     { "Top", "alt-lt; home; a1" },
 224     { "Bottom", "alt-gt; end; c1" },
 225     { "PageDown", "pgdn; ctrl-v" },
 226     { "PageUp", "pgup; alt-v" },
 227     { "SelectCodepage", "alt-e" },
 228     { "Search", "ctrl-s; alt-s" },
 229     { "PanelOtherSync", "alt-i" },
 230     {
 231         NULL,
 232         NULL,
 233     },
 234 };
 235 
 236 /* dialog */
 237 static const global_keymap_ini_t default_dialog_keymap[] = {
 238     { "Ok", "enter" },
 239     { "Cancel", "f10; esc; ctrl-g" },
 240     { "Up", "up; left" },
 241     { "Down", "down; right" },
 242 #if 0
 243     {"Left", "up; left"},
 244     {"Right", "down; right"},
 245 #endif
 246     { "Help", "f1" },
 247     { "Suspend", "ctrl-z" },
 248     { "Refresh", "ctrl-l" },
 249     { "ScreenList", "alt-prime" },
 250     { "ScreenNext", "alt-rbrace" },
 251     { "ScreenPrev", "alt-lbrace" },
 252     {
 253         NULL,
 254         NULL,
 255     },
 256 };
 257 
 258 /* menubar */
 259 static const global_keymap_ini_t default_menu_keymap[] = {
 260     { "Help", "f1" },
 261     { "Left", "left; ctrl-b" },
 262     { "Right", "right; ctrl-f" },
 263     { "Up", "up; ctrl-p" },
 264     { "Down", "down; ctrl-n" },
 265     { "Home", "home; alt-lt; ctrl-a" },
 266     { "End", "end; alt-gt; ctrl-e" },
 267     { "Enter", "enter" },
 268     { "Quit", "f10; ctrl-g; esc" },
 269     {
 270         NULL,
 271         NULL,
 272     },
 273 };
 274 
 275 /* input line */
 276 static const global_keymap_ini_t default_input_keymap[] = {
 277     // Motion
 278     { "Home", "ctrl-a; alt-lt; home; a1" },
 279     { "End", "ctrl-e; alt-gt; end; c1" },
 280     { "Left", "left; alt-left; ctrl-b" },
 281     { "Right", "right; alt-right; ctrl-f" },
 282     { "WordLeft", "ctrl-left; alt-b" },
 283     { "WordRight", "ctrl-right; alt-f" },
 284     // Mark
 285     { "MarkLeft", "shift-left" },
 286     { "MarkRight", "shift-right" },
 287     { "MarkToWordBegin", "ctrl-shift-left" },
 288     { "MarkToWordEnd", "ctrl-shift-right" },
 289     { "MarkToHome", "shift-home" },
 290     { "MarkToEnd", "shift-end" },
 291     // Editing
 292     { "Backspace", "backspace; ctrl-h" },
 293     { "Delete", "delete; ctrl-d" },
 294     { "DeleteToWordEnd", "alt-d" },
 295     { "DeleteToWordBegin", "alt-backspace" },
 296     // Region manipulation
 297     { "Remove", "ctrl-w" },
 298     { "Store", "alt-w" },
 299     { "Yank", "ctrl-y" },
 300     { "DeleteToEnd", "ctrl-k" },
 301     // History
 302     { "History", "alt-h" },
 303     { "HistoryPrev", "alt-p; ctrl-down" },
 304     { "HistoryNext", "alt-n; ctrl-up" },
 305     // Completion
 306     { "Complete", "alt-tab" },
 307     {
 308         NULL,
 309         NULL,
 310     },
 311 };
 312 
 313 /* listbox */
 314 static const global_keymap_ini_t default_listbox_keymap[] = {
 315     { "Up", "up; ctrl-p" },
 316     { "Down", "down; ctrl-n" },
 317     { "Top", "home; alt-lt; a1" },
 318     { "Bottom", "end; alt-gt; c1" },
 319     { "PageUp", "pgup; alt-v" },
 320     { "PageDown", "pgdn; ctrl-v" },
 321     { "Delete", "delete; d" },
 322     { "Clear", "shift-delete; shift-d" },
 323     { "View", "f3" },
 324     { "Edit", "f4" },
 325     { "Enter", "enter" },
 326     {
 327         NULL,
 328         NULL,
 329     },
 330 };
 331 
 332 /* radio */
 333 static const global_keymap_ini_t default_radio_keymap[] = {
 334     { "Up", "up; ctrl-p" },
 335     { "Down", "down; ctrl-n" },
 336     { "Top", "home; alt-lt; a1" },
 337     { "Bottom", "end; alt-gt; c1" },
 338     { "Select", "space" },
 339     {
 340         NULL,
 341         NULL,
 342     },
 343 };
 344 
 345 /* tree */
 346 static const global_keymap_ini_t default_tree_keymap[] = {
 347     { "Help", "f1" },
 348     { "Rescan", "f2; ctrl-r" },
 349     { "Forget", "f3" },
 350     { "ToggleNavigation", "f4" },
 351     { "Copy", "f5" },
 352     { "Move", "f6" },
 353 #if 0
 354     {"MakeDir", "f7"},
 355 #endif
 356     { "Delete", "f8; delete" },
 357     { "Up", "up; ctrl-p" },
 358     { "Down", "down; ctrl-n" },
 359     { "Left", "left" },
 360     { "Right", "right" },
 361     { "Top", "home; alt-lt; a1" },
 362     { "Bottom", "end; alt-gt; c1" },
 363     { "PageUp", "pgup; alt-v" },
 364     { "PageDown", "pgdn; ctrl-v" },
 365     { "Enter", "enter" },
 366     { "Search", "ctrl-s; alt-s" },
 367     {
 368         NULL,
 369         NULL,
 370     },
 371 };
 372 
 373 /* help */
 374 static const global_keymap_ini_t default_help_keymap[] = {
 375     { "Help", "f1" },
 376     { "Index", "f2; c" },
 377     { "Back", "f3; left; l" },
 378     { "Quit", "f10; esc" },
 379     { "Up", "up; ctrl-p" },
 380     { "Down", "down; ctrl-n" },
 381     { "PageDown", "f; space; pgdn; ctrl-v" },
 382     { "PageUp", "b; pgup; alt-v; backspace" },
 383     { "HalfPageDown", "d" },
 384     { "HalfPageUp", "u" },
 385     { "Top", "home; ctrl-home; ctrl-pgup; a1; alt-lt; g" },
 386     { "Bottom", "end; ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g" },
 387     { "Enter", "right; enter" },
 388     { "LinkNext", "tab" },
 389     { "LinkPrev", "alt-tab" },
 390     { "NodeNext", "n" },
 391     { "NodePrev", "p" },
 392     {
 393         NULL,
 394         NULL,
 395     },
 396 };
 397 
 398 #ifdef ENABLE_EXT2FS_ATTR
 399 /* chattr dialog */
 400 static const global_keymap_ini_t default_chattr_keymap[] = {
 401     { "Up", "up; left; ctrl-p" },
 402     { "Down", "down; right; ctrl-n" },
 403     { "Top", "home; alt-lt; a1" },
 404     { "Bottom", "end; alt-gt; c1" },
 405     { "PageUp", "pgup; alt-v" },
 406     { "PageDown", "pgdn; ctrl-v" },
 407     { "Mark", "t; shift-t" },
 408     { "MarkAndDown", "insert" },
 409     {
 410         NULL,
 411         NULL,
 412     },
 413 };
 414 #endif
 415 
 416 #ifdef USE_INTERNAL_EDIT
 417 static const global_keymap_ini_t default_editor_keymap[] = {
 418     { "Enter", "enter" },
 419     { "Return", "shift-enter; ctrl-enter; ctrl-shift-enter" },  // useful for pasting multiline text
 420     { "Tab", "tab; shift-tab; ctrl-tab; ctrl-shift-tab" },      // ditto
 421     { "BackSpace", "backspace; ctrl-h" },
 422     { "Delete", "delete; ctrl-d" },
 423     { "Left", "left" },
 424     { "Right", "right" },
 425     { "Up", "up" },
 426     { "Down", "down" },
 427     { "Home", "home" },
 428     { "End", "end" },
 429     { "PageUp", "pgup" },
 430     { "PageDown", "pgdn" },
 431     { "WordLeft", "ctrl-left; ctrl-z" },
 432     { "WordRight", "ctrl-right; ctrl-x" },
 433     { "InsertOverwrite", "insert" },
 434     { "Help", "f1" },
 435     { "Save", "f2" },
 436     { "Mark", "f3" },
 437     { "Replace", "f4" },
 438     { "Copy", "f5" },
 439     { "Move", "f6" },
 440     { "Search", "f7" },
 441     { "Remove", "f8; ctrl-delete" },
 442     { "Menu", "f9" },
 443     { "Quit", "f10; esc" },
 444     { "UserMenu", "f11" },
 445     { "SaveAs", "f12; ctrl-f2" },
 446     { "MarkColumn", "f13" },
 447     { "ReplaceContinue", "f14; ctrl-f4" },
 448     { "InsertFile", "f15" },
 449     { "SearchContinue", "f17; ctrl-f7" },
 450     { "EditNew", "ctrl-n" },
 451     { "DeleteToWordBegin", "alt-backspace" },
 452     { "DeleteToWordEnd", "alt-d" },
 453     { "DeleteLine", "ctrl-y" },
 454     { "DeleteToEnd", "ctrl-k" },
 455     { "Undo", "ctrl-u; ctrl-backspace" },
 456     { "Redo", "alt-r" },
 457     { "SelectCodepage", "alt-e" },
 458     { "Goto", "alt-l; alt-shift-l" },
 459     { "Refresh", "ctrl-l" },
 460     { "Shell", "ctrl-o" },
 461     { "Top", "ctrl-home; ctrl-pgup; alt-lt" },
 462     { "Bottom", "ctrl-end; ctrl-pgdn; alt-gt" },
 463     { "TopOnScreen", "ctrl-pgup" },
 464     { "BottomOnScreen", "ctrl-pgdn" },
 465     { "ScrollUp", "ctrl-up" },
 466     { "ScrollDown", "ctrl-down" },
 467     { "Store", "ctrl-insert" },
 468     { "Paste", "shift-insert" },
 469     { "Cut", "shift-delete" },
 470     { "BlockSave", "ctrl-f" },
 471     { "MarkLeft", "shift-left" },
 472     { "MarkRight", "shift-right" },
 473     { "MarkUp", "shift-up" },
 474     { "MarkDown", "shift-down" },
 475     { "MarkPageUp", "shift-pgup" },
 476     { "MarkPageDown", "shift-pgdn" },
 477     { "MarkToWordBegin", "ctrl-shift-left" },
 478     { "MarkToWordEnd", "ctrl-shift-right" },
 479     { "MarkToHome", "shift-home" },
 480     { "MarkToEnd", "shift-end" },
 481     { "MarkToFileBegin", "ctrl-shift-home" },
 482     { "MarkToFileEnd", "ctrl-shift-end" },
 483     { "MarkToPageBegin", "ctrl-shift-pgup" },
 484     { "MarkToPageEnd", "ctrl-shift-pgdn" },
 485     { "MarkScrollUp", "ctrl-shift-up" },
 486     { "MarkScrollDown", "ctrl-shift-down" },
 487     { "MarkColumnLeft", "alt-left" },
 488     { "MarkColumnRight", "alt-right" },
 489     { "MarkColumnUp", "alt-up" },
 490     { "MarkColumnDown", "alt-down" },
 491     { "MarkColumnPageUp", "alt-pgup" },
 492     { "MarkColumnPageDown", "alt-pgdn" },
 493     { "InsertLiteral", "ctrl-q" },
 494     { "Complete", "alt-tab" },
 495     { "MatchBracket", "alt-b" },
 496     { "ParagraphFormat", "alt-p" },
 497     { "Bookmark", "alt-k" },
 498     { "BookmarkFlush", "alt-o" },
 499     { "BookmarkNext", "alt-j" },
 500     { "BookmarkPrev", "alt-i" },
 501     { "MacroStartStopRecord", "ctrl-r" },
 502     { "MacroExecute", "ctrl-a" },
 503     { "ShowNumbers", "alt-n" },
 504     { "ShowTabTws", "alt-underline" },
 505     { "SyntaxOnOff", "ctrl-s" },
 506     { "Find", "alt-enter" },
 507     { "FilePrev", "alt-minus" },
 508     { "FileNext", "alt-plus" },
 509     { "Sort", "alt-t" },
 510     { "Mail", "alt-m" },
 511     { "ExternalCommand", "alt-u" },
 512 #ifdef HAVE_ASPELL
 513     { "SpellCheckCurrentWord", "ctrl-p" },
 514 #endif
 515     { "ExtendedKeyMap", "ctrl-x" },
 516     {
 517         NULL,
 518         NULL,
 519     },
 520 };
 521 
 522 /* emacs keyboard layout emulation */
 523 static const global_keymap_ini_t default_editor_x_keymap[] = {
 524     { NULL, NULL },
 525 };
 526 #endif
 527 
 528 /* viewer */
 529 static const global_keymap_ini_t default_viewer_keymap[] = {
 530     { "Help", "f1" },
 531     { "WrapMode", "f2" },
 532     { "Quit", "f3; f10; q; esc" },
 533     { "HexMode", "f4" },
 534     { "Goto", "f5" },
 535     { "Search", "f7" },
 536     { "SearchContinue", "f17; n" },
 537     { "MagicMode", "f8" },
 538     { "NroffMode", "f9" },
 539     { "Home", "ctrl-a" },
 540     { "End", "ctrl-e" },
 541     { "Left", "h; left" },
 542     { "Right", "l; right" },
 543     { "LeftQuick", "ctrl-left" },
 544     { "RightQuick", "ctrl-right" },
 545     { "Up", "k; y; insert; up; ctrl-p" },
 546     { "Down", "j; e; delete; down; enter; ctrl-n" },
 547     { "PageDown", "f; space; pgdn; ctrl-v" },
 548     { "PageUp", "b; pgup; alt-v; backspace" },
 549     { "HalfPageDown", "d" },
 550     { "HalfPageUp", "u" },
 551     { "Top", "home; ctrl-home; ctrl-pgup; a1; alt-lt; g" },
 552     { "Bottom", "end; ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g" },
 553     { "BookmarkGoto", "m" },
 554     { "Bookmark", "r" },
 555     { "FileNext", "ctrl-f" },
 556     { "FilePrev", "ctrl-b" },
 557     { "SelectCodepage", "alt-e" },
 558     { "Shell", "ctrl-o" },
 559     { "Ruler", "alt-r" },
 560     { "SearchForward", "slash" },
 561     { "SearchBackward", "question" },
 562     { "SearchForwardContinue", "ctrl-s" },
 563     { "SearchBackwardContinue", "ctrl-r" },
 564     { "SearchOppositeContinue", "shift-n" },
 565     { "History", "alt-shift-e" },
 566     {
 567         NULL,
 568         NULL,
 569     },
 570 };
 571 
 572 /* hex viewer */
 573 static const global_keymap_ini_t default_viewer_hex_keymap[] = {
 574     { "Help", "f1" },
 575     { "HexEditMode", "f2" },
 576     { "Quit", "f3; f10; q; esc" },
 577     { "HexMode", "f4" },
 578     { "Goto", "f5" },
 579     { "Save", "f6" },
 580     { "Search", "f7" },
 581     { "SearchContinue", "f17; n" },
 582     { "MagicMode", "f8" },
 583     { "NroffMode", "f9" },
 584     { "ToggleNavigation", "tab" },
 585     { "Home", "ctrl-a; home" },
 586     { "End", "ctrl-e; end" },
 587     { "Left", "b; left" },
 588     { "Right", "f; right" },
 589     { "Up", "k; y; up" },
 590     { "Down", "j; delete; down" },
 591     { "PageDown", "pgdn; ctrl-v" },
 592     { "PageUp", "pgup; alt-v" },
 593     { "Top", "ctrl-home; ctrl-pgup; a1; alt-lt; g" },
 594     { "Bottom", "ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g" },
 595     { "SelectCodepage", "alt-e" },
 596     { "Shell", "ctrl-o" },
 597     { "SearchForward", "slash" },
 598     { "SearchBackward", "question" },
 599     { "SearchForwardContinue", "ctrl-s" },
 600     { "SearchBackwardContinue", "ctrl-r" },
 601     { "SearchOppositeContinue", "shift-n" },
 602     { "History", "alt-shift-e" },
 603     {
 604         NULL,
 605         NULL,
 606     },
 607 };
 608 
 609 #ifdef USE_DIFF_VIEW
 610 /* diff viewer */
 611 static const global_keymap_ini_t default_diff_keymap[] = {
 612     { "ShowSymbols", "alt-s; s" },
 613     { "ShowNumbers", "alt-n; l" },
 614     { "SplitFull", "f" },
 615     { "SplitEqual", "equal" },
 616     { "SplitMore", "gt" },
 617     { "SplitLess", "lt" },
 618     { "Tab2", "2" },
 619     { "Tab3", "3" },
 620     { "Tab4", "4" },
 621     { "Tab8", "8" },
 622     { "Swap", "ctrl-u" },
 623     { "Redo", "ctrl-r" },
 624     { "HunkNext", "n; enter; space" },
 625     { "HunkPrev", "p; backspace" },
 626     { "Goto", "g; shift-g" },
 627     { "Save", "f2" },
 628     { "Edit", "f4" },
 629     { "EditOther", "f14" },
 630     { "Merge", "f5" },
 631     { "MergeOther", "f15" },
 632     { "Search", "f7" },
 633     { "SearchContinue", "f17" },
 634     { "Options", "f9" },
 635     { "Top", "ctrl-home" },
 636     { "Bottom", "ctrl-end" },
 637     { "Down", "down" },
 638     { "Up", "up" },
 639     { "LeftQuick", "ctrl-left" },
 640     { "RightQuick", "ctrl-right" },
 641     { "Left", "left" },
 642     { "Right", "right" },
 643     { "PageDown", "pgdn" },
 644     { "PageUp", "pgup" },
 645     { "Home", "home" },
 646     { "End", "end" },
 647     { "Help", "f1" },
 648     { "Quit", "f10; q; shift-q; esc" },
 649     { "SelectCodepage", "alt-e" },
 650     { "Shell", "ctrl-o" },
 651     {
 652         NULL,
 653         NULL,
 654     },
 655 };
 656 #endif
 657 
 658 /* --------------------------------------------------------------------------------------------- */
 659 /*** file scope functions ************************************************************************/
 660 /* --------------------------------------------------------------------------------------------- */
 661 
 662 static void
 663 create_default_keymap_section (mc_config_t *keymap, const char *section,
     /* [previous][next][first][last][top][bottom][index][help]  */
 664                                const global_keymap_ini_t *k)
 665 {
 666     size_t i;
 667 
 668     for (i = 0; k[i].key != NULL; i++)
 669         mc_config_set_string_raw (keymap, section, k[i].key, k[i].value);
 670 }
 671 
 672 /* --------------------------------------------------------------------------------------------- */
 673 
 674 static mc_config_t *
 675 create_default_keymap (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 676 {
 677     mc_config_t *keymap;
 678 
 679     keymap = mc_config_init (NULL, TRUE);
 680 
 681     create_default_keymap_section (keymap, KEYMAP_SECTION_FILEMANAGER, default_filemanager_keymap);
 682     create_default_keymap_section (keymap, KEYMAP_SECTION_FILEMANAGER_EXT,
 683                                    default_filemanager_x_keymap);
 684     create_default_keymap_section (keymap, KEYMAP_SECTION_PANEL, default_panel_keymap);
 685     create_default_keymap_section (keymap, KEYMAP_SECTION_DIALOG, default_dialog_keymap);
 686     create_default_keymap_section (keymap, KEYMAP_SECTION_MENU, default_menu_keymap);
 687     create_default_keymap_section (keymap, KEYMAP_SECTION_INPUT, default_input_keymap);
 688     create_default_keymap_section (keymap, KEYMAP_SECTION_LISTBOX, default_listbox_keymap);
 689     create_default_keymap_section (keymap, KEYMAP_SECTION_RADIO, default_radio_keymap);
 690     create_default_keymap_section (keymap, KEYMAP_SECTION_TREE, default_tree_keymap);
 691     create_default_keymap_section (keymap, KEYMAP_SECTION_HELP, default_help_keymap);
 692 #ifdef ENABLE_EXT2FS_ATTR
 693     create_default_keymap_section (keymap, KEYMAP_SECTION_HELP, default_chattr_keymap);
 694 #endif
 695 #ifdef USE_INTERNAL_EDIT
 696     create_default_keymap_section (keymap, KEYMAP_SECTION_EDITOR, default_editor_keymap);
 697     create_default_keymap_section (keymap, KEYMAP_SECTION_EDITOR_EXT, default_editor_x_keymap);
 698 #endif
 699     create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER, default_viewer_keymap);
 700     create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER_HEX, default_viewer_hex_keymap);
 701 #ifdef USE_DIFF_VIEW
 702     create_default_keymap_section (keymap, KEYMAP_SECTION_DIFFVIEWER, default_diff_keymap);
 703 #endif
 704 
 705     return keymap;
 706 }
 707 
 708 /* --------------------------------------------------------------------------------------------- */
 709 
 710 static void
 711 load_keymap_from_section (const char *section_name, GArray *keymap, mc_config_t *cfg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 712 {
 713     gchar **profile_keys, **keys;
 714 
 715     if (section_name == NULL)
 716         return;
 717 
 718     keys = mc_config_get_keys (cfg, section_name, NULL);
 719 
 720     for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
 721     {
 722         gchar **values;
 723 
 724         values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
 725         if (values != NULL)
 726         {
 727             long action;
 728 
 729             action = keybind_lookup_action (*profile_keys);
 730             if (action > 0)
 731             {
 732                 gchar **curr_values;
 733 
 734                 for (curr_values = values; *curr_values != NULL; curr_values++)
 735                     keybind_cmd_bind (keymap, *curr_values, action);
 736             }
 737 
 738             g_strfreev (values);
 739         }
 740     }
 741 
 742     g_strfreev (keys);
 743 }
 744 
 745 /* --------------------------------------------------------------------------------------------- */
 746 /**
 747  * Get name of config file.
 748  *
 749  * @param subdir If not NULL, config is also searched in specified subdir.
 750  * @param config_file_name If relative, file if searched in standard paths.
 751  *
 752  * @return newly allocated string with config name or NULL if file is not found.
 753  */
 754 
 755 static char *
 756 load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
     /* [previous][next][first][last][top][bottom][index][help]  */
 757 {
 758     /*
 759        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 760      */
 761     char *lc_basename, *ret;
 762     char *file_name;
 763 
 764     if (config_file_name == NULL)
 765         return NULL;
 766 
 767     // check for .keymap suffix
 768     if (g_str_has_suffix (config_file_name, ".keymap"))
 769         file_name = g_strdup (config_file_name);
 770     else
 771         file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);
 772 
 773     canonicalize_pathname (file_name);
 774 
 775     if (g_path_is_absolute (file_name))
 776         return file_name;
 777 
 778     lc_basename = g_path_get_basename (file_name);
 779     g_free (file_name);
 780 
 781     if (lc_basename == NULL)
 782         return NULL;
 783 
 784     if (subdir != NULL)
 785         ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, (char *) NULL);
 786     else
 787         ret = g_build_filename (mc_config_get_path (), lc_basename, (char *) NULL);
 788 
 789     if (exist_file (ret))
 790     {
 791         g_free (lc_basename);
 792         canonicalize_pathname (ret);
 793         return ret;
 794     }
 795     g_free (ret);
 796 
 797     if (subdir != NULL)
 798         ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, (char *) NULL);
 799     else
 800         ret = g_build_filename (mc_global.share_data_dir, lc_basename, (char *) NULL);
 801 
 802     g_free (lc_basename);
 803 
 804     if (exist_file (ret))
 805     {
 806         canonicalize_pathname (ret);
 807         return ret;
 808     }
 809 
 810     g_free (ret);
 811     return NULL;
 812 }
 813 
 814 /* --------------------------------------------------------------------------------------------- */
 815 /**
 816   Create new mc_config object from specified ini-file or
 817   append data to existing mc_config object from ini-file
 818 */
 819 
 820 static void
 821 load_setup_init_config_from_file (mc_config_t **config, const char *fname, gboolean read_only)
     /* [previous][next][first][last][top][bottom][index][help]  */
 822 {
 823     /*
 824        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 825      */
 826     if (exist_file (fname))
 827     {
 828         if (*config != NULL)
 829             mc_config_read_file (*config, fname, read_only, TRUE);
 830         else
 831             *config = mc_config_init (fname, read_only);
 832     }
 833 }
 834 
 835 /* --------------------------------------------------------------------------------------------- */
 836 
 837 static mc_config_t *
 838 load_setup_get_keymap_profile_config (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
 839 {
 840     /*
 841        TODO: IMHO, in future, this function shall be placed in mcconfig module.
 842      */
 843     mc_config_t *keymap_config;
 844     char *share_keymap, *sysconfig_keymap;
 845     char *fname, *fname2;
 846 
 847     // 0) Create default keymap
 848     keymap_config = create_default_keymap ();
 849     if (!load_from_file)
 850         return keymap_config;
 851 
 852     // load and merge global keymaps
 853 
 854     // 1) /usr/share/mc (mc_global.share_data_dir)
 855     share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 856     load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
 857 
 858     // 2) /etc/mc (mc_global.sysconfig_dir)
 859     sysconfig_keymap =
 860         g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, (char *) NULL);
 861     load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
 862 
 863     // then load and merge one of user-defined keymap
 864 
 865     // 3) --keymap=<keymap>
 866     fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
 867     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 868     {
 869         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 870         goto done;
 871     }
 872     g_free (fname);
 873 
 874     // 4) getenv("MC_KEYMAP")
 875     fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
 876     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 877     {
 878         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 879         goto done;
 880     }
 881 
 882     MC_PTR_FREE (fname);
 883 
 884     // 5) main config; [Midnight Commander] -> keymap
 885     fname2 = mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "keymap", NULL);
 886     if (fname2 != NULL && *fname2 != '\0')
 887         fname = load_setup_get_full_config_name (NULL, fname2);
 888     g_free (fname2);
 889     if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
 890     {
 891         load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 892         goto done;
 893     }
 894     g_free (fname);
 895 
 896     // 6) ${XDG_CONFIG_HOME}/mc/mc.keymap
 897     fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
 898     load_setup_init_config_from_file (&keymap_config, fname, TRUE);
 899 
 900 done:
 901     g_free (fname);
 902     g_free (sysconfig_keymap);
 903     g_free (share_keymap);
 904 
 905     return keymap_config;
 906 }
 907 
 908 /* --------------------------------------------------------------------------------------------- */
 909 /*** public functions ****************************************************************************/
 910 /* --------------------------------------------------------------------------------------------- */
 911 
 912 void
 913 keymap_load (gboolean load_from_file)
     /* [previous][next][first][last][top][bottom][index][help]  */
 914 {
 915     /*
 916      * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
 917      * definitions override global settings.
 918      */
 919     mc_config_t *mc_global_keymap;
 920 
 921     mc_global_keymap = load_setup_get_keymap_profile_config (load_from_file);
 922 
 923     if (mc_global_keymap != NULL)
 924     {
 925 #define LOAD_KEYMAP(s, km)                                                                         \
 926     km##_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));                             \
 927     load_keymap_from_section (KEYMAP_SECTION_##s, km##_keymap, mc_global_keymap)
 928 
 929         LOAD_KEYMAP (FILEMANAGER, filemanager);
 930         LOAD_KEYMAP (FILEMANAGER_EXT, filemanager_x);
 931         LOAD_KEYMAP (PANEL, panel);
 932         LOAD_KEYMAP (DIALOG, dialog);
 933         LOAD_KEYMAP (MENU, menu);
 934         LOAD_KEYMAP (INPUT, input);
 935         LOAD_KEYMAP (LISTBOX, listbox);
 936         LOAD_KEYMAP (RADIO, radio);
 937         LOAD_KEYMAP (TREE, tree);
 938         LOAD_KEYMAP (HELP, help);
 939 #ifdef ENABLE_EXT2FS_ATTR
 940         LOAD_KEYMAP (CHATTR, chattr);
 941 #endif
 942 #ifdef USE_INTERNAL_EDIT
 943         LOAD_KEYMAP (EDITOR, editor);
 944         LOAD_KEYMAP (EDITOR_EXT, editor_x);
 945 #endif
 946         LOAD_KEYMAP (VIEWER, viewer);
 947         LOAD_KEYMAP (VIEWER_HEX, viewer_hex);
 948 #ifdef USE_DIFF_VIEW
 949         LOAD_KEYMAP (DIFFVIEWER, diff);
 950 #endif
 951 
 952 #undef LOAD_KEYMAP
 953         mc_config_deinit (mc_global_keymap);
 954     }
 955 
 956 #define SET_MAP(m) m##_map = (global_keymap_t *) m##_keymap->data
 957 
 958     SET_MAP (filemanager);
 959     SET_MAP (filemanager_x);
 960     SET_MAP (panel);
 961     SET_MAP (dialog);
 962     SET_MAP (menu);
 963     SET_MAP (input);
 964     SET_MAP (listbox);
 965     SET_MAP (radio);
 966     SET_MAP (tree);
 967     SET_MAP (help);
 968 #ifdef ENABLE_EXT2FS_ATTR
 969     SET_MAP (chattr);
 970 #endif
 971 #ifdef USE_INTERNAL_EDIT
 972     SET_MAP (editor);
 973     SET_MAP (editor_x);
 974 #endif
 975     SET_MAP (viewer);
 976     SET_MAP (viewer_hex);
 977 #ifdef USE_DIFF_VIEW
 978     SET_MAP (diff);
 979 #endif
 980 
 981 #undef SET_MAP
 982 }
 983 
 984 /* --------------------------------------------------------------------------------------------- */
 985 
 986 void
 987 keymap_free (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 988 {
 989 #define FREE_KEYMAP(km)                                                                            \
 990     if (km##_keymap != NULL)                                                                       \
 991     g_array_free (km##_keymap, TRUE)
 992 
 993     FREE_KEYMAP (filemanager);
 994     FREE_KEYMAP (filemanager_x);
 995     FREE_KEYMAP (panel);
 996     FREE_KEYMAP (dialog);
 997     FREE_KEYMAP (menu);
 998     FREE_KEYMAP (input);
 999     FREE_KEYMAP (listbox);
1000     FREE_KEYMAP (radio);
1001     FREE_KEYMAP (tree);
1002     FREE_KEYMAP (help);
1003 #ifdef ENABLE_EXT2FS_ATTR
1004     FREE_KEYMAP (chattr);
1005 #endif
1006 #ifdef USE_INTERNAL_EDIT
1007     FREE_KEYMAP (editor);
1008     FREE_KEYMAP (editor_x);
1009 #endif
1010     FREE_KEYMAP (viewer);
1011     FREE_KEYMAP (viewer_hex);
1012 #ifdef USE_DIFF_VIEW
1013     FREE_KEYMAP (diff);
1014 #endif
1015 
1016 #undef FREE_KEYMAP
1017 }
1018 
1019 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */