簡體   English   中英

libreadline 編輯和執行命令支持

[英]libreadline edit-and-execute-command support

在 bash(和其他)中,我可以使用Cx Cd或其他鍵綁定使用$EDITOR$VISUAL中定義的外部編輯器來編輯命令。

但是,當我在程序中使用 libreadline 時,默認情況下它沒有類似的功能。

如何在我的程序中啟用它? 或者可能是 bash 特定的恐懼,而不是 libreadline? 那怎么實現呢?

剛剛看了一下Bash源碼中的 bashline.c 發現:

   1 /* bashline.c -- Bash's interface to the readline library. */
 ...
 440 /* Called once from parse.y if we are going to use readline. */
 441 void
 442 initialize_readline ()
 443 {
 ...
 482   rl_add_defun ("edit-and-execute-command", emacs_edit_and_execute_command, -1);
 ...
 592   /* Bind C-xC-e to invoke emacs and run result as commands. */
 593   rl_bind_key_if_unbound_in_map (CTRL ('E'), emacs_edit_and_execute_command, emacs_ctlx_keymap);
 594 #if defined (VI_MODE)
 595   rl_bind_key_if_unbound_in_map ('v', vi_edit_and_execute_command, vi_movement_keymap);
 ...
 924 #define VI_EDIT_COMMAND         "fc -e \"${VISUAL:-${EDITOR:-vi}}\""
 925 #define EMACS_EDIT_COMMAND      "fc -e \"${VISUAL:-${EDITOR:-emacs}}\""
 926 #define POSIX_VI_EDIT_COMMAND   "fc -e vi"
 ...
1003 #if defined (VI_MODE)
1004 static int
1005 vi_edit_and_execute_command (count, c)
1006      int count, c;
1007 {
1008   if (posixly_correct)
1009     return (edit_and_execute_command (count, c, VI_EDITING_MODE, POSIX_VI_EDIT_COMMAND));
1010   else
1011     return (edit_and_execute_command (count, c, VI_EDITING_MODE, VI_EDIT_COMMAND));
1012 }
1013 #endif /* VI_MODE */
1014 
1015 static int
1016 emacs_edit_and_execute_command (count, c)
1017      int count, c;
1018 {
1019   return (edit_and_execute_command (count, c, EMACS_EDITING_MODE, EMACS_EDIT_COMMAND));
1020 }
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM