如何在emacs lisp中指定变量的属性值 [英] how to specify a property value of a variable in emacs lisp

查看:132
本文介绍了如何在emacs lisp中指定变量的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  ;;定义存储我的组织文件的机器特定目录
(cond((system-name-is-home)(setq org-dir/ data / org))
((系统名称工作) )(setq org-dir〜/ org)))

因此,我想使用一个变量指定:base-directory to org-dir 而不是硬编码为 〜/组织。如何做到这一点?

 (require'org-publish)
(setq org-publish-project-alist
'(
(org-notes
:base-directory〜/ org
:base-extensionorg
:publishing-directory〜 / tmp /
:recursive t
:publishing-function org-publish-org-to-html
:headline-level 4
:auto-preamble t

:auto-sitemap t;自动生成sitemap.org ...
:sitemap-filenamesitemap.org; ...称它为sitemap.org(默认)...
:sitemap-titleSitemap; ...标题为Sitemap

(org-static
:base-directory〜/ org
:base-extensioncss\\ | js\\ | | png\\ | jpg\\ | gif\\ | pdf\\ || mp3\\ | ogg\ \ | swf
:发布目录〜/ tmp /
:递归t
:pub lucky-function org-publish-attachment

(org:components(org-notesorg-static))
))


解决方案

一种方法是使用`(backquote)和(逗号)。从 GNU Emacs Lisp参考手册


反引号构造允许您引用列表,但有选择地评估该列表的元素。在最简单的情况下,它与特殊形式 quote 相同。 (...)要反向引用的参数内的特殊标记''表示不恒定的值。 Emacs Lisp评估器评估''的参数,并将该值放在列表结构中。


所以你可以按照以下方式编写你的程序:

 (require'org-publish)
(setq org-publish-project-alist
`(; XXX:backquote
(org-notes
:base-directory,org-dir; XXX:逗号
:base-extensionorg
:publishing-directory〜/ tmp /
:recursive t
:publishing-function org-publish-org-to-html
:标题级别4
:自动前导码t

:auto-sitemap t
:sitemap-filenamesitemap.org
:sitemap-titleSitemap

(org-static
:base-directory,org-dir; XXX:逗号
:基本扩展名css\\ | js\\\ \\ | png\\ | jpg\\ | gif\\ | PDF \\ | mp3\\ | ogg\\ | swf
:publishing-directory〜/ tmp /
:递归t
:publishing-function org-发布附件

(org:components(org-notesorg-static))
))
pre>

I use the following code in .emacs file to set default publish behavior. I put the org base directory in difference locations for difference computers:

;; 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")))

Thus I'd like to use a variable to specify :base-directory to org-dir instead of hard-coding it as "~/org". How can I do that?

(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"))
        ))

解决方案

One way to do it will be using ` (backquote) and , (comma). From GNU Emacs Lisp Reference Manual,

Backquote constructs allow you to quote a list, but selectively evaluate elements of that list. In the simplest case, it is identical to the special form quote. (...) The special marker ',' inside of the argument to backquote indicates a value that isn't constant. The Emacs Lisp evaluator evaluates the argument of ',', and puts the value in the list structure.

So you can write your program as follows:

(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"))
        ))

这篇关于如何在emacs lisp中指定变量的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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