Moved src/util.[ch] into lib, also moved unixcompat.h and utilunix.c.
[midnight-commander.git] / src / keybind.c
blob8859e5f5e2466eb2da8353b4ac770d0f978442ab
1 /*
2 Copyright (C) 2009 The Free Software Foundation, Inc.
4 Written by: 2005 Vitja Makarov
5 2009 Ilia Maslakov
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be
15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 MA 02110-1301, USA.
25 #include <config.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
37 #include "lib/global.h"
39 #include "cmddef.h" /* CK_ cmd name const */
40 #include "lib/tty/win.h"
41 #include "lib/tty/key.h" /* KEY_M_ */
42 #include "lib/tty/tty.h" /* keys */
43 #include "wtools.h"
44 #include "strutil.h"
46 #include "keybind.h"
48 static name_keymap_t command_names[] = {
49 #ifdef USE_INTERNAL_EDIT
50 { "EditNoCommand", CK_Ignore_Key },
51 { "EditIgnoreKey", CK_Ignore_Key },
52 { "EditBackSpace", CK_BackSpace },
53 { "EditDelete", CK_Delete },
54 { "EditEnter", CK_Enter },
55 { "EditPageUp", CK_Page_Up },
56 { "EditPageDown", CK_Page_Down },
57 { "EditLeft", CK_Left },
58 { "EditRight", CK_Right },
59 { "EditWordLeft", CK_Word_Left },
60 { "EditWordRight", CK_Word_Right },
61 { "EditUp", CK_Up },
62 { "EditDown", CK_Down },
63 { "EditHome", CK_Home },
64 { "EditEnd", CK_End },
65 { "EditTab", CK_Tab },
66 { "EditUndo", CK_Undo },
67 { "EditBeginningOfText", CK_Beginning_Of_Text },
68 { "EditEndOfText", CK_End_Of_Text },
69 { "EditScrollUp", CK_Scroll_Up },
70 { "EditScrollDown", CK_Scroll_Down },
71 { "EditReturn", CK_Return },
72 { "EditBeginPage", CK_Begin_Page },
73 { "EditEndPage", CK_End_Page },
74 { "EditDeleteWordLeft", CK_Delete_Word_Left },
75 { "EditDeleteWordRight", CK_Delete_Word_Right },
76 { "EditParagraphUp", CK_Paragraph_Up },
77 { "EditParagraphDown", CK_Paragraph_Down },
78 { "EditMenu", CK_Menu },
79 { "EditSave", CK_Save },
80 { "EditLoad", CK_Load },
81 { "EditNew", CK_New },
82 { "EditSaveas", CK_Save_As },
83 { "EditMark", CK_Mark },
84 { "EditCopy", CK_Copy },
85 { "EditMove", CK_Move },
86 { "EditRemove", CK_Remove },
87 { "EditMarkAll", CK_Mark_All },
88 { "EditUnmark", CK_Unmark },
89 { "EditSaveBlock", CK_Save_Block },
90 { "EditColumnMark", CK_Column_Mark },
91 { "EditFind", CK_Find },
92 { "EditFindAgain", CK_Find_Again },
93 { "EditReplace", CK_Replace },
94 { "EditReplaceAgain", CK_Replace_Again },
95 { "EditCompleteWord", CK_Complete_Word },
97 #if 0
98 { "EditDebugStart", CK_Debug_Start },
99 { "EditDebugStop", CK_Debug_Stop },
100 { "EditDebugToggleBreak", CK_Debug_Toggle_Break },
101 { "EditDebugClear", CK_Debug_Clear },
102 { "EditDebugNext", CK_Debug_Next },
103 { "EditDebugStep", CK_Debug_Step },
104 { "EditDebugBackTrace", CK_Debug_Back_Trace },
105 { "EditDebugContinue", CK_Debug_Continue },
106 { "EditDebugEnterCommand", CK_Debug_Enter_Command },
107 { "EditDebugUntilCurser", CK_Debug_Until_Curser },
108 #endif
109 { "EditInsertFile", CK_Insert_File },
110 { "EditQuit", CK_Quit },
111 { "EditToggleInsert", CK_Toggle_Insert },
112 { "EditHelp", CK_Help },
113 { "EditDate", CK_Date },
114 { "EditRefresh", CK_Refresh },
115 { "EditGoto", CK_Goto },
116 { "EditDeleteLine", CK_Delete_Line },
117 { "EditDeleteToLineEnd", CK_Delete_To_Line_End },
118 { "EditDeleteToLineBegin", CK_Delete_To_Line_Begin },
119 { "EditManPage", CK_Man_Page },
120 { "EditSort", CK_Sort },
121 { "EditMail", CK_Mail },
122 { "EditCancel", CK_Cancel },
123 { "EditComplete", CK_Complete },
124 { "EditParagraphFormat", CK_Paragraph_Format },
125 { "EditUtil", CK_Util },
126 { "EditTypeLoadPython", CK_Type_Load_Python },
127 { "EditFindFile", CK_Find_File },
128 { "EditCtags", CK_Ctags },
129 { "EditMatchBracket", CK_Match_Bracket },
130 { "EditTerminal", CK_Terminal },
131 { "EditTerminalApp", CK_Terminal_App },
132 { "EditExtCmd", CK_ExtCmd },
133 { "EditUserMenu", CK_User_Menu },
134 { "EditBeginRecordMacro", CK_Begin_Record_Macro },
135 { "EditEndRecordMacro", CK_End_Record_Macro },
136 { "EditDeleteMacro", CK_Delete_Macro },
137 { "EditToggleBookmark", CK_Toggle_Bookmark },
138 { "EditFlushBookmarks", CK_Flush_Bookmarks },
139 { "EditNextBookmark", CK_Next_Bookmark },
140 { "EditPrevBookmark", CK_Prev_Bookmark },
141 { "EditPageUpHighlight", CK_Page_Up_Highlight },
142 { "EditPageDownHighlight", CK_Page_Down_Highlight },
143 { "EditLeftHighlight", CK_Left_Highlight },
144 { "EditRightHighlight", CK_Right_Highlight },
145 { "EditWordLeftHighlight", CK_Word_Left_Highlight },
146 { "EditWordRightHighlight", CK_Word_Right_Highlight },
147 { "EditUpHighlight", CK_Up_Highlight },
148 { "EditDownHighlight", CK_Down_Highlight },
149 { "EditHomeHighlight", CK_Home_Highlight },
150 { "EditEndHighlight", CK_End_Highlight },
151 { "EditBeginningOfTextHighlight", CK_Beginning_Of_Text_Highlight },
152 { "EditEndOfTextHighlight", CK_End_Of_Text_Highlight },
153 { "EditBeginPageHighlight", CK_Begin_Page_Highlight },
154 { "EditEndPageHighlight", CK_End_Page_Highlight },
155 { "EditScrollUpHighlight", CK_Scroll_Up_Highlight },
156 { "EditScrollDownHighlight", CK_Scroll_Down_Highlight },
157 { "EditParagraphUpHighlight", CK_Paragraph_Up_Highlight },
158 { "EditParagraphDownHighlight", CK_Paragraph_Down_Highlight },
160 { "EditPageUpAltHighlight", CK_Page_Up_Alt_Highlight },
161 { "EditPageDownAltHighlight", CK_Page_Down_Alt_Highlight },
162 { "EditLeftAltHighlight", CK_Left_Alt_Highlight },
163 { "EditRightAltHighlight", CK_Right_Alt_Highlight },
164 { "EditWordLeftAltHighlight", CK_Word_Left_Alt_Highlight },
165 { "EditWordRightAltHighlight", CK_Word_Right_Alt_Highlight },
166 { "EditUpAltHighlight", CK_Up_Alt_Highlight },
167 { "EditDownAltHighlight", CK_Down_Alt_Highlight },
168 { "EditHomeAltHighlight", CK_Home_Alt_Highlight },
169 { "EditEndAltHighlight", CK_End_Alt_Highlight },
170 { "EditBeginningOfTextAltHighlight", CK_Beginning_Of_Text_Alt_Highlight },
171 { "EditEndOfTextAltHighlight", CK_End_Of_Text_Alt_Highlight },
172 { "EditBeginPageAltHighlight", CK_Begin_Page_Alt_Highlight },
173 { "EditEndPageAltHighlight", CK_End_Page_Alt_Highlight },
174 { "EditScrollUpAltHighlight", CK_Scroll_Up_Alt_Highlight },
175 { "EditScrollDownAltHighlight", CK_Scroll_Down_Alt_Highlight },
176 { "EditParagraphUpAltHighlight", CK_Paragraph_Up_Alt_Highlight },
177 { "EditParagraphDownAltHighlight", CK_Paragraph_Down_Alt_Highlight },
179 { "EditShiftBlockLeft", CK_Shift_Block_Left },
180 { "EditShiftBlockRight", CK_Shift_Block_Right },
182 { "EditXStore", CK_XStore },
183 { "EditXCut", CK_XCut },
184 { "EditXPaste", CK_XPaste },
185 { "EditSelectionHistory", CK_Selection_History },
186 { "EditShell", CK_Shell },
187 { "EditInsertLiteral", CK_Insert_Literal },
188 { "EditExecuteMacro", CK_Execute_Macro },
189 { "EditBeginOrEndMacro", CK_Begin_End_Macro },
190 { "EditExtMode", CK_Ext_Mode },
191 { "EditToggleLineState", CK_Toggle_Line_State },
192 { "EditToggleTabTWS", CK_Toggle_Tab_TWS },
193 { "EditToggleSyntax", CK_Toggle_Syntax },
194 { "EditToggleShowMargin", CK_Toggle_Show_Margin },
195 { "EditFindDefinition", CK_Find_Definition },
196 { "EditLoadPrevFile", CK_Load_Prev_File },
197 { "EditLoadNextFile", CK_Load_Next_File },
198 { "EditOptions", CK_Edit_Options },
199 { "EditSaveMode", CK_Edit_Save_Mode },
200 { "EditChooseSyntax", CK_Choose_Syntax },
201 { "EditAbout", CK_About },
203 #if 0
204 { "EditFocusNext", CK_Focus_Next },
205 { "EditFocusPrev", CK_Focus_Prev },
206 { "EditHeightInc", CK_Height_Inc },
207 { "EditHeightDec", CK_Height_Dec },
208 { "EditMake", CK_Make },
209 { "EditErrorNext", CK_Error_Next },
210 { "EditErrorPrev", CK_Error_Prev },
211 #endif
213 #if 0
214 { "EditSaveDesktop", CK_Save_Desktop },
215 { "EditNewWindow", CK_New_Window },
216 { "EditCycle", CK_Cycle },
217 { "EditSaveAndQuit", CK_Save_And_Quit },
218 { "EditRunAnother", CK_Run_Another },
219 { "EditCheckSaveAndQuit", CK_Check_Save_And_Quit },
220 { "EditMaximize", CK_Maximize },
221 #endif
223 #endif /* USE_INTERNAL_EDIT */
225 /* viewer */
226 { "ViewHelp", CK_ViewHelp },
227 { "ViewToggleWrapMode", CK_ViewToggleWrapMode },
228 { "ViewToggleHexEditMode", CK_ViewToggleHexEditMode },
229 { "ViewQuit", CK_ViewQuit },
230 { "ViewToggleHexMode", CK_ViewToggleHexMode },
231 { "ViewGoto", CK_ViewGoto },
232 { "ViewHexEditSave", CK_ViewHexEditSave },
233 { "ViewSearch", CK_ViewSearch },
234 { "ViewToggleMagicMode", CK_ViewToggleMagicMode },
235 { "ViewToggleNroffMode", CK_ViewToggleNroffMode },
236 { "ViewContinueSearch", CK_ViewContinueSearch },
237 { "ViewGotoBookmark", CK_ViewGotoBookmark },
238 { "ViewNewBookmark", CK_ViewNewBookmark },
239 { "ViewMoveUp", CK_ViewMoveUp },
240 { "ViewMoveDown", CK_ViewMoveDown },
241 { "ViewMoveLeft", CK_ViewMoveLeft },
242 { "ViewMoveRight", CK_ViewMoveRight },
243 { "ViewMovePgDn", CK_ViewMovePgDn },
244 { "ViewMovePgUp", CK_ViewMovePgUp },
245 { "ViewMoveHalfPgDn", CK_ViewMoveHalfPgDn },
246 { "ViewMoveHalfPgUp", CK_ViewMoveHalfPgUp },
247 { "ViewMoveToBol", CK_ViewMoveToBol },
248 { "ViewMoveToEol", CK_ViewMoveToEol },
249 { "ViewNextFile", CK_ViewNextFile },
250 { "ViewPrevFile", CK_ViewPrevFile },
251 { "ViewToggleRuler", CK_ViewToggleRuler },
252 { "ViewToggleHexNavMode", CK_ViewToggleHexNavMode },
254 /* help */
255 { "HelpHelp", CK_HelpHelp },
256 { "HelpIndex", CK_HelpIndex },
257 { "HelpBack", CK_HelpBack },
258 { "HelpQuit", CK_HelpQuit },
259 { "HelpMoveUp", CK_HelpMoveUp },
260 { "HelpMoveDown", CK_HelpMoveDown },
261 { "HelpSelectLink", CK_HelpSelectLink },
262 { "HelpNextLink", CK_HelpNextLink },
263 { "HelpPrevLink", CK_HelpPrevLink },
264 { "HelpNextNode", CK_HelpNextNode },
265 { "HelpPrevNode", CK_HelpPrevNode },
267 /* tree */
268 { "TreeHelp", CK_TreeHelp },
269 { "TreeForget", CK_TreeForget },
270 { "TreeToggleNav", CK_TreeToggleNav },
271 { "TreeCopy", CK_TreeCopy },
272 { "TreeMove", CK_TreeMove },
273 { "TreeMake", CK_TreeMake },
274 { "TreeMoveUp", CK_TreeMoveUp },
275 { "TreeMoveDown", CK_TreeMoveDown },
276 { "TreeMoveLeft", CK_TreeMoveLeft },
277 { "TreeMoveRight", CK_TreeMoveRight },
278 { "TreeMoveHome", CK_TreeMoveHome },
279 { "TreeMoveEnd", CK_TreeMoveEnd },
280 { "TreeMovePgUp", CK_TreeMovePgUp },
281 { "TreeMovePgDn", CK_TreeMovePgDn },
282 { "TreeOpen", CK_TreeOpen },
283 { "TreeRescan", CK_TreeRescan },
284 { "TreeStartSearch", CK_TreeStartSearch },
285 { "TreeRemove", CK_TreeRemove },
287 /* main commands */
288 { "CmdHelp", CK_HelpCmd },
289 { "CmdMenu", CK_MenuCmd },
290 { "CmdChmod", CK_ChmodCmd },
291 { "CmdMenuLastSelected", CK_MenuLastSelectedCmd },
292 { "CmdSingleDirsize", CK_SingleDirsizeCmd },
293 { "CmdCopyCurrentPathname", CK_CopyCurrentPathname },
294 { "CmdCopyOtherPathname", CK_CopyOtherPathname },
295 { "CmdSuspend", CK_SuspendCmd },
296 { "CmdToggleListing", CK_ToggleListingCmd },
297 { "CmdChownAdvanced", CK_ChownAdvancedCmd },
298 { "CmdChown", CK_ChownCmd },
299 { "CmdCompareDirs", CK_CompareDirsCmd },
300 { "CmdConfigureBox", CK_ConfigureBox },
301 { "CmdConfigureVfs", CK_ConfigureVfs },
302 { "CmdConfirmBox", CK_ConfirmBox },
303 { "CmdCopy", CK_CopyCmd },
304 { "CmdDelete", CK_DeleteCmd },
305 { "CmdDirsizes", CK_DirsizesCmd },
306 { "CmdDisplayBitsBox", CK_DisplayBitsBox },
307 { "CmdEdit", CK_EditCmd },
308 { "CmdEditExtFile", CK_EditExtFileCmd },
309 { "CmdEditFhlFile", CK_EditFhlFileCmd },
310 { "CmdEditMcMenu", CK_EditMcMenuCmd },
311 { "CmdEditSymlink", CK_EditSymlinkCmd },
312 { "CmdEditSyntax", CK_EditSyntaxCmd },
313 { "CmdEditUserMenu", CK_EditUserMenuCmd },
314 { "CmdExternalPanelize", CK_ExternalPanelize },
315 { "CmdFilter", CK_FilterCmd },
316 { "CmdFilteredView", CK_FilteredViewCmd },
317 { "CmdFind", CK_FindCmd },
318 #ifdef USE_NETCODE
319 { "CmdFishlink", CK_FishlinkCmd },
320 { "CmdFtplink", CK_FtplinkCmd },
321 #endif
322 { "CmdHistory", CK_HistoryCmd },
323 { "CmdInfo", CK_InfoCmd },
324 #ifdef WITH_BACKGROUND
325 { "CmdJobs", CK_JobsCmd },
326 #endif
327 { "CmdLayout", CK_LayoutCmd },
328 { "CmdLearnKeys", CK_LearnKeys },
329 { "CmdLink", CK_LinkCmd },
330 { "CmdListing", CK_ListingCmd },
331 #ifdef LISTMODE_EDITOR
332 { "CmdListmodeCmd", CK_ListmodeCmd }.
333 #endif
334 { "CmdMkdir", CK_MkdirCmd },
335 #if defined (USE_NETCODE) && defined (ENABLE_VFS_MCFS)
336 { "CmdNetlink", CK_NetlinkCmd },
337 #endif
338 { "CmdQuickCd", CK_QuickCdCmd },
339 { "CmdQuickChdir", CK_QuickChdirCmd },
340 { "CmdQuickView", CK_QuickViewCmd },
341 { "CmdQuietQuit", CK_QuietQuitCmd },
342 { "CmdRename", CK_RenameCmd },
343 { "CmdReread", CK_RereadCmd },
344 { "CmdReselectVfs", CK_ReselectVfs },
345 { "CmdReverseSelection", CK_ReverseSelectionCmd },
346 { "CmdSaveSetup", CK_SaveSetupCmd },
347 { "CmdSelect", CK_SelectCmd },
348 #if defined (USE_NETCODE) && defined (ENABLE_VFS_SMB)
349 { "CmdSmblinkCmd", CK_SmblinkCmd },
350 #endif /* USE_NETCODE || ENABLE_VFS_SMB */
351 { "CmdSwapPanel", CK_SwapCmd },
352 { "CmdSymlink", CK_SymlinkCmd },
353 { "CmdTree", CK_TreeCmd },
354 { "CmdTreeBox", CK_TreeBoxCmd },
355 #ifdef USE_EXT2FSLIB
356 { "CmdUndelete", CK_UndeleteCmd },
357 #endif
358 { "CmdUnselect", CK_UnselectCmd },
359 { "CmdUserMenu", CK_UserMenuCmd },
360 { "CmdUserFileMenu", CK_UserFileMenuCmd },
361 { "CmdView", CK_ViewCmd },
362 { "CmdViewFile", CK_ViewFileCmd },
363 { "CmdCopyCurrentReadlink", CK_CopyCurrentReadlink },
364 { "CmdCopyOtherReadlink", CK_CopyOtherReadlink },
365 { "CmdAddHotlist", CK_AddHotlist },
366 { "CmdQuit", CK_QuitCmd },
367 { "CmdCopyCurrentTagged", CK_CopyCurrentTagged },
368 { "CmdCopyOtherTagged", CK_CopyOtherTagged },
369 { "CmdToggleShowHidden", CK_ToggleShowHidden },
371 /* panel */
372 { "PanelChdirOtherPanel", CK_PanelChdirOtherPanel },
373 { "PanelChdirToReadlink", CK_PanelChdirToReadlink },
374 { "PanelCopyLocal", CK_PanelCmdCopyLocal },
375 { "PanelDeleteLocal", CK_PanelCmdDeleteLocal },
376 { "PanelDoEnter", CK_PanelCmdDoEnter },
377 { "PanelEditNew", CK_PanelCmdEditNew },
378 { "PanelRenameLocal", CK_PanelCmdRenameLocal },
379 { "PanelReverseSelection", CK_PanelCmdReverseSelection },
380 { "PanelSelect", CK_PanelCmdSelect },
381 { "PanelUnselect", CK_PanelCmdUnselect },
382 { "PanelViewSimple", CK_PanelCmdViewSimple },
383 { "PanelCtrlNextPage", CK_PanelCtrlNextPage },
384 { "PanelCtrlPrevPage", CK_PanelCtrlPrevPage },
385 { "PanelDirectoryHistoryList", CK_PanelDirectoryHistoryList },
386 { "PanelDirectoryHistoryNext", CK_PanelDirectoryHistoryNext },
387 { "PanelDirectoryHistoryPrev", CK_PanelDirectoryHistoryPrev },
388 { "PanelGotoBottomFile", CK_PanelGotoBottomFile },
389 { "PanelGotoMiddleFile", CK_PanelGotoMiddleFile },
390 { "PanelGotoTopFile", CK_PanelGotoTopFile },
391 { "PanelMarkFile", CK_PanelMarkFile },
392 { "PanelMoveUp", CK_PanelMoveUp },
393 { "PanelMoveDown", CK_PanelMoveDown },
394 { "PanelMoveLeft", CK_PanelMoveLeft },
395 { "PanelMoveRight", CK_PanelMoveRight },
396 { "PanelMoveEnd", CK_PanelMoveEnd },
397 { "PanelMoveHome", CK_PanelMoveHome },
398 { "PanelNextPage", CK_PanelNextPage },
399 { "PanelPrevPage", CK_PanelPrevPage },
400 #ifdef HAVE_CHARSET
401 { "PanelSetPanelEncoding", CK_PanelSetPanelEncoding },
402 #endif
403 { "PanelStartSearch", CK_PanelStartSearch },
404 { "PanelSyncOtherPanel", CK_PanelSyncOtherPanel },
405 { "PanelToggleSortOrderNext", CK_PanelToggleSortOrderNext },
406 { "PanelToggleSortOrderPrev", CK_PanelToggleSortOrderPrev },
407 { "PanelSelectSortOrder", CK_PanelSelectSortOrder },
408 { "PanelReverseSort", CK_PanelReverseSort },
409 { "PanelSortOrderByName", CK_PanelSortOrderByName },
410 { "PanelSortOrderByExt", CK_PanelSortOrderByExt },
411 { "PanelSortOrderBySize", CK_PanelSortOrderBySize },
412 { "PanelSortOrderByMTime", CK_PanelSortOrderByMTime },
414 /* input line */
415 { "InputBol", CK_InputBol },
416 { "InputEol", CK_InputEol },
417 { "InputMoveLeft", CK_InputMoveLeft },
418 { "InputWordLeft", CK_InputWordLeft },
419 { "InputBackwardChar", CK_InputBackwardChar },
420 { "InputBackwardWord", CK_InputBackwardWord },
421 { "InputMoveRight", CK_InputMoveRight },
422 { "InputWordRight", CK_InputWordRight },
423 { "InputForwardChar", CK_InputForwardChar },
424 { "InputForwardWord", CK_InputForwardWord },
425 { "InputBackwardDelete", CK_InputBackwardDelete },
426 { "InputDeleteChar", CK_InputDeleteChar },
427 { "InputKillWord", CK_InputKillWord },
428 { "InputBackwardKillWord", CK_InputBackwardKillWord },
429 { "InputSetMark", CK_InputSetMark },
430 { "InputKillRegion", CK_InputKillRegion },
431 { "InputYank", CK_InputYank },
432 { "InputKillLine", CK_InputKillLine },
433 { "InputHistoryPrev", CK_InputHistoryPrev },
434 { "InputHistoryNext", CK_InputHistoryNext },
435 { "InputHistoryShow", CK_InputHistoryShow },
436 { "InputComplete", CK_InputComplete },
437 { "InputXStore", CK_InputKillSave },
438 { "InputXPaste", CK_InputPaste },
439 { "InputClearLine", CK_InputClearLine },
441 /* common */
442 { "ExtMap1", CK_StartExtMap1 },
443 { "ExtMap2", CK_StartExtMap2 },
444 { "ShowCommandLine", CK_ShowCommandLine },
445 { "SelectCodepage", CK_SelectCodepage },
447 { NULL, CK_Ignore_Key }
450 static const size_t num_command_names = sizeof (command_names) /
451 sizeof (command_names[0]) - 1;
453 /*** global variables ****************************************************************************/
455 /* viewer/actions_cmd.c */
456 const global_keymap_t default_viewer_keymap[] = {
457 { KEY_F (1), CK_ViewHelp, "F1" },
458 { KEY_F (2), CK_ViewToggleWrapMode, "F2" },
459 { KEY_F (3), CK_ViewQuit, "F3" },
460 { KEY_F (4), CK_ViewToggleHexMode, "F4" },
461 { KEY_F (5), CK_ViewGoto, "F5" },
462 { KEY_F (7), CK_ViewSearch, "F7" },
463 { KEY_F (8), CK_ViewToggleMagicMode, "F8" },
464 { KEY_F (9), CK_ViewToggleNroffMode, "F9" },
465 { KEY_F (10), CK_ViewQuit, "F10" },
467 { '?', CK_ViewSearch, "?" },
468 { '/', CK_ViewSearch, "/" },
469 { XCTRL ('r'), CK_ViewContinueSearch, "C-r" },
470 { XCTRL ('s'), CK_ViewContinueSearch, "C-s" },
471 { KEY_F (17), CK_ViewContinueSearch, "S-F7" },
472 { 'n', CK_ViewContinueSearch, "n" },
473 { ALT ('r'), CK_ViewToggleRuler, "M-r" },
475 { XCTRL ('a'), CK_ViewMoveToBol, "C-a" },
476 { XCTRL ('e'), CK_ViewMoveToEol, "C-e" },
478 { 'h', CK_ViewMoveLeft, "h" },
479 { KEY_LEFT, CK_ViewMoveLeft, "Left" },
481 { 'l', CK_ViewMoveRight, "l" },
482 { KEY_RIGHT, CK_ViewMoveRight, "Right" },
484 { 'k', CK_ViewMoveUp, "k" },
485 { 'y', CK_ViewMoveUp, "y" },
486 { KEY_IC, CK_ViewMoveUp, "Insert" },
487 { KEY_UP, CK_ViewMoveUp, "Up" },
489 { 'j', CK_ViewMoveDown, "j" },
490 { 'e', CK_ViewMoveDown, "e" },
491 { KEY_DOWN, CK_ViewMoveDown, "Down" },
492 { KEY_DC, CK_ViewMoveDown, "Delete" },
494 { ' ', CK_ViewMovePgDn, "Space" },
495 { 'f', CK_ViewMovePgDn, "f" },
496 { KEY_NPAGE, CK_ViewMovePgDn, "PgDn" },
498 { 'b', CK_ViewMovePgUp, "b" },
499 { KEY_PPAGE, CK_ViewMovePgUp, "PgUp" },
501 { 'd', CK_ViewMoveHalfPgDn, "d" },
502 { 'u', CK_ViewMoveHalfPgUp, "u" },
504 { 'm', CK_ViewGotoBookmark, "m" },
505 { 'r', CK_ViewNewBookmark, "r" },
507 { XCTRL ('f'), CK_ViewNextFile, "C-f" },
508 { XCTRL ('b'), CK_ViewPrevFile, "C-b" },
510 { 'q', CK_ViewQuit, "q" },
511 { XCTRL ('g'), CK_ViewQuit, "C-g" },
512 { ESC_CHAR, CK_ViewQuit, "Esc" },
514 { ALT ('e'), CK_SelectCodepage, "M-e" },
515 { XCTRL ('o'), CK_ShowCommandLine, "C-o" },
517 { 0, CK_Ignore_Key, "" }
520 const global_keymap_t default_viewer_hex_keymap[] = {
521 { KEY_F (1), CK_ViewHelp, "F1" },
522 { KEY_F (2), CK_ViewToggleHexEditMode, "F2" },
523 { KEY_F (3), CK_ViewQuit, "F3" },
524 { KEY_F (4), CK_ViewToggleHexMode, "F4" },
525 { KEY_F (5), CK_ViewGoto, "F5" },
526 { KEY_F (6), CK_ViewHexEditSave, "F6" },
527 { KEY_F (7), CK_ViewSearch, "F7" },
528 { KEY_F (8), CK_ViewToggleMagicMode, "F8" },
529 { KEY_F (9), CK_ViewToggleNroffMode, "F9" },
530 { KEY_F (10), CK_ViewQuit, "F10" },
532 { '?', CK_ViewSearch, "?" },
533 { '/', CK_ViewSearch, "/" },
534 { XCTRL ('r'), CK_ViewContinueSearch, "C-r" },
535 { XCTRL ('s'), CK_ViewContinueSearch, "C-s" },
536 { KEY_F (17), CK_ViewContinueSearch, "S-F7" },
537 { 'n', CK_ViewContinueSearch, "n" },
539 { '\t', CK_ViewToggleHexNavMode, "Tab" },
540 { XCTRL ('a'), CK_ViewMoveToBol, "C-a" },
541 { XCTRL ('e'), CK_ViewMoveToEol, "C-e" },
543 { 'b', CK_ViewMoveLeft, "b" },
544 { KEY_LEFT, CK_ViewMoveLeft, "Left" },
546 { 'f', CK_ViewMoveRight, "f" },
547 { KEY_RIGHT, CK_ViewMoveRight, "Right" },
549 { 'k', CK_ViewMoveUp, "k" },
550 { 'y', CK_ViewMoveUp, "y" },
551 { KEY_UP, CK_ViewMoveUp, "Up" },
553 { 'j', CK_ViewMoveDown, "j" },
554 { KEY_DOWN, CK_ViewMoveDown, "Down" },
555 { KEY_DC, CK_ViewMoveDown, "Delete" },
557 { 'q', CK_ViewQuit, "q" },
558 { XCTRL ('g'), CK_ViewQuit, "C-g" },
559 { ESC_CHAR, CK_ViewQuit, "Esc" },
561 { ALT ('e'), CK_SelectCodepage, "M-e" },
562 { XCTRL ('o'), CK_ShowCommandLine, "C-o" },
564 { 0, CK_Ignore_Key, "" }
567 #ifdef USE_INTERNAL_EDIT
568 /* ../edit/editkeys.c */
569 const global_keymap_t default_editor_keymap[] = {
570 { '\n', CK_Enter, "Enter" },
571 { '\t', CK_Tab, "Tab" },
573 { KEY_F (1), CK_Help, "F1" },
574 { KEY_F (2), CK_Save, "F2" },
575 { KEY_F (3), CK_Mark, "F3" },
576 { KEY_F (4), CK_Replace, "F4" },
577 { KEY_F (5), CK_Copy, "F5" },
578 { KEY_F (6), CK_Move, "F6" },
579 { KEY_F (7), CK_Find, "F7" },
580 { KEY_F (8), CK_Remove, "F8" },
581 { KEY_F (9), CK_Menu, "F9" },
582 { KEY_F (10), CK_Quit, "F10" },
583 /* edit user menu */
584 { KEY_F (11), CK_User_Menu, "S-F1" },
585 { KEY_F (12), CK_Save_As, "S-F2" },
586 { KEY_F (13), CK_Column_Mark, "S-F3" },
587 { KEY_F (14), CK_Replace_Again, "S-F4" },
588 { KEY_F (15), CK_Insert_File, "S-F5" },
589 { KEY_F (17), CK_Find_Again, "S-F7" },
590 /* C formatter */
591 { KEY_F (19), CK_Pipe_Block (0), "S-F9" },
593 { ESC_CHAR, CK_Quit, "Esc" },
594 { KEY_BACKSPACE, CK_BackSpace, "BackSpace" },
595 { KEY_DC, CK_Delete, "Delete" },
596 { KEY_DOWN, CK_Down, "Down" },
597 { KEY_END, CK_End, "End" },
598 { KEY_HOME, CK_Home, "Home" },
599 { KEY_IC, CK_Toggle_Insert, "Insert" },
600 { KEY_LEFT, CK_Left, "Left" },
601 { KEY_NPAGE, CK_Page_Down, "PgDn" },
602 { KEY_PPAGE, CK_Page_Up, "PgUp" },
603 { KEY_RIGHT, CK_Right, "Right" },
604 { KEY_UP, CK_Up, "Up" },
606 /* Ctrl */
607 { KEY_M_CTRL | (KEY_F (2)), CK_Save_As, "C-F2" },
608 { KEY_M_CTRL | (KEY_F (4)), CK_Replace_Again, "C-F4" },
609 { KEY_M_CTRL | (KEY_F (7)), CK_Find_Again, "C-F7" },
610 { KEY_M_CTRL | KEY_BACKSPACE, CK_Undo, "C-BackSpace" },
611 { KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text, "C-PgDn" },
612 { KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text, "C-PgUp" },
613 { KEY_M_CTRL | KEY_HOME, CK_Beginning_Of_Text, "C-Home" },
614 { KEY_M_CTRL | KEY_END, CK_End_Of_Text, "C-End" },
615 { KEY_M_CTRL | KEY_UP, CK_Scroll_Up, "C-Up" },
616 { KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down, "C-Down" },
617 { KEY_M_CTRL | KEY_LEFT, CK_Word_Left, "C-Left" },
618 { KEY_M_CTRL | KEY_RIGHT, CK_Word_Right, "C-Right" },
619 { KEY_M_CTRL | KEY_IC, CK_XStore, "C-Insert" },
620 { KEY_M_CTRL | KEY_DC, CK_Remove, "C-Delete" },
622 { XCTRL ('n'), CK_New, "C-n" },
623 { XCTRL ('k'), CK_Delete_To_Line_End, "C-k" },
624 { XCTRL ('l'), CK_Refresh, "C-l" },
625 { XCTRL ('o'), CK_Shell, "C-o" },
626 { XCTRL ('s'), CK_Toggle_Syntax, "C-s" },
627 { XCTRL ('u'), CK_Undo, "C-u" },
628 { ALT ('e'), CK_SelectCodepage, "M-e" },
629 { XCTRL ('q'), CK_Insert_Literal, "C-q" },
630 { XCTRL ('r'), CK_Begin_End_Macro, "C-r" },
631 { XCTRL ('r'), CK_Begin_Record_Macro, "C-r" },
632 { XCTRL ('r'), CK_End_Record_Macro, "C-r" },
633 { XCTRL ('a'), CK_Execute_Macro, "C-a" },
635 /* Shift */
636 { KEY_M_SHIFT | KEY_NPAGE, CK_Page_Down_Highlight, "S-PgDn" },
637 { KEY_M_SHIFT | KEY_PPAGE, CK_Page_Up_Highlight, "S-PgUp" },
638 { KEY_M_SHIFT | KEY_LEFT, CK_Left_Highlight, "S-Left" },
639 { KEY_M_SHIFT | KEY_RIGHT, CK_Right_Highlight, "S-Right" },
640 { KEY_M_SHIFT | KEY_UP, CK_Up_Highlight, "S-Up" },
641 { KEY_M_SHIFT | KEY_DOWN, CK_Down_Highlight, "S-Down" },
642 { KEY_M_SHIFT | KEY_HOME, CK_Home_Highlight, "S-Home" },
643 { KEY_M_SHIFT | KEY_END, CK_End_Highlight, "S-End" },
644 { KEY_M_SHIFT | KEY_IC, CK_XPaste, "S-Insert" },
645 { KEY_M_SHIFT | KEY_DC, CK_XCut, "S-Delete" },
646 /* useful for pasting multiline text */
647 { KEY_M_SHIFT | '\n', CK_Return, "S-Enter" },
649 /* Ctrl + Shift */
650 { KEY_M_SHIFT | KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text_Highlight, "C-S-PgDn" },
651 { KEY_M_SHIFT | KEY_M_CTRL | KEY_PPAGE, CK_Beginning_Of_Text_Highlight, "C-S-PgUp" },
652 { KEY_M_SHIFT | KEY_M_CTRL | KEY_LEFT, CK_Word_Left_Highlight, "C-S-Left" },
653 { KEY_M_SHIFT | KEY_M_CTRL | KEY_RIGHT, CK_Word_Right_Highlight, "C-S-Right" },
654 { KEY_M_SHIFT | KEY_M_CTRL | KEY_UP, CK_Scroll_Up_Highlight, "C-S-Up" },
655 { KEY_M_SHIFT | KEY_M_CTRL | KEY_DOWN, CK_Scroll_Down_Highlight, "C-S-Down" },
657 /* Alt */
658 { KEY_M_ALT | KEY_NPAGE, CK_Page_Down_Alt_Highlight, "M-PgDn" },
659 { KEY_M_ALT | KEY_PPAGE, CK_Page_Up_Alt_Highlight, "M-PgUp" },
660 { KEY_M_ALT | KEY_LEFT, CK_Left_Alt_Highlight, "M-Left" },
661 { KEY_M_ALT | KEY_RIGHT, CK_Right_Alt_Highlight, "M-Right" },
662 { KEY_M_ALT | KEY_UP, CK_Up_Alt_Highlight, "M-Up" },
663 { KEY_M_ALT | KEY_DOWN, CK_Down_Alt_Highlight, "M-Down" },
664 { KEY_M_ALT | KEY_HOME, CK_Home_Highlight, "M-Home" },
665 { KEY_M_ALT | KEY_END, CK_End_Alt_Highlight, "M-End" },
667 { ALT ('\n'), CK_Find_Definition, "M-Enter" },
668 { ALT ('\t'), CK_Complete_Word, "M-Tab" },
669 { ALT ('l'), CK_Goto, "M-l" },
670 { ALT ('L'), CK_Goto, "M-L" },
671 { ALT ('p'), CK_Paragraph_Format, "M-p" },
672 { ALT ('t'), CK_Sort, "M-t" },
673 { ALT ('u'), CK_ExtCmd, "M-u" },
674 { ALT ('<'), CK_Beginning_Of_Text, "M-<" },
675 { ALT ('>'), CK_End_Of_Text, "M->" },
676 { ALT ('-'), CK_Load_Prev_File, "M--" },
677 { ALT ('+'), CK_Load_Next_File, "M-+" },
678 { ALT ('d'), CK_Delete_Word_Right, "M-d" },
679 { ALT (KEY_BACKSPACE), CK_Delete_Word_Left, "M-BackSpace" },
680 { ALT ('n'), CK_Toggle_Line_State, "M-n" },
681 { ALT ('_'), CK_Toggle_Tab_TWS, "M-_" },
682 { ALT ('k'), CK_Toggle_Bookmark, "M-k" },
683 { ALT ('i'), CK_Prev_Bookmark, "M-i" },
684 { ALT ('j'), CK_Next_Bookmark, "M-j" },
685 { ALT ('o'), CK_Flush_Bookmarks, "M-o" },
687 { XCTRL ('x'), CK_Ext_Mode, "C-x" },
689 { 0, CK_Ignore_Key, "" }
692 /* emacs keyboard layout emulation */
693 const global_keymap_t default_editor_x_keymap[] = {
694 { 'k', CK_New, "k"},
695 { 'e', CK_Execute_Macro, "e"},
696 { 0, CK_Ignore_Key, "" }
698 #endif /* USE_INTERNAL_EDIT */
700 /* tree */
701 const global_keymap_t default_tree_keymap[] = {
702 { KEY_F (1), CK_TreeHelp, "F1"},
703 { KEY_F (2), CK_TreeRescan, "F2" },
704 { KEY_F (3), CK_TreeForget, "F3" },
705 { KEY_F (4), CK_TreeToggleNav, "F4" },
706 { KEY_F (5), CK_TreeCopy, "F5" },
707 { KEY_F (6), CK_TreeMove, "F6" },
708 #if 0
709 { KEY_F (7), CK_TreeMake, "F7" },
710 #endif
711 { KEY_F (8), CK_TreeRemove, "F8" },
712 { KEY_UP, CK_TreeMoveUp, "Up" },
713 { XCTRL ('p'), CK_TreeMoveUp, "C-p" },
714 { KEY_DOWN, CK_TreeMoveDown, "Down" },
715 { XCTRL ('n'), CK_TreeMoveDown, "C-n" },
716 { KEY_LEFT, CK_TreeMoveLeft, "Left" },
717 { KEY_RIGHT, CK_TreeMoveRight, "Right" },
718 { KEY_HOME, CK_TreeMoveHome, "Home" },
719 { ALT ('<'), CK_TreeMoveHome, "M-<" },
720 { KEY_END, CK_TreeMoveEnd , "End" },
721 { ALT ('>'), CK_TreeMoveEnd , "M->" },
722 { KEY_PPAGE, CK_TreeMovePgUp, "PgUp" },
723 { ALT ('v'), CK_TreeMovePgUp, "M-v" },
724 { KEY_NPAGE, CK_TreeMovePgDn, "PnDn" },
725 { XCTRL ('v'), CK_TreeMovePgDn, "C-v" },
726 { '\n', CK_TreeOpen, "Enter" },
727 { KEY_ENTER, CK_TreeOpen, "Enter" },
728 { XCTRL ('r'), CK_TreeRescan, "C-r" },
729 { XCTRL ('s'), CK_TreeStartSearch, "C-s" },
730 { ALT ('s'), CK_TreeStartSearch, "M-s" },
731 { KEY_DC, CK_TreeRemove, "Delete" },
732 { 0, CK_Ignore_Key, ""}
735 /* help */
736 const global_keymap_t default_help_keymap[] = {
737 { KEY_F (1), CK_HelpHelp, "F1" },
738 { KEY_F (2), CK_HelpIndex, "F2" },
739 { KEY_F (3), CK_HelpBack, "F3" },
740 { KEY_F (10), CK_HelpQuit, "F10" },
741 { KEY_LEFT, CK_HelpBack, "Left" },
742 { 'l', CK_HelpBack, "l" },
743 { KEY_DOWN, CK_HelpMoveDown, "Down" },
744 { KEY_UP, CK_HelpMoveUp, "Up" },
745 { KEY_RIGHT, CK_HelpSelectLink, "Right" },
746 { KEY_ENTER, CK_HelpSelectLink, "Enter" },
747 { '\n', CK_HelpSelectLink, "Enter" },
748 { '\t', CK_HelpNextLink, "Tab" },
749 { ALT ('\t'), CK_HelpPrevLink, "M-Tab" },
750 { 'n', CK_HelpNextNode, "n" },
751 { 'p', CK_HelpPrevNode, "p" },
752 { ESC_CHAR, CK_HelpQuit, "Esc" },
753 { XCTRL ('g'), CK_HelpQuit, "C-g" },
754 { 0, CK_Ignore_Key, "" }
757 /* screen.c */
758 const global_keymap_t default_panel_keymap[] = {
759 { ALT ('o'), CK_PanelChdirOtherPanel, "M-o" },
760 { ALT ('l'), CK_PanelChdirToReadlink, "M-l" },
761 { KEY_F (15), CK_PanelCmdCopyLocal, "S-F5" },
762 { KEY_F (18), CK_PanelCmdDeleteLocal, "S-F8" },
763 { KEY_ENTER, CK_PanelCmdDoEnter, "Enter" },
764 { '\n', CK_PanelCmdDoEnter, "Enter" },
765 { KEY_F (14), CK_PanelCmdEditNew, "S-F4" },
766 { KEY_F (16), CK_PanelCmdRenameLocal, "S-F6" },
767 { ALT ('*'), CK_PanelCmdReverseSelection, "M-*" },
768 { KEY_KP_ADD, CK_PanelCmdSelect, "M-+" },
769 { KEY_KP_SUBTRACT, CK_PanelCmdUnselect, "M--" },
770 { KEY_F (13), CK_PanelCmdViewSimple, "S-F3" },
771 { KEY_M_CTRL | KEY_NPAGE, CK_PanelCtrlNextPage, "C-PgDn" },
772 { KEY_M_CTRL | KEY_PPAGE, CK_PanelCtrlPrevPage, "C-PgUp" },
773 { ALT ('H'), CK_PanelDirectoryHistoryList, "M-H" },
774 { ALT ('u'), CK_PanelDirectoryHistoryNext, "M-u" },
775 { ALT ('y'), CK_PanelDirectoryHistoryPrev, "M-y" },
776 { ALT ('j'), CK_PanelGotoBottomFile, "M-j" },
777 { ALT ('r'), CK_PanelGotoMiddleFile, "M-r" },
778 { ALT ('g'), CK_PanelGotoTopFile, "M-g" },
779 { KEY_IC, CK_PanelMarkFile, "Insert" },
780 { KEY_UP, CK_PanelMoveUp, "Up" },
781 { KEY_DOWN, CK_PanelMoveDown, "Down" },
782 { KEY_LEFT, CK_PanelMoveLeft, "Left" },
783 { KEY_RIGHT, CK_PanelMoveRight, "Right" },
784 { KEY_END, CK_PanelMoveEnd, "End" },
785 { KEY_HOME, CK_PanelMoveHome, "Home" },
786 { KEY_A1, CK_PanelMoveHome, "Home" },
787 { KEY_NPAGE, CK_PanelNextPage, "PgDn" },
788 { KEY_PPAGE, CK_PanelPrevPage, "PgUp" },
789 { ALT ('e'), CK_PanelSetPanelEncoding, "M-e" },
790 { XCTRL ('s'), CK_PanelStartSearch, "C-s" },
791 { ALT ('s'), CK_PanelStartSearch, "M-s" },
792 { ALT ('i'), CK_PanelSyncOtherPanel, "M-i" },
793 { 0, CK_Ignore_Key , "" }
796 /* main.c */
797 const global_keymap_t default_main_map[] = {
798 { KEY_F (1), CK_HelpCmd, "F1" },
799 { KEY_F (2), CK_UserMenuCmd, "F2" },
800 { KEY_F (3), CK_ViewCmd, "F3" },
801 { KEY_F (4), CK_EditCmd, "F4" },
802 { KEY_F (5), CK_CopyCmd, "F5" },
803 { KEY_F (6), CK_RenameCmd, "F6" },
804 { KEY_F (7), CK_MkdirCmd, "F7" },
805 { KEY_F (8), CK_DeleteCmd, "F8" },
806 { KEY_F (9), CK_MenuCmd, "F9" },
807 { KEY_F (10), CK_QuitCmd, "F10" },
808 { KEY_F (13), CK_ViewFileCmd, "S-F3" },
809 { KEY_F (19), CK_MenuLastSelectedCmd, "S-F9" },
810 { KEY_F (20), CK_QuietQuitCmd, "S-10" },
811 { ALT ('h'), CK_HistoryCmd, "M-h" },
812 { XCTRL ('@'), CK_SingleDirsizeCmd, "C-Space" },
813 /* Copy useful information to the command line */
814 { ALT ('a'), CK_CopyCurrentPathname, "M-a" },
815 { ALT ('A'), CK_CopyOtherPathname, "M-A" },
816 { ALT ('c'), CK_QuickCdCmd, "M-c" },
817 /* To access the directory hotlist */
818 { XCTRL ('\\'), CK_QuickChdirCmd, "C-\\" },
819 /* Suspend */
820 { XCTRL ('z'), CK_SuspendCmd, "C-z" },
821 /* The filtered view command */
822 { ALT ('!'), CK_FilteredViewCmd, "M-!" },
823 /* Find file */
824 { ALT ('?'), CK_FindCmd, "M-?" },
825 /* Panel refresh */
826 { XCTRL ('r'), CK_RereadCmd, "C-r" },
827 /* Toggle listing between long, user defined and full formats */
828 { ALT ('t'), CK_ToggleListingCmd, "M-t" },
829 /* Swap panels */
830 { XCTRL ('u'), CK_SwapCmd, "C-u" },
831 /* View output */
832 { XCTRL ('o'), CK_ShowCommandLine, "C-o" },
833 { ALT ('.'), CK_ToggleShowHidden, "M-." },
834 { XCTRL ('x'), CK_StartExtMap1, "C-x" },
835 /* Select/unselect group */
836 { KEY_KP_ADD, CK_SelectCmd, "+" },
837 { KEY_KP_SUBTRACT, CK_UnselectCmd, "-" },
838 { ALT ('*'), CK_ReverseSelectionCmd, "*" },
839 { 0, CK_Ignore_Key, "" }
842 const global_keymap_t default_main_x_map[] = {
843 { 'd', CK_CompareDirsCmd, "d" },
844 #ifdef ENABLE_VFS
845 { 'a', CK_ReselectVfs, "a"},
846 #endif /* ENABLE_VFS */
847 { 'p', CK_CopyCurrentPathname, "p" },
848 { XCTRL ('p'), CK_CopyOtherPathname, "C-p" },
849 { 't', CK_CopyCurrentTagged, "t" },
850 { XCTRL ('t'), CK_CopyOtherTagged, "C-t" },
851 { 'c', CK_ChmodCmd, "c" },
852 { 'o', CK_ChownCmd, "o" },
853 { 'r', CK_CopyCurrentReadlink, "r" },
854 { XCTRL ('r'), CK_CopyOtherReadlink, "C-r" },
855 { 'l', CK_LinkCmd, "l" },
856 { 's', CK_SymlinkCmd, "s" },
857 { XCTRL ('s'), CK_EditSymlinkCmd, "C-s" },
858 { 'i', CK_InfoCmd, "i" },
859 { 'q', CK_QuickViewCmd, "q" },
860 { 'h', CK_AddHotlist, "h" },
861 { '!', CK_ExternalPanelize, "!" },
862 #ifdef WITH_BACKGROUND
863 { 'j', CK_JobsCmd, "j" },
864 #endif /* WITH_BACKGROUND */
865 { 0, CK_Ignore_Key, "" }
868 const global_keymap_t default_input_keymap[] = {
869 /* Motion */
870 { XCTRL ('a'), CK_InputBol, "C-a" },
871 { KEY_HOME, CK_InputBol, "Home" },
872 { KEY_A1, CK_InputBol, "Home" },
873 { ALT ('<'), CK_InputBol, "M-<" },
874 { XCTRL ('e'), CK_InputEol, "C-e" },
875 { KEY_END, CK_InputEol, "End" },
876 { KEY_C1, CK_InputEol, "End" },
877 { ALT ('>'), CK_InputEol, "M->" },
878 { KEY_LEFT, CK_InputMoveLeft, "Left" },
879 { KEY_M_CTRL | KEY_LEFT, CK_InputWordLeft, "C-Left" },
880 { KEY_RIGHT, CK_InputMoveRight, "Right" },
881 { KEY_M_CTRL | KEY_RIGHT, CK_InputWordRight, "C-Right" },
883 { XCTRL ('b'), CK_InputBackwardChar, "C-b" },
884 { ALT ('b'), CK_InputBackwardWord, "M-b" },
885 { XCTRL ('f'), CK_InputForwardChar, "C-f" },
886 { ALT ('f'), CK_InputForwardWord, "M-f" },
888 /* Editing */
889 { KEY_BACKSPACE, CK_InputBackwardDelete, "BackSpace" },
890 { KEY_DC, CK_InputDeleteChar, "Delete" },
891 { ALT ('d'), CK_InputKillWord, "M-d" },
892 { ALT (KEY_BACKSPACE), CK_InputBackwardKillWord, "M-BackSpace" },
894 /* Region manipulation */
895 { XCTRL ('w'), CK_InputKillRegion, "C-w" },
896 { ALT ('w'), CK_InputKillSave, "M-w" },
897 { XCTRL ('y'), CK_InputYank, "C-y" },
898 { XCTRL ('k'), CK_InputKillLine, "C-k" },
900 /* History */
901 { ALT ('p'), CK_InputHistoryPrev, "M-p" },
902 { ALT ('n'), CK_InputHistoryNext, "M-n" },
903 { ALT ('h'), CK_InputHistoryShow, "M-h" },
905 /* Completion */
906 { ALT ('\t'), CK_InputComplete, "M-tab" },
908 { 0, CK_Ignore_Key, "" }
911 static int
912 name_keymap_comparator (const void *p1, const void *p2)
914 const name_keymap_t *m1 = (const name_keymap_t *) p1;
915 const name_keymap_t *m2 = (const name_keymap_t *) p2;
917 return str_casecmp (m1->name, m2->name);
920 static inline void
921 sort_command_names (void)
923 static gboolean has_been_sorted = FALSE;
925 if (!has_been_sorted) {
926 qsort (command_names, num_command_names,
927 sizeof (command_names[0]), &name_keymap_comparator);
928 has_been_sorted = TRUE;
932 static void
933 keymap_add (GArray *keymap, long key, unsigned long cmd, const char *caption)
935 if (key != 0 && cmd != CK_Ignore_Key) {
936 global_keymap_t new_bind;
938 new_bind.key = key;
939 new_bind.command = cmd;
940 g_snprintf (new_bind.caption, sizeof (new_bind.caption), "%s", caption);
941 g_array_append_val (keymap, new_bind);
945 void
946 keybind_cmd_bind (GArray *keymap, const char *keybind, unsigned long action)
948 char *caption = NULL;
949 long key;
951 key = lookup_key (keybind, &caption);
952 keymap_add (keymap, key, action, caption);
953 g_free (caption);
956 unsigned long
957 lookup_action (const char *keyname)
959 const name_keymap_t key = { keyname, 0 };
960 name_keymap_t *res;
962 sort_command_names ();
964 res = bsearch (&key, command_names, num_command_names,
965 sizeof (command_names[0]), name_keymap_comparator);
967 return (res != NULL) ? res->val : CK_Ignore_Key;
970 const char *
971 lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action)
973 size_t i;
975 for (i = 0; keymap[i].key != 0; i++)
976 if (keymap[i].command == action)
977 return (keymap[i].caption[0] != '\0') ? keymap[i].caption : NULL;
979 return NULL;
982 unsigned long
983 lookup_keymap_command (const global_keymap_t *keymap, long key)
985 size_t i;
987 for (i = 0; keymap[i].key != 0; i++)
988 if (keymap[i].key == key)
989 return keymap[i].command;
991 return CK_Ignore_Key;