Elisp,alist和字符串;类型混淆 [英] Elisp, alist and strings; type confusion

查看:103
本文介绍了Elisp,alist和字符串;类型混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将组织项目发布为html,并使用以下组织项目定义自动执行任务:

I'm trying to publish an org-project as html, and automate the task with the following org project definition:

(defconst home (file-name-directory (or load-file-name buffer-file-name)))

(require 'org-publish)
(setq org-publish-project-alist
      '(
        ;; add all the components here
        ;; *notes* - publishes org files to html
        ("org-notes"
         :base-directory (concat home "org/")
         :base-extension "org"  ; Filename suffix without dot
         :publishing-directory (concat home "../public_html/")
         :recursive t           ; includes subdirectories
         :publishing-function org-publish-org-to-html
         :headline-levels 4             ; Just the default for this project.
         :auto-preamble t
         :auto-sitemap t                ; generate automagically
         :sitemap-filename "sitemap.org"
         :sitemap-title "Sitemap"
         )

        ;; *static* - copies files to directories
        ("org-static"
         :base-directory (concat home "org/")
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory (concat home "../public_html/")
         :recursive t
         :publishing-function org-publish-attachment
         )

        ;; *publish* with M-x org-publish-project RET emacsclub RET
        ("emacsclub" :components ("org-notes" "org-static"))
        ))

但是,导出项目时出现错误

However, upon exporting the project, I get the error


类型错误的参数:stringp,(concat主页 org)

Wrong type argument: stringp, (concat home "org")

从Elisp的角度来看,到底是怎么回事上? concat的输出不是字符串吗?在这种情况下,为什么会失败?我尝试使用concat参数将 stringp 单独使用,它返回true。

From an Elisp perspective, what the heck is going on? Isn't the output of concat a string? In which case why is this failing? I try stringp on it's own with the concat argument and it returns true.

我要完成的其他事情是,在评估此文件时导出整个项目。我已经尝试过
(命令执行org-publish-all)
之类的东西,但是它也抱怨类型参数错误。我可以用什么来完成这项工作?

Something else I'm trying to get done, is have the whole project exported when this file gets evaluated. I've tried things like (command-execute org-publish-all) but it also complains of a wrong type argument. What can I use to get this done?

推荐答案

问题是引用(setq org-publish-project-alist' (...))表示将不评估该列表结构中的任何内容。换句话说,Emacs告诉您(concat主页 org)的值不是字符串:实际上,它是三个元素的列表(如果进行评估,给你一个字符串)。

The problem is that quoting the second argument in (setq org-publish-project-alist '(...)) means that nothing in that list structure will be evaluated. In other words, Emacs is telling you that the value (concat home "org") isn't a string: in fact it's a list of three elements (which if evaluated would give you a string).

一种可能的解决方法是使用 backquote或 quasiquote机制,就像 quote ',但允许您使用,@ 。 (有关更多详细信息,请参见《信息》手册中的(elisp)Backquote )。因此,您可以将上面的代码更改为

One possible workaround might be to use the "backquote" or "quasiquote" mechanism, which is just like quote or ' but allows you to selectively splice in bits of evaluated Lisp code using , and ,@. (See (elisp)Backquote in the Info manual for more details). So, you could change your code above to something like

(setq org-publish-project-alist
  `(                            ; note ` instead of '
    ("org-notes"
     ;; Note commas , in front of code to evaluate
     :base-directory ,(concat home "org/")
     :base-extension "org"
     :publishing-directory ,(concat home "../public_html/")
     ....

请注意,当(setq ...)的形式被求值:换句话说,如果您需要这些值针对不同的项目目录进行动态更改,这将无济于事,但是由于您正在定义作为常数也许没关系?

Note that the unquoted pieces will get evaluated and spliced in to the list only once, when the (setq ...) form is evaluated: in other words, this won't help you if you need those values to change dynamically for different project directories. But since you're defining home as a constant maybe that doesn't matter?

PS:如果您需要更详细地了解<$ c $的位置, c>错误类型参数错误源于此,请尝试执行 MX错误切换错误或评估(setq错误调试t)以获得详细的追溯。

PS: If you need to figure out in more detail where your wrong-type-argument errors are coming from, try doing M-x toggle-debug-on-error or evaluate (setq debug-on-error t) to get a detailed backtrace.

这篇关于Elisp,alist和字符串;类型混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆