如何将列表中的成员作为字符串传递给另一个函数?

How to pass member from a list as string to another function?

这是我的第一个 elisp 程序。我正在尝试制作各种仪表板以在 Emacs 启动时显示。我正在关注 elisp 启动页面 startup.el:

中的代码
(defun dashboard ()
  "Display a custom dashboard on startup"
  (let ((dash-buffer (get-buffer-create "*dashboard*")))
    (with-current-buffer dash-buffer
      (let ((inhibit-read-only t))
        (erase-buffer)

        (fancy-splash-insert
         :face 'variable-pitch "Recent Files:"
         :face 'variable-pitch "\n")

        (dolist (recent recentf-list)
          (defconst file-text
            `((:link ((with-output-to-string (princ recent)),
                      (lambda (_button) (browse-url "https://www.gnu.org/software/emacs/"))
                      ))))

          (apply #'fancy-splash-insert (car file-text))
          (insert "\n")))

      (display-buffer dash-buffer))))

我想最终显示最近使用的文件,所以我用 (dolist (recent recentf-list) 遍历列表,所以 recent 理论上包含一个最近使用的文件。然后我想从变量 recent 中创建一个 link。是的,我意识到 link 到 gnu.org 并不是我想要的,但我还没有进入 link 部分。我认为带有 find-file 的东西是我想要的,但我稍后会谈到。无论如何,尽我所能,我唯一能做的就是硬编码字符串:

--有效

`((:link ("foo",

--不起作用

`((:link (recent,

`((:link ((format "%s" recent),

`((:link ((with-output-to-string (princ recent)),

我已经尝试了所有我能想到的方法来让这个东西接受一个变量,但它打败了我……有什么想法吗?

我收到类似于以下内容的错误:

fancy-splash-insert: Wrong type argument: char-or-string-p, (with-output-to-string (princ recent))

您需要使用特殊标记 , 来告诉反引号 recent 不是常量。您也不需要 princwith output to string。这应该有效:

(defun dashboard ()
  "Display a custom dashboard on startup"
  (let ((dash-buffer (get-buffer-create "*dashboard*")))
    (with-current-buffer dash-buffer
      (let ((inhibit-read-only t))
        (erase-buffer)

        (fancy-splash-insert
         :face 'variable-pitch "Recent Files:"
         :face 'variable-pitch "\n")

        (dolist (recent recentf-list)
          (defconst file-text
            `((:link (,recent
                      (lambda (_button) (browse-url "https://www.gnu.org/software/emacs/"))
                      ))))

          (apply #'fancy-splash-insert (car file-text))
          (insert "\n")))

      (display-buffer dash-buffer))))

the documentation 中查看有关反引号的更多信息。