【发布时间】:2013-08-23 08:56:50
【问题描述】:
我的 `.bashrc' 文件中定义了一些 bash 函数。在 emacs 中 shell-mode,我想用完整的函数名。
emacs `shell' 包默认不能完成功能,所以我 计划加强它。
问题是我无法获取 shell 的当前函数定义。这 查询函数定义的常用方法是键入:
$ declare -F
由于'declare'只是一个内置命令,我们应该将它包装在一个 脚本文件然后用 `bash' 调用它。使用 emacs 我们可以:
* create a file, wrap the code:
-------------- file: get-functions -----------
declare -F
-------------- file end ----------------------
* in emacs, eval the expression:
(call-process "bash" "get-functions" "output-buffer")
但是,我在“输出缓冲区”中一无所获。有趣的是,如果我 在真正的 shell 中运行脚本:
$ bash get-functions
我仍然没有任何输出。
这是否意味着我们不能在脚本中使用`declare -F'?
顺便说一句,如果我们从脚本文件中删除“-F”选项,那么我们可以 调用“bash get-functions”时得到输出,但我们得到的不是函数 定义,但是是所有变量。
我的环境:GNU bash,版本 4.1.2(1)-release (i386-redhat-linux-gnu),CentOS 6.3 32bits
【问题讨论】:
-
已经有一个包在shell模式下添加了内置/别名/函数等的完成:github.com/szermatt/emacs-bash-completion。
-
感谢您的信息。