【问题标题】:how to specify a property value of a variable in emacs lisp如何在emacs lisp中指定变量的属性值
【发布时间】:2012-08-09 01:48:08
【问题描述】:

我在 .emacs 文件中使用以下代码来设置默认发布行为。我将 org 基本目录放在不同计算机的不同位置:

;; 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-directory 指定为org-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"))
        ))

【问题讨论】:

    标签: emacs lisp elisp org-mode


    【解决方案1】:

    一种方法是使用`(反引号)和,(逗号)。来自GNU Emacs Lisp Reference Manual

    反引号结构允许您引用列表,但有选择地评估该列表的元素。在最简单的情况下,它与特殊形式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"))
            ))
    

    【讨论】:

    • 无效:org-publish-get-base-files: Wrong type argument: stringp, (\, org-dir)org-publish-get-base-files: Wrong type argument: stringp, (\` org-dir)
    • @RNAer 在执行代码之前,您是否评估了 (cond ...) 代码和 setqs org-dir?我已经检查了代码在设置 org-dir 时是否有效。
    • 是的,当然。我在其他代码行中使用org-dir 没有任何问题。
    • 对不起,我错过了第一次修改。现在它起作用了!非常感谢!
    猜你喜欢
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多