首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libreadline编辑和执行命令支持

libreadline编辑和执行命令支持
EN

Stack Overflow用户
提问于 2021-02-26 09:59:12
回答 1查看 40关注 0票数 0

在bash(和其他)中,我可以使用$EDITOR$VISUAL中定义的外部编辑器,使用C-x C-d或其他键绑定来编辑命令。

但是,当我在程序中使用libreadline时,默认情况下它没有类似的功能。

如何在我的程序中启用它?或者可能是bash特有的恐惧,而不是libreadline?那么该如何实现呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-26 18:31:31

我只是看了一下Bash源代码中的bashline.c,发现:

代码语言:javascript
复制
   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 }
....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66379067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档