如何指定的Emacs Lisp变量的属性值(how to specify a property va

2019-09-21 01:43发布

我用下面的代码在.emacs文件设置默认发布行为。 我把差价电脑差异位置组织基本目录:

;; define machine specific directories storing my org files
(cond ((system-name-is-home) (setq org-dir "/data/org"))
      ((system-name-is-work) (setq org-dir "~/org")))

因此,我想用一个变量来指定:base-directoryorg-dir而不是硬编码为"~/org" 。 我怎样才能做到这一点?

(require 'org-publish)
(setq org-publish-project-alist
      '(
        ("org-notes"
         :base-directory "~/org"
         :base-extension "org"
         :publishing-directory "~/tmp/"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 4
         :auto-preamble t

         :auto-sitemap t          ; Generate sitemap.org automagically ...
         :sitemap-filename "sitemap.org" ; ... call it sitemap.org (the default) ...
         :sitemap-title "Sitemap" ; ... with title 'Sitemap'.
         )
        ("org-static"
         :base-directory "~/org"
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory "~/tmp/"
         :recursive t
         :publishing-function org-publish-attachment
         )
        ("org" :components ("org-notes" "org-static"))
        ))

Answer 1:

一种方式做到这一点将使用` (反引号)和, (逗号)。 从GNU的Emacs Lisp参考手册 ,

反引号结构允许你引用一个列表,但选择性地评估该列表的元素。 在最简单的情况下,等同于特殊形式quote 。 (...)的特殊标记“将参数反引号内”表示的值不是常数。 , 该的Emacs Lisp评估的评估“的说法, ”,并把该值列表中的结构。

所以,你可以写成如下程序:

(require 'org-publish)
(setq org-publish-project-alist
      `(                              ; XXX: backquote
        ("org-notes"
         :base-directory ,org-dir     ; XXX: comma
         :base-extension "org"
         :publishing-directory "~/tmp/"
         :recursive t
         :publishing-function org-publish-org-to-html
         :headline-levels 4
         :auto-preamble t

         :auto-sitemap t          
         :sitemap-filename "sitemap.org" 
         :sitemap-title "Sitemap"
         )
        ("org-static"
         :base-directory ,org-dir     ; XXX: comma
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory "~/tmp/"
         :recursive t
         :publishing-function org-publish-attachment
         )
        ("org" :components ("org-notes" "org-static"))
        ))


文章来源: how to specify a property value of a variable in emacs lisp