Merge branch 'maint'
[org-mode.git] / lisp / org-publish.el
blob908f3e3da9a963c183eb39a7f1e88c0756d989be
1 ;;; org-publish.el --- publish related org-mode files as a website
2 ;; Copyright (C) 2006-2013 Free Software Foundation, Inc.
4 ;; Author: David O'Toole <dto@gnu.org>
5 ;; Maintainer: Carsten Dominik <carsten DOT dominik AT gmail DOT com>
6 ;; Keywords: hypermedia, outlines, wp
8 ;; This file is part of GNU Emacs.
9 ;;
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This program allow configurable publishing of related sets of
26 ;; Org-mode files as a complete website.
28 ;; org-publish.el can do the following:
30 ;; + Publish all one's org-files to HTML or PDF
31 ;; + Upload HTML, images, attachments and other files to a web server
32 ;; + Exclude selected private pages from publishing
33 ;; + Publish a clickable sitemap of pages
34 ;; + Manage local timestamps for publishing only changed files
35 ;; + Accept plugin functions to extend range of publishable content
37 ;; Documentation for publishing is in the manual.
39 ;;; Code:
42 (eval-when-compile
43 (require 'cl))
44 (require 'org)
45 (require 'org-exp)
46 (require 'format-spec)
48 (eval-and-compile
49 (unless (fboundp 'declare-function)
50 (defmacro declare-function (fn file &optional arglist fileonly))))
52 (defvar org-publish-initial-buffer nil
53 "The buffer `org-publish' has been called from.")
55 (defvar org-publish-temp-files nil
56 "Temporary list of files to be published.")
58 ;; Here, so you find the variable right before it's used the first time:
59 (defvar org-publish-cache nil
60 "This will cache timestamps and titles for files in publishing projects.
61 Blocks could hash sha1 values here.")
63 (defgroup org-publish nil
64 "Options for publishing a set of Org-mode and related files."
65 :tag "Org Publishing"
66 :group 'org)
68 (defcustom org-publish-project-alist nil
69 "Association list to control publishing behavior.
70 Each element of the alist is a publishing 'project.' The CAR of
71 each element is a string, uniquely identifying the project. The
72 CDR of each element is in one of the following forms:
74 1. A well-formed property list with an even number of elements, alternating
75 keys and values, specifying parameters for the publishing process.
77 (:property value :property value ... )
79 2. A meta-project definition, specifying of a list of sub-projects:
81 (:components (\"project-1\" \"project-2\" ...))
83 When the CDR of an element of org-publish-project-alist is in
84 this second form, the elements of the list after :components are
85 taken to be components of the project, which group together files
86 requiring different publishing options. When you publish such a
87 project with \\[org-publish], the components all publish.
89 When a property is given a value in org-publish-project-alist, its
90 setting overrides the value of the corresponding user variable
91 \(if any) during publishing. However, options set within a file
92 override everything.
94 Most properties are optional, but some should always be set:
96 :base-directory Directory containing publishing source files
97 :base-extension Extension (without the dot!) of source files.
98 This can be a regular expression. If not given,
99 \"org\" will be used as default extension.
100 :publishing-directory Directory (possibly remote) where output
101 files will be published
103 The :exclude property may be used to prevent certain files from
104 being published. Its value may be a string or regexp matching
105 file names you don't want to be published.
107 The :include property may be used to include extra files. Its
108 value may be a list of filenames to include. The filenames are
109 considered relative to the base directory.
111 When both :include and :exclude properties are given values, the
112 exclusion step happens first.
114 One special property controls which back-end function to use for
115 publishing files in the project. This can be used to extend the
116 set of file types publishable by org-publish, as well as the set
117 of output formats.
119 :publishing-function Function to publish file. The default is
120 `org-publish-org-to-html', but other
121 values are possible. May also be a
122 list of functions, in which case
123 each function in the list is invoked
124 in turn.
126 Another property allows you to insert code that prepares a
127 project for publishing. For example, you could call GNU Make on a
128 certain makefile, to ensure published files are built up to date.
130 :preparation-function Function to be called before publishing
131 this project. This may also be a list
132 of functions.
133 :completion-function Function to be called after publishing
134 this project. This may also be a list
135 of functions.
137 Some properties control details of the Org publishing process,
138 and are equivalent to the corresponding user variables listed in
139 the right column. See the documentation for those variables to
140 learn more about their use and default values.
142 :language `org-export-default-language'
143 :headline-levels `org-export-headline-levels'
144 :section-numbers `org-export-with-section-numbers'
145 :table-of-contents `org-export-with-toc'
146 :emphasize `org-export-with-emphasize'
147 :sub-superscript `org-export-with-sub-superscripts'
148 :TeX-macros `org-export-with-TeX-macros'
149 :fixed-width `org-export-with-fixed-width'
150 :tables `org-export-with-tables'
151 :table-auto-headline `org-export-highlight-first-table-line'
152 :style `org-export-html-style'
153 :convert-org-links `org-export-html-link-org-files-as-html'
154 :html-inline-images `org-export-html-inline-images'
155 :latex-inline-images `org-export-latex-inline-images'
156 :odt-inline-images `org-export-odt-inline-images'
157 :docbook-inline-images `org-export-docbook-inline-images'
158 :expand-quoted-html `org-export-html-expand'
159 :timestamp `org-export-html-with-timestamp'
160 :publishing-directory `org-export-publishing-directory'
161 :html-preamble `org-export-html-preamble'
162 :html-postamble `org-export-html-postamble'
163 :author `user-full-name'
164 :email `user-mail-address'
166 The following properties may be used to control publishing of a
167 sitemap of files or summary page for a given project.
169 :auto-sitemap Whether to publish a sitemap during
170 `org-publish-current-project' or `org-publish-all'.
171 :sitemap-filename Filename for output of sitemap. Defaults
172 to 'sitemap.org' (which becomes 'sitemap.html').
173 :sitemap-title Title of sitemap page. Defaults to name of file.
174 :sitemap-function Plugin function to use for generation of sitemap.
175 Defaults to `org-publish-org-sitemap', which
176 generates a plain list of links to all files
177 in the project.
178 :sitemap-style Can be `list' (sitemap is just an itemized list
179 of the titles of the files involved) or
180 `tree' (the directory structure of the source
181 files is reflected in the sitemap). Defaults to
182 `tree'.
183 :sitemap-sans-extension Remove extension from sitemap's
184 filenames. Useful to have cool
185 URIs (see
186 http://www.w3.org/Provider/Style/URI).
187 Defaults to nil.
189 If you create a sitemap file, adjust the sorting like this:
191 :sitemap-sort-folders Where folders should appear in the sitemap.
192 Set this to `first' (default) or `last' to
193 display folders first or last, respectively.
194 Any other value will mix files and folders.
195 :sitemap-sort-files The site map is normally sorted alphabetically.
196 You can change this behaviour setting this to
197 `chronologically', `anti-chronologically' or nil.
198 :sitemap-ignore-case Should sorting be case-sensitive? Default nil.
200 The following properties control the creation of a concept index.
202 :makeindex Create a concept index.
204 Other properties affecting publication.
206 :body-only Set this to 't' to publish only the body of the
207 documents, excluding everything outside and
208 including the <body> tags in HTML, or
209 \begin{document}..\end{document} in LaTeX."
210 :group 'org-publish
211 :type 'alist)
213 (defcustom org-publish-use-timestamps-flag t
214 "Non-nil means use timestamp checking to publish only changed files.
215 When nil, do no timestamp checking and always publish all files."
216 :group 'org-publish
217 :type 'boolean)
219 (defcustom org-publish-timestamp-directory (convert-standard-filename
220 "~/.org-timestamps/")
221 "Name of directory in which to store publishing timestamps."
222 :group 'org-publish
223 :type 'directory)
225 (defcustom org-publish-list-skipped-files t
226 "Non-nil means show message about files *not* published."
227 :group 'org-publish
228 :type 'boolean)
230 (defcustom org-publish-before-export-hook nil
231 "Hook run before export on the Org file.
232 The hook may modify the file in arbitrary ways before publishing happens.
233 The original version of the buffer will be restored after publishing."
234 :group 'org-publish
235 :type 'hook)
237 (defcustom org-publish-after-export-hook nil
238 "Hook run after export on the exported buffer.
239 Any changes made by this hook will be saved."
240 :group 'org-publish
241 :type 'hook)
243 (defcustom org-publish-sitemap-sort-files 'alphabetically
244 "How sitemaps files should be sorted by default?
245 Possible values are `alphabetically', `chronologically', `anti-chronologically' and nil.
246 If `alphabetically', files will be sorted alphabetically.
247 If `chronologically', files will be sorted with older modification time first.
248 If `anti-chronologically', files will be sorted with newer modification time first.
249 nil won't sort files.
251 You can overwrite this default per project in your
252 `org-publish-project-alist', using `:sitemap-sort-files'."
253 :group 'org-publish
254 :version "24.1"
255 :type 'symbol)
257 (defcustom org-publish-sitemap-sort-folders 'first
258 "A symbol, denoting if folders are sorted first in sitemaps.
259 Possible values are `first', `last', and nil.
260 If `first', folders will be sorted before files.
261 If `last', folders are sorted to the end after the files.
262 Any other value will not mix files and folders.
264 You can overwrite this default per project in your
265 `org-publish-project-alist', using `:sitemap-sort-folders'."
266 :group 'org-publish
267 :version "24.1"
268 :type 'symbol)
270 (defcustom org-publish-sitemap-sort-ignore-case nil
271 "Sort sitemaps case insensitively by default?
273 You can overwrite this default per project in your
274 `org-publish-project-alist', using `:sitemap-ignore-case'."
275 :group 'org-publish
276 :version "24.1"
277 :type 'boolean)
279 (defcustom org-publish-sitemap-date-format "%Y-%m-%d"
280 "Format for `format-time-string' which is used to print a date
281 in the sitemap."
282 :group 'org-publish
283 :version "24.1"
284 :type 'string)
286 (defcustom org-publish-sitemap-file-entry-format "%t"
287 "How a sitemap file entry is formatted.
288 You could use brackets to delimit on what part the link will be.
290 %t is the title.
291 %a is the author.
292 %d is the date formatted using `org-publish-sitemap-date-format'."
293 :group 'org-publish
294 :version "24.1"
295 :type 'string)
298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
299 ;;; Sanitize-plist (FIXME why?)
301 (defun org-publish-sanitize-plist (plist)
302 ;; FIXME document
303 (mapcar (lambda (x)
304 (or (cdr (assq x '((:index-filename . :sitemap-filename)
305 (:index-title . :sitemap-title)
306 (:index-function . :sitemap-function)
307 (:index-style . :sitemap-style)
308 (:auto-index . :auto-sitemap))))
310 plist))
312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
313 ;;; Timestamp-related functions
315 (defun org-publish-timestamp-filename (filename &optional pub-dir pub-func)
316 "Return path to timestamp file for filename FILENAME."
317 (setq filename (concat filename "::" (or pub-dir "") "::"
318 (format "%s" (or pub-func ""))))
319 (concat "X" (if (fboundp 'sha1) (sha1 filename) (md5 filename))))
321 (defun org-publish-needed-p (filename &optional pub-dir pub-func true-pub-dir base-dir)
322 "Return t if FILENAME should be published in PUB-DIR using PUB-FUNC.
323 TRUE-PUB-DIR is where the file will truly end up. Currently we are not using
324 this - maybe it can eventually be used to check if the file is present at
325 the target location, and how old it is. Right now we cannot do this, because
326 we do not know under what file name the file will be stored - the publishing
327 function can still decide about that independently."
328 (let ((rtn
329 (if org-publish-use-timestamps-flag
330 (org-publish-cache-file-needs-publishing
331 filename pub-dir pub-func base-dir)
332 ;; don't use timestamps, always return t
333 t)))
334 (if rtn
335 (message "Publishing file %s using `%s'" filename pub-func)
336 (when org-publish-list-skipped-files
337 (message "Skipping unmodified file %s" filename)))
338 rtn))
340 (defun org-publish-update-timestamp (filename &optional pub-dir pub-func base-dir)
341 "Update publishing timestamp for file FILENAME.
342 If there is no timestamp, create one."
343 (let ((key (org-publish-timestamp-filename filename pub-dir pub-func))
344 (stamp (org-publish-cache-ctime-of-src filename)))
345 (org-publish-cache-set key stamp)))
347 (defun org-publish-remove-all-timestamps ()
348 "Remove all files in the timestamp directory."
349 (let ((dir org-publish-timestamp-directory)
350 files)
351 (when (and (file-exists-p dir)
352 (file-directory-p dir))
353 (mapc 'delete-file (directory-files dir 'full "[^.]\\'"))
354 (org-publish-reset-cache))))
357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
358 ;;; Compatibility aliases
360 ;; Delete-dups is not in Emacs <22
361 (if (fboundp 'delete-dups)
362 (defalias 'org-publish-delete-dups 'delete-dups)
363 (defun org-publish-delete-dups (list)
364 "Destructively remove `equal' duplicates from LIST.
365 Store the result in LIST and return it. LIST must be a proper list.
366 Of several `equal' occurrences of an element in LIST, the first
367 one is kept.
369 This is a compatibility function for Emacsen without `delete-dups'."
370 ;; Code from `subr.el' in Emacs 22:
371 (let ((tail list))
372 (while tail
373 (setcdr tail (delete (car tail) (cdr tail)))
374 (setq tail (cdr tail))))
375 list))
377 (declare-function org-publish-delete-dups "org-publish" (list))
378 (declare-function find-lisp-find-files "find-lisp" (directory regexp))
379 (declare-function org-pop-to-buffer-same-window
380 "org-compat" (&optional buffer-or-name norecord label))
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 ;;; Getting project information out of org-publish-project-alist
385 (defun org-publish-expand-projects (projects-alist)
386 "Expand projects in PROJECTS-ALIST.
387 This splices all the components into the list."
388 (let ((rest projects-alist) rtn p components)
389 (while (setq p (pop rest))
390 (if (setq components (plist-get (cdr p) :components))
391 (setq rest (append
392 (mapcar (lambda (x) (assoc x org-publish-project-alist))
393 components)
394 rest))
395 (push p rtn)))
396 (nreverse (org-publish-delete-dups (delq nil rtn)))))
398 (defvar org-sitemap-sort-files)
399 (defvar org-sitemap-sort-folders)
400 (defvar org-sitemap-ignore-case)
401 (defvar org-sitemap-requested)
402 (defvar org-sitemap-date-format)
403 (defvar org-sitemap-file-entry-format)
404 (defun org-publish-compare-directory-files (a b)
405 "Predicate for `sort', that sorts folders and files for sitemap."
406 (let ((retval t))
407 (when (or org-sitemap-sort-files org-sitemap-sort-folders)
408 ;; First we sort files:
409 (when org-sitemap-sort-files
410 (cond ((equal org-sitemap-sort-files 'alphabetically)
411 (let* ((adir (file-directory-p a))
412 (aorg (and (string-match "\\.org$" a) (not adir)))
413 (bdir (file-directory-p b))
414 (borg (and (string-match "\\.org$" b) (not bdir)))
415 (A (if aorg
416 (concat (file-name-directory a)
417 (org-publish-find-title a)) a))
418 (B (if borg
419 (concat (file-name-directory b)
420 (org-publish-find-title b)) b)))
421 (setq retval (if org-sitemap-ignore-case
422 (not (string-lessp (upcase B) (upcase A)))
423 (not (string-lessp B A))))))
424 ((or (equal org-sitemap-sort-files 'chronologically)
425 (equal org-sitemap-sort-files 'anti-chronologically))
426 (let* ((adate (org-publish-find-date a))
427 (bdate (org-publish-find-date b))
428 (A (+ (lsh (car adate) 16) (cadr adate)))
429 (B (+ (lsh (car bdate) 16) (cadr bdate))))
430 (setq retval (if (equal org-sitemap-sort-files 'chronologically)
431 (<= A B)
432 (>= A B)))))))
433 ;; Directory-wise wins:
434 (when org-sitemap-sort-folders
435 ;; a is directory, b not:
436 (cond
437 ((and (file-directory-p a) (not (file-directory-p b)))
438 (setq retval (equal org-sitemap-sort-folders 'first)))
439 ;; a is not a directory, but b is:
440 ((and (not (file-directory-p a)) (file-directory-p b))
441 (setq retval (equal org-sitemap-sort-folders 'last))))))
442 retval))
444 (defun org-publish-get-base-files-1 (base-dir &optional recurse match skip-file skip-dir)
445 "Set `org-publish-temp-files' with files from BASE-DIR directory.
446 If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is
447 non-nil, restrict this list to the files matching the regexp
448 MATCH. If SKIP-FILE is non-nil, skip file matching the regexp
449 SKIP-FILE. If SKIP-DIR is non-nil, don't check directories
450 matching the regexp SKIP-DIR when recursing through BASE-DIR."
451 (mapc (lambda (f)
452 (let ((fd-p (file-directory-p f))
453 (fnd (file-name-nondirectory f)))
454 (if (and fd-p recurse
455 (not (string-match "^\\.+$" fnd))
456 (if skip-dir (not (string-match skip-dir fnd)) t))
457 (org-publish-get-base-files-1 f recurse match skip-file skip-dir)
458 (unless (or fd-p ;; this is a directory
459 (and skip-file (string-match skip-file fnd))
460 (not (file-exists-p (file-truename f)))
461 (not (string-match match fnd)))
463 (pushnew f org-publish-temp-files)))))
464 (if org-sitemap-requested
465 (sort (directory-files base-dir t (unless recurse match))
466 'org-publish-compare-directory-files)
467 (directory-files base-dir t (unless recurse match)))))
469 (defun org-publish-get-base-files (project &optional exclude-regexp)
470 "Return a list of all files in PROJECT.
471 If EXCLUDE-REGEXP is set, this will be used to filter out
472 matching filenames."
473 (let* ((project-plist (cdr project))
474 (base-dir (file-name-as-directory
475 (plist-get project-plist :base-directory)))
476 (include-list (plist-get project-plist :include))
477 (recurse (plist-get project-plist :recursive))
478 (extension (or (plist-get project-plist :base-extension) "org"))
479 ;; sitemap-... variables are dynamically scoped for
480 ;; org-publish-compare-directory-files:
481 (org-sitemap-requested
482 (plist-get project-plist :auto-sitemap))
483 (sitemap-filename
484 (or (plist-get project-plist :sitemap-filename)
485 "sitemap.org"))
486 (org-sitemap-sort-folders
487 (if (plist-member project-plist :sitemap-sort-folders)
488 (plist-get project-plist :sitemap-sort-folders)
489 org-publish-sitemap-sort-folders))
490 (org-sitemap-sort-files
491 (cond ((plist-member project-plist :sitemap-sort-files)
492 (plist-get project-plist :sitemap-sort-files))
493 ;; For backward compatibility:
494 ((plist-member project-plist :sitemap-alphabetically)
495 (if (plist-get project-plist :sitemap-alphabetically)
496 'alphabetically nil))
497 (t org-publish-sitemap-sort-files)))
498 (org-sitemap-ignore-case
499 (if (plist-member project-plist :sitemap-ignore-case)
500 (plist-get project-plist :sitemap-ignore-case)
501 org-publish-sitemap-sort-ignore-case))
502 (match (if (eq extension 'any)
503 "^[^\\.]"
504 (concat "^[^\\.].*\\.\\(" extension "\\)$"))))
505 ;; Make sure `org-sitemap-sort-folders' has an accepted value
506 (unless (memq org-sitemap-sort-folders '(first last))
507 (setq org-sitemap-sort-folders nil))
509 (setq org-publish-temp-files nil)
510 (if org-sitemap-requested
511 (pushnew (expand-file-name (concat base-dir sitemap-filename))
512 org-publish-temp-files))
513 (org-publish-get-base-files-1 base-dir recurse match
514 ;; FIXME distinguish exclude regexp
515 ;; for skip-file and skip-dir?
516 exclude-regexp exclude-regexp)
517 (mapc (lambda (f)
518 (pushnew
519 (expand-file-name (concat base-dir f))
520 org-publish-temp-files))
521 include-list)
522 org-publish-temp-files))
524 (defun org-publish-get-project-from-filename (filename &optional up)
525 "Return the project that FILENAME belongs to."
526 (let* ((filename (expand-file-name filename))
527 project-name)
529 (catch 'p-found
530 (dolist (prj org-publish-project-alist)
531 (unless (plist-get (cdr prj) :components)
532 ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
533 (let* ((r (plist-get (cdr prj) :recursive))
534 (b (expand-file-name (file-name-as-directory
535 (plist-get (cdr prj) :base-directory))))
536 (x (or (plist-get (cdr prj) :base-extension) "org"))
537 (e (plist-get (cdr prj) :exclude))
538 (i (plist-get (cdr prj) :include))
539 (xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
540 (when
542 (and
543 i (member filename
544 (mapcar
545 (lambda (file) (expand-file-name file b))
546 i)))
547 (and
548 (not (and e (string-match e filename)))
549 (string-match xm filename)))
550 (setq project-name (car prj))
551 (throw 'p-found project-name))))))
552 (when up
553 (dolist (prj org-publish-project-alist)
554 (if (member project-name (plist-get (cdr prj) :components))
555 (setq project-name (car prj)))))
556 (assoc project-name org-publish-project-alist)))
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 ;;; Pluggable publishing back-end functions
561 (defun org-publish-org-to (format plist filename pub-dir)
562 "Publish an org file to FORMAT.
563 PLIST is the property list for the given project.
564 FILENAME is the filename of the org file to be published.
565 PUB-DIR is the publishing directory."
566 (require 'org)
567 (unless (file-exists-p pub-dir)
568 (make-directory pub-dir t))
569 (let ((visiting (find-buffer-visiting filename)))
570 (save-excursion
571 (org-pop-to-buffer-same-window (or visiting (find-file filename)))
572 (let* ((plist (cons :buffer-will-be-killed (cons t plist)))
573 (init-buf (current-buffer))
574 (init-point (point))
575 (init-buf-string (buffer-string))
576 export-buf-or-file)
577 ;; run hooks before exporting
578 (run-hooks 'org-publish-before-export-hook)
579 ;; export the possibly modified buffer
580 (setq export-buf-or-file
581 (funcall (intern (concat "org-export-as-" format))
582 (plist-get plist :headline-levels)
583 plist nil
584 (plist-get plist :body-only)
585 pub-dir))
586 (when (and (bufferp export-buf-or-file)
587 (buffer-live-p export-buf-or-file))
588 (set-buffer export-buf-or-file)
589 ;; run hooks after export and save export
590 (progn (run-hooks 'org-publish-after-export-hook)
591 (if (buffer-modified-p) (save-buffer)))
592 (kill-buffer export-buf-or-file))
593 ;; maybe restore buffer's content
594 (set-buffer init-buf)
595 (when (buffer-modified-p init-buf)
596 (erase-buffer)
597 (insert init-buf-string)
598 (save-buffer)
599 (goto-char init-point))
600 (unless visiting
601 (kill-buffer init-buf))))))
603 (defmacro org-publish-with-aux-preprocess-maybe (&rest body)
604 "Execute BODY with a modified hook to preprocess for index."
605 `(let ((org-export-preprocess-after-headline-targets-hook
606 (if (plist-get project-plist :makeindex)
607 (cons 'org-publish-aux-preprocess
608 org-export-preprocess-after-headline-targets-hook)
609 org-export-preprocess-after-headline-targets-hook)))
610 ,@body))
611 (def-edebug-spec org-publish-with-aux-preprocess-maybe (body))
613 (defvar project-plist)
614 (defun org-publish-org-to-latex (plist filename pub-dir)
615 "Publish an org file to LaTeX.
616 See `org-publish-org-to' to the list of arguments."
617 (org-publish-with-aux-preprocess-maybe
618 (org-publish-org-to "latex" plist filename pub-dir)))
620 (defun org-publish-org-to-pdf (plist filename pub-dir)
621 "Publish an org file to PDF (via LaTeX).
622 See `org-publish-org-to' to the list of arguments."
623 (org-publish-with-aux-preprocess-maybe
624 (org-publish-org-to "pdf" plist filename pub-dir)))
626 (defun org-publish-org-to-html (plist filename pub-dir)
627 "Publish an org file to HTML.
628 See `org-publish-org-to' to the list of arguments."
629 (org-publish-with-aux-preprocess-maybe
630 (org-publish-org-to "html" plist filename pub-dir)))
632 (defun org-publish-org-to-org (plist filename pub-dir)
633 "Publish an org file to HTML.
634 See `org-publish-org-to' to the list of arguments."
635 (org-publish-org-to "org" plist filename pub-dir))
637 (defun org-publish-org-to-ascii (plist filename pub-dir)
638 "Publish an org file to ASCII.
639 See `org-publish-org-to' to the list of arguments."
640 (org-publish-with-aux-preprocess-maybe
641 (org-publish-org-to "ascii" plist filename pub-dir)))
643 (defun org-publish-org-to-latin1 (plist filename pub-dir)
644 "Publish an org file to Latin-1.
645 See `org-publish-org-to' to the list of arguments."
646 (org-publish-with-aux-preprocess-maybe
647 (org-publish-org-to "latin1" plist filename pub-dir)))
649 (defun org-publish-org-to-utf8 (plist filename pub-dir)
650 "Publish an org file to UTF-8.
651 See `org-publish-org-to' to the list of arguments."
652 (org-publish-with-aux-preprocess-maybe
653 (org-publish-org-to "utf8" plist filename pub-dir)))
655 (defun org-publish-org-to-taskjuggler (plist filename pub-dir)
656 "Publish an org file to TaskJuggler.
657 See `org-publish-org-to' to the list of arguments."
658 (org-publish-with-aux-preprocess-maybe
659 (org-publish-org-to "taskjuggler" plist filename pub-dir)))
661 (defun org-publish-attachment (plist filename pub-dir)
662 "Publish a file with no transformation of any kind.
663 See `org-publish-org-to' to the list of arguments."
664 ;; make sure eshell/cp code is loaded
665 (unless (file-directory-p pub-dir)
666 (make-directory pub-dir t))
667 (or (equal (expand-file-name (file-name-directory filename))
668 (file-name-as-directory (expand-file-name pub-dir)))
669 (copy-file filename
670 (expand-file-name (file-name-nondirectory filename) pub-dir)
671 t)))
673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
674 ;;; Publishing files, sets of files, and indices
676 (defun org-publish-file (filename &optional project no-cache)
677 "Publish file FILENAME from PROJECT.
678 If NO-CACHE is not nil, do not initialize org-publish-cache and
679 write it to disk. This is needed, since this function is used to
680 publish single files, when entire projects are published.
681 See `org-publish-projects'."
682 (let* ((project
683 (or project
684 (or (org-publish-get-project-from-filename filename)
685 (error "File %s not part of any known project"
686 (abbreviate-file-name filename)))))
687 (project-plist (cdr project))
688 (ftname (expand-file-name filename))
689 (publishing-function
690 (or (plist-get project-plist :publishing-function)
691 'org-publish-org-to-html))
692 (base-dir
693 (file-name-as-directory
694 (expand-file-name
695 (or (plist-get project-plist :base-directory)
696 (error "Project %s does not have :base-directory defined"
697 (car project))))))
698 (pub-dir
699 (file-name-as-directory
700 (file-truename
701 (or (eval (plist-get project-plist :publishing-directory))
702 (error "Project %s does not have :publishing-directory defined"
703 (car project))))))
704 tmp-pub-dir)
706 (unless no-cache
707 (org-publish-initialize-cache (car project)))
709 (setq tmp-pub-dir
710 (file-name-directory
711 (concat pub-dir
712 (and (string-match (regexp-quote base-dir) ftname)
713 (substring ftname (match-end 0))))))
714 (if (listp publishing-function)
715 ;; allow chain of publishing functions
716 (mapc (lambda (f)
717 (when (org-publish-needed-p filename pub-dir f tmp-pub-dir base-dir)
718 (funcall f project-plist filename tmp-pub-dir)
719 (org-publish-update-timestamp filename pub-dir f base-dir)))
720 publishing-function)
721 (when (org-publish-needed-p filename pub-dir publishing-function tmp-pub-dir base-dir)
722 (funcall publishing-function project-plist filename tmp-pub-dir)
723 (org-publish-update-timestamp
724 filename pub-dir publishing-function base-dir)))
725 (unless no-cache (org-publish-write-cache-file))))
727 (defun org-publish-projects (projects)
728 "Publish all files belonging to the PROJECTS alist.
729 If :auto-sitemap is set, publish the sitemap too.
730 If :makeindex is set, also produce a file theindex.org."
731 (mapc
732 (lambda (project)
733 ;; Each project uses its own cache file:
734 (org-publish-initialize-cache (car project))
735 (let*
736 ((project-plist (cdr project))
737 (exclude-regexp (plist-get project-plist :exclude))
738 (sitemap-p (plist-get project-plist :auto-sitemap))
739 (sitemap-filename (or (plist-get project-plist :sitemap-filename)
740 "sitemap.org"))
741 (sitemap-function (or (plist-get project-plist :sitemap-function)
742 'org-publish-org-sitemap))
743 (org-sitemap-date-format (or (plist-get project-plist :sitemap-date-format)
744 org-publish-sitemap-date-format))
745 (org-sitemap-file-entry-format (or (plist-get project-plist :sitemap-file-entry-format)
746 org-publish-sitemap-file-entry-format))
747 (preparation-function (plist-get project-plist :preparation-function))
748 (completion-function (plist-get project-plist :completion-function))
749 (files (org-publish-get-base-files project exclude-regexp)) file)
750 (when preparation-function (run-hooks 'preparation-function))
751 (if sitemap-p (funcall sitemap-function project sitemap-filename))
752 (while (setq file (pop files))
753 (org-publish-file file project t))
754 (when (plist-get project-plist :makeindex)
755 (org-publish-index-generate-theindex
756 (plist-get project-plist :base-directory))
757 (org-publish-file (expand-file-name
758 "theindex.org"
759 (plist-get project-plist :base-directory))
760 project t))
761 (when completion-function (run-hooks 'completion-function))
762 (org-publish-write-cache-file)))
763 (org-publish-expand-projects projects)))
765 (defun org-publish-org-sitemap (project &optional sitemap-filename)
766 "Create a sitemap of pages in set defined by PROJECT.
767 Optionally set the filename of the sitemap with SITEMAP-FILENAME.
768 Default for SITEMAP-FILENAME is 'sitemap.org'."
769 (let* ((project-plist (cdr project))
770 (dir (file-name-as-directory
771 (plist-get project-plist :base-directory)))
772 (localdir (file-name-directory dir))
773 (indent-str (make-string 2 ?\ ))
774 (exclude-regexp (plist-get project-plist :exclude))
775 (files (nreverse (org-publish-get-base-files project exclude-regexp)))
776 (sitemap-filename (concat dir (or sitemap-filename "sitemap.org")))
777 (sitemap-title (or (plist-get project-plist :sitemap-title)
778 (concat "Sitemap for project " (car project))))
779 (sitemap-style (or (plist-get project-plist :sitemap-style)
780 'tree))
781 (sitemap-sans-extension (plist-get project-plist :sitemap-sans-extension))
782 (visiting (find-buffer-visiting sitemap-filename))
783 (ifn (file-name-nondirectory sitemap-filename))
784 file sitemap-buffer)
785 (with-current-buffer (setq sitemap-buffer
786 (or visiting (find-file sitemap-filename)))
787 (erase-buffer)
788 (insert (concat "#+TITLE: " sitemap-title "\n\n"))
789 (while (setq file (pop files))
790 (let ((fn (file-name-nondirectory file))
791 (link (file-relative-name file dir))
792 (oldlocal localdir))
793 (when sitemap-sans-extension
794 (setq link (file-name-sans-extension link)))
795 ;; sitemap shouldn't list itself
796 (unless (equal (file-truename sitemap-filename)
797 (file-truename file))
798 (if (eq sitemap-style 'list)
799 (message "Generating list-style sitemap for %s" sitemap-title)
800 (message "Generating tree-style sitemap for %s" sitemap-title)
801 (setq localdir (concat (file-name-as-directory dir)
802 (file-name-directory link)))
803 (unless (string= localdir oldlocal)
804 (if (string= localdir dir)
805 (setq indent-str (make-string 2 ?\ ))
806 (let ((subdirs
807 (split-string
808 (directory-file-name
809 (file-name-directory
810 (file-relative-name localdir dir))) "/"))
811 (subdir "")
812 (old-subdirs (split-string
813 (file-relative-name oldlocal dir) "/")))
814 (setq indent-str (make-string 2 ?\ ))
815 (while (string= (car old-subdirs) (car subdirs))
816 (setq indent-str (concat indent-str (make-string 2 ?\ )))
817 (pop old-subdirs)
818 (pop subdirs))
819 (dolist (d subdirs)
820 (setq subdir (concat subdir d "/"))
821 (insert (concat indent-str " + " d "\n"))
822 (setq indent-str (make-string
823 (+ (length indent-str) 2) ?\ )))))))
824 ;; This is common to 'flat and 'tree
825 (let ((entry
826 (org-publish-format-file-entry org-sitemap-file-entry-format
827 file project-plist))
828 (regexp "\\(.*\\)\\[\\([^][]+\\)\\]\\(.*\\)"))
829 (cond ((string-match-p regexp entry)
830 (string-match regexp entry)
831 (insert (concat indent-str " + " (match-string 1 entry)
832 "[[file:" link "]["
833 (match-string 2 entry)
834 "]]" (match-string 3 entry) "\n")))
836 (insert (concat indent-str " + [[file:" link "]["
837 entry
838 "]]\n"))))))))
839 (save-buffer))
840 (or visiting (kill-buffer sitemap-buffer))))
842 (defun org-publish-format-file-entry (fmt file project-plist)
843 (format-spec fmt
844 `((?t . ,(org-publish-find-title file t))
845 (?d . ,(format-time-string org-sitemap-date-format
846 (org-publish-find-date file)))
847 (?a . ,(or (plist-get project-plist :author) user-full-name)))))
849 (defun org-publish-find-title (file &optional reset)
850 "Find the title of FILE in project."
852 (and (not reset) (org-publish-cache-get-file-property file :title nil t))
853 (let* ((visiting (find-buffer-visiting file))
854 (buffer (or visiting (find-file-noselect file)))
855 title)
856 (with-current-buffer buffer
857 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
858 (org-infile-export-plist))))
859 (setq title
860 (or (plist-get opt-plist :title)
861 (and (not
862 (plist-get opt-plist :skip-before-1st-heading))
863 (org-export-grab-title-from-buffer))
864 (file-name-nondirectory (file-name-sans-extension file))))))
865 (unless visiting
866 (kill-buffer buffer))
867 (org-publish-cache-set-file-property file :title title)
868 title)))
870 (defun org-publish-find-date (file)
871 "Find the date of FILE in project.
872 If FILE provides a #+date keyword use it else use the file
873 system's modification time.
875 It returns time in `current-time' format."
876 (let ((visiting (find-buffer-visiting file)))
877 (save-excursion
878 (org-pop-to-buffer-same-window (or visiting (find-file-noselect file nil t)))
879 (let* ((plist (org-infile-export-plist))
880 (date (plist-get plist :date)))
881 (unless visiting
882 (kill-buffer (current-buffer)))
883 (if date
884 (org-time-string-to-time date)
885 (when (file-exists-p file)
886 (nth 5 (file-attributes file))))))))
888 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
889 ;;; Interactive publishing functions
891 ;;;###autoload
892 (defalias 'org-publish-project 'org-publish)
894 ;;;###autoload
895 (defun org-publish (project &optional force)
896 "Publish PROJECT."
897 (interactive
898 (list
899 (assoc (org-icompleting-read
900 "Publish project: "
901 org-publish-project-alist nil t)
902 org-publish-project-alist)
903 current-prefix-arg))
904 (setq org-publish-initial-buffer (current-buffer))
905 (save-window-excursion
906 (let* ((org-publish-use-timestamps-flag
907 (if force nil org-publish-use-timestamps-flag)))
908 (org-publish-projects
909 (if (stringp project)
910 ;; If this function is called in batch mode,
911 ;; project is still a string here.
912 (list (assoc project org-publish-project-alist))
913 (list project))))))
915 ;;;###autoload
916 (defun org-publish-all (&optional force)
917 "Publish all projects.
918 With prefix argument, remove all files in the timestamp
919 directory and force publishing all files."
920 (interactive "P")
921 (when force
922 (org-publish-remove-all-timestamps))
923 (save-window-excursion
924 (let ((org-publish-use-timestamps-flag
925 (if force nil org-publish-use-timestamps-flag)))
926 (org-publish-projects org-publish-project-alist))))
928 ;;;###autoload
929 (defun org-publish-current-file (&optional force)
930 "Publish the current file.
931 With prefix argument, force publish the file."
932 (interactive "P")
933 (save-window-excursion
934 (let ((org-publish-use-timestamps-flag
935 (if force nil org-publish-use-timestamps-flag)))
936 (org-publish-file (buffer-file-name)))))
938 ;;;###autoload
939 (defun org-publish-current-project (&optional force)
940 "Publish the project associated with the current file.
941 With a prefix argument, force publishing of all files in
942 the project."
943 (interactive "P")
944 (save-window-excursion
945 (let ((project (org-publish-get-project-from-filename (buffer-file-name) 'up))
946 (org-publish-use-timestamps-flag
947 (if force nil org-publish-use-timestamps-flag)))
948 (if (not project)
949 (error "File %s is not part of any known project" (buffer-file-name)))
950 ;; FIXME: force is not used here?
951 (org-publish project))))
954 ;;; Index generation
956 (defun org-publish-aux-preprocess ()
957 "Find index entries and write them to an .orgx file."
958 (let ((case-fold-search t)
959 entry index target)
960 (goto-char (point-min))
961 (while
962 (and
963 (re-search-forward "^[ \t]*#\\+index:[ \t]*\\(.*?\\)[ \t]*$" nil t)
964 (> (match-end 1) (match-beginning 1)))
965 (setq entry (match-string 1))
966 (when (eq org-export-current-backend 'latex)
967 (replace-match (format "\\index{%s}" entry) t t))
968 (save-excursion
969 (ignore-errors (org-back-to-heading t))
970 (setq target (get-text-property (point) 'target))
971 (setq target (or (cdr (assoc target org-export-preferred-target-alist))
972 (cdr (assoc target org-export-id-target-alist))
973 target ""))
974 (push (cons entry target) index)))
975 (with-temp-file
976 (concat
977 (file-name-directory org-current-export-file) "."
978 (file-name-sans-extension
979 (file-name-nondirectory org-current-export-file)) ".orgx")
980 (dolist (entry (nreverse index))
981 (insert (format "INDEX: (%s) %s\n" (cdr entry) (car entry)))))))
983 (defun org-publish-index-generate-theindex (directory)
984 "Generate the index from all .orgx files in DIRECTORY."
985 (require 'find-lisp)
986 (let* ((fulldir (file-name-as-directory
987 (expand-file-name directory)))
988 (full-files (find-lisp-find-files directory "\\.orgx\\'"))
989 (re (concat "\\`" fulldir))
990 (files (mapcar (lambda (f) (if (string-match re f)
991 (substring f (match-end 0))
993 full-files))
994 (default-directory directory)
995 index origfile buf target entry ibuffer
996 main last-main letter last-letter file sub link tgext)
997 ;; `files' contains the list of relative file names
998 (dolist (file files)
999 (setq origfile
1000 (concat (file-name-directory file)
1001 (substring (file-name-nondirectory file) 1 -1)))
1002 (setq buf (find-file-noselect file))
1003 (with-current-buffer buf
1004 (goto-char (point-min))
1005 (while (re-search-forward "^INDEX: (\\(.*?\\)) \\(.*\\)" nil t)
1006 (setq target (match-string 1)
1007 entry (match-string 2))
1008 (push (list entry origfile target) index)))
1009 (kill-buffer buf))
1010 (setq index (sort index (lambda (a b) (string< (downcase (car a))
1011 (downcase (car b))))))
1012 (setq ibuffer (find-file-noselect (expand-file-name "theindex.inc" directory)))
1013 (with-current-buffer ibuffer
1014 (erase-buffer)
1015 (insert "* Index\n")
1016 (setq last-letter nil)
1017 (dolist (idx index)
1018 (setq entry (car idx) file (nth 1 idx) target (nth 2 idx))
1019 (if (and (stringp target) (string-match "\\S-" target))
1020 (setq tgext (concat "::#" target))
1021 (setq tgext ""))
1022 (setq letter (upcase (substring entry 0 1)))
1023 (when (not (equal letter last-letter))
1024 (insert "** " letter "\n")
1025 (setq last-letter letter))
1026 (if (string-match "!" entry)
1027 (setq main (substring entry 0 (match-beginning 0))
1028 sub (substring entry (match-end 0)))
1029 (setq main nil sub nil last-main nil))
1030 (when (and main (not (equal main last-main)))
1031 (insert " - " main "\n")
1032 (setq last-main main))
1033 (setq link (concat "[[file:" file tgext "]"
1034 "[" (or sub entry) "]]"))
1035 (if (and main sub)
1036 (insert " - " link "\n")
1037 (insert " - " link "\n")))
1038 (save-buffer))
1039 (kill-buffer ibuffer)
1040 ;; Create theindex.org if it doesn't exist already
1041 (let ((index-file (expand-file-name "theindex.org" directory)))
1042 (unless (file-exists-p index-file)
1043 (setq ibuffer (find-file-noselect index-file))
1044 (with-current-buffer ibuffer
1045 (erase-buffer)
1046 (insert "\n\n#+INCLUDE: \"theindex.inc\"\n\n")
1047 (save-buffer))
1048 (kill-buffer ibuffer)))))
1050 ;; Caching functions:
1052 (defun org-publish-write-cache-file (&optional free-cache)
1053 "Write `org-publish-cache' to file.
1054 If FREE-CACHE, empty the cache."
1055 (or org-publish-cache
1056 (error "`org-publish-write-cache-file' called, but no cache present"))
1058 (let ((cache-file (org-publish-cache-get ":cache-file:")))
1059 (or cache-file
1060 (error "Cannot find cache-file name in `org-publish-write-cache-file'"))
1061 (with-temp-file cache-file
1062 (let ((print-level nil)
1063 (print-length nil))
1064 (insert "(setq org-publish-cache (make-hash-table :test 'equal :weakness nil :size 100))\n")
1065 (maphash (lambda (k v)
1066 (insert
1067 (format (concat "(puthash %S "
1068 (if (or (listp v) (symbolp v))
1069 "'" "")
1070 "%S org-publish-cache)\n") k v)))
1071 org-publish-cache)))
1072 (when free-cache (org-publish-reset-cache))))
1074 (defun org-publish-initialize-cache (project-name)
1075 "Initialize the projects cache if not initialized yet and return it."
1077 (or project-name
1078 (error "Cannot initialize `org-publish-cache' without projects name in `org-publish-initialize-cache'"))
1080 (unless (file-exists-p org-publish-timestamp-directory)
1081 (make-directory org-publish-timestamp-directory t))
1082 (if (not (file-directory-p org-publish-timestamp-directory))
1083 (error "Org publish timestamp: %s is not a directory"
1084 org-publish-timestamp-directory))
1086 (unless (and org-publish-cache
1087 (string= (org-publish-cache-get ":project:") project-name))
1088 (let* ((cache-file (concat
1089 (expand-file-name org-publish-timestamp-directory)
1090 project-name
1091 ".cache"))
1092 (cexists (file-exists-p cache-file)))
1094 (when org-publish-cache
1095 (org-publish-reset-cache))
1097 (if cexists
1098 (load-file cache-file)
1099 (setq org-publish-cache
1100 (make-hash-table :test 'equal :weakness nil :size 100))
1101 (org-publish-cache-set ":project:" project-name)
1102 (org-publish-cache-set ":cache-file:" cache-file))
1103 (unless cexists (org-publish-write-cache-file nil))))
1104 org-publish-cache)
1106 (defun org-publish-reset-cache ()
1107 "Empty org-publish-cache and reset it nil."
1108 (message "%s" "Resetting org-publish-cache")
1109 (if (hash-table-p org-publish-cache)
1110 (clrhash org-publish-cache))
1111 (setq org-publish-cache nil))
1113 (defun org-publish-cache-file-needs-publishing (filename &optional pub-dir pub-func base-dir)
1114 "Check the timestamp of the last publishing of FILENAME.
1115 Return `t', if the file needs publishing. The function also
1116 checks if any included files have been more recently published,
1117 so that the file including them will be republished as well."
1118 (or org-publish-cache
1119 (error "`org-publish-cache-file-needs-publishing' called, but no cache present"))
1120 (let* ((key (org-publish-timestamp-filename filename pub-dir pub-func))
1121 (pstamp (org-publish-cache-get key))
1122 (visiting (find-buffer-visiting filename))
1123 (case-fold-search t)
1124 included-files-ctime buf)
1126 (when (equal (file-name-extension filename) "org")
1127 (setq buf (find-file (expand-file-name filename)))
1128 (with-current-buffer buf
1129 (goto-char (point-min))
1130 (while (re-search-forward "^#\\+include:[ \t]+\"\\([^\t\n\r\"]*\\)\"[ \t]*.*$" nil t)
1131 (let* ((included-file (expand-file-name (match-string 1))))
1132 (add-to-list 'included-files-ctime
1133 (org-publish-cache-ctime-of-src included-file) t))))
1134 ;; FIXME don't kill current buffer
1135 (unless visiting (kill-buffer buf)))
1136 (if (null pstamp)
1138 (let ((ctime (org-publish-cache-ctime-of-src filename)))
1139 (or (< pstamp ctime)
1140 (when included-files-ctime
1141 (not (null (delq nil (mapcar (lambda(ct) (< ctime ct))
1142 included-files-ctime))))))))))
1144 (defun org-publish-cache-set-file-property (filename property value &optional project-name)
1145 "Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE.
1146 Use cache file of PROJECT-NAME. If the entry does not exist, it will be
1147 created. Return VALUE."
1148 ;; Evtl. load the requested cache file:
1149 (if project-name (org-publish-initialize-cache project-name))
1150 (let ((pl (org-publish-cache-get filename)))
1151 (if pl
1152 (progn
1153 (plist-put pl property value)
1154 value)
1155 (org-publish-cache-get-file-property
1156 filename property value nil project-name))))
1158 (defun org-publish-cache-get-file-property
1159 (filename property &optional default no-create project-name)
1160 "Return the value for a PROPERTY of file FILENAME in publishing cache.
1161 Use cache file of PROJECT-NAME. Return the value of that PROPERTY or
1162 DEFAULT, if the value does not yet exist.
1163 If the entry will be created, unless NO-CREATE is not nil."
1164 ;; Evtl. load the requested cache file:
1165 (if project-name (org-publish-initialize-cache project-name))
1166 (let ((pl (org-publish-cache-get filename))
1167 (retval nil))
1168 (if pl
1169 (if (plist-member pl property)
1170 (setq retval (plist-get pl property))
1171 (setq retval default))
1172 ;; no pl yet:
1173 (unless no-create
1174 (org-publish-cache-set filename (list property default)))
1175 (setq retval default))
1176 retval))
1178 (defun org-publish-cache-get (key)
1179 "Return the value stored in `org-publish-cache' for key KEY.
1180 Returns nil, if no value or nil is found, or the cache does not
1181 exist."
1182 (or org-publish-cache
1183 (error "`org-publish-cache-get' called, but no cache present"))
1184 (gethash key org-publish-cache))
1186 (defun org-publish-cache-set (key value)
1187 "Store KEY VALUE pair in `org-publish-cache'.
1188 Returns value on success, else nil."
1189 (or org-publish-cache
1190 (error "`org-publish-cache-set' called, but no cache present"))
1191 (puthash key value org-publish-cache))
1193 (defun org-publish-cache-ctime-of-src (file)
1194 "Get the ctime of filename F as an integer."
1195 (let ((attr (file-attributes
1196 (expand-file-name (or (file-symlink-p file) file)
1197 (file-name-directory file)))))
1198 (+ (lsh (car (nth 5 attr)) 16)
1199 (cadr (nth 5 attr)))))
1201 (provide 'org-publish)
1203 ;; Local variables:
1204 ;; generated-autoload-file: "org-loaddefs.el"
1205 ;; End:
1207 ;;; org-publish.el ends here