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

时间:2019-02-23 03:25:47

标签: elisp

这是我有史以来第一个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的链接并不是我想要的,但我尚未将其链接到链接部分。我认为带有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))

1 个答案:

答案 0 :(得分: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中查看有关反引号的更多信息。

相关问题