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

问题描述 投票:1回答:1

这是我的第一个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中建立一个链接。是的,我意识到gnu.org的链接并不是我想要的,但我还没有进入链接部分。我认为找到文件的东西是我想要的东西,但我稍后会谈到。无论如何,尽我所能,我唯一可以做的就是硬编码的字符串:

- 作品

`((: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))
elisp
1个回答
1
投票

您需要使用特殊标记,来告诉反引号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中反引号的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.