emi*_*ish 3 emacs elisp org-mode
我正在尝试将组织项目发布为html,并使用以下组织项目定义自动执行该任务:
(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"))
))
Run Code Online (Sandbox Code Playgroud)
但是,在导出项目时,我收到错误
错误的类型参数:stringp,(concat home"org")
从Elisp的角度来看,到底发生了什么?concat的输出不是字符串吗?在哪种情况下,为什么会失败?我 stringp 用concat参数尝试它自己,它返回true.
我正在尝试完成的其他事情是在评估此文件时导出整个项目.我尝试过(命令执行org-publish-all)之类的东西,但它也抱怨错误的类型参数.我可以用什么来完成这项工作?
Jon*_* O. 10
问题是引用第二个参数(setq org-publish-project-alist '(...))意味着将评估该列表结构中的任何内容.换句话说,Emacs告诉你这个值(concat home "org")不是一个字符串:实际上它是一个包含三个元素的列表(如果被评估会给你一个字符串).
一种可能的解决方法可能是使用"反引号"或"quasiquote"机制,它就像quote或者'允许您使用,和选择性地拼接评估的Lisp代码,@.(有关(elisp)Backquote详细信息,请参阅信息手册).因此,您可以将上面的代码更改为类似的内容
(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/")
....
Run Code Online (Sandbox Code Playgroud)
请注意,在评估(setq ...)表单时,不会对未引用的部分进行评估并将其拼接到列表中:换句话说,如果您需要为不同的项目目录动态更改这些值,这将无法帮助您.但既然你把它定义home为一个常数也许并不重要?
PS:如果您需要更详细地了解wrong-type-argument错误的来源,请尝试进行M-x toggle-debug-on-error或评估(setq debug-on-error t)以获得详细的回溯.