emacs - 从 (Emacs) Lisp 中的字符串名称调用函数

标签 emacs lisp elisp

给定一个由各种串联构建的字符串“my-func-name”,我想调用关联的函数。

由于 funcall 需要一个函数对象作为参数,我想知道是否有办法通过名称检索函数引用,以便我可以执行它。

提示:我目前使用的是 Emacs Lisp 方言。

非常感谢

奖励:示例虚拟代码

(defun my-func-name ()
  "My function."
  (message "Hello"))

(setq mfname "my-func-name")

;; Not working, obviously
;; (funcall mfname)

最佳答案

intern获取那个名字的symbol,然后funcall它:

(funcall (intern "my-func-name"))

关于emacs - 从 (Emacs) Lisp 中的字符串名称调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29213111/

相关文章:

Lisp 函数 : union

linux - Emacs Lisp 中的无效函数

emacs - 为什么我在 native 使用 Google Drive API 时收到 "The authenticated user has not installed the app with client id"错误?

emacs - 仅在主要模式下设置快捷键?

emacs - 有没有人有用于缩进(和取消缩进)文本 block 的 Emacs 宏?

types - Lisp 类型的系统故障

shell - elisp 解析异步 shell 命令的输出

vim - 您会为初学者程序员推荐 vim/emacs 吗?

emacs - 如何在 Emacs 模式行中显示总行数

compiler-construction - 是否有针对不同 "RnRS"方案标准的摘要?