Version number change to 6.00pre-5
[org-mode.git] / lisp / org-publish.el
blob2562aa84b242bdd66baae1f59bd4c963692db847
1 ;;; org-publish.el --- publish related org-mode files as a website
2 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
4 ;; Author: David O'Toole <dto@gnu.org>
5 ;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
6 ;; Keywords: hypermedia, outlines, wp
7 ;; Version: 6.00pre-5
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;; Requires at least version 4.27 of org.el
30 ;; This program allow configurable publishing of related sets of
31 ;; Org-mode files as a complete website.
33 ;; org-publish.el can do the following:
35 ;; + Publish all one's org-files to HTML or LaTeX
36 ;; + Upload HTML, images, attachments and other files to a web server
37 ;; + Exclude selected private pages from publishing
38 ;; + Publish a clickable index of pages
39 ;; + Manage local timestamps for publishing only changed files
40 ;; + Accept plugin functions to extend range of publishable content
42 ;; Special thanks to the org-mode maintainer Carsten Dominik for his
43 ;; ideas, enthusiasm, and cooperation.
45 ;;; Installation:
47 ;; Put org-publish.el in your load path, byte-compile it, and then add
48 ;; the following lines to your emacs initialization file:
50 ;; (autoload 'org-publish "org-publish" nil t)
51 ;; (autoload 'org-publish "org-publish-all" nil t)
52 ;; (autoload 'org-publish "org-publish-current-file" nil t)
53 ;; (autoload 'org-publish "org-publish-current-project" nil t)
55 ;; NOTE: When org-publish.el is included with org.el, those forms are
56 ;; already in the file org-install.el, and hence don't need to be put
57 ;; in your emacs initialization file in this case.
59 ;;; Usage:
61 ;; The program's main configuration variable is
62 ;; `org-publish-project-alist'. See below for example configurations
63 ;; with commentary.
65 ;; The main interactive functions are:
67 ;; M-x org-publish
68 ;; M-x org-publish-all
69 ;; M-x org-publish-current-file
70 ;; M-x org-publish-current-project
72 ;;;; Simple example configuration:
74 ;; (setq org-publish-project-alist
75 ;; (list
76 ;; '("org" . (:base-directory "~/org/"
77 ;; :base-extension "org"
78 ;; :publishing-directory "~/public_html"
79 ;; :with-section-numbers nil
80 ;; :table-of-contents nil
81 ;; :recursive t
82 ;; :style "<link rel=stylesheet href=\"../other/mystyle.css\" type=\"text/css\">")))
84 ;;;; More complex example configuration:
86 ;; Imagine your *.org files are kept in ~/org, your images in
87 ;; ~/images, and stylesheets in ~/other. Now imagine you want to
88 ;; publish the files through an ssh connection to a remote host, via
89 ;; Tramp-mode. To maintain relative links from *.org files to /images
90 ;; and /other, we should replicate the same directory structure in
91 ;; your web server account's designated html root (in this case,
92 ;; assumed to be ~/html)
94 ;; Once you've done created the proper directories, you can adapt the
95 ;; following example configuration to your specific paths, run M-x
96 ;; org-publish-all, and it should publish the files to the correct
97 ;; directories on the web server, transforming the *.org files into
98 ;; HTML, and leaving other files alone.
100 ;; (setq org-publish-project-alist
101 ;; (list
102 ;; '("orgfiles" :base-directory "~/org/"
103 ;; :base-extension "org"
104 ;; :publishing-directory "/ssh:user@host:~/html/notebook/"
105 ;; :publishing-function org-publish-org-to-html
106 ;; :exclude "PrivatePage.org" ;; regexp
107 ;; :headline-levels 3
108 ;; :with-section-numbers nil
109 ;; :table-of-contents nil
110 ;; :style "<link rel=stylesheet href=\"../other/mystyle.css\" type=\"text/css\">"
111 ;; :auto-preamble t
112 ;; :auto-postamble nil)
113 ;; ("images" :base-directory "~/images/"
114 ;; :base-extension "jpg\\|gif\\|png"
115 ;; :publishing-directory "/ssh:user@host:~/html/images/"
116 ;; :publishing-function org-publish-attachment)
117 ;; ("other" :base-directory "~/other/"
118 ;; :base-extension "css"
119 ;; :publishing-directory "/ssh:user@host:~/html/other/"
120 ;; :publishing-function org-publish-attachment)
121 ;; ("website" :components ("orgfiles" "images" "other"))))
123 ;; For more information, see the documentation for the variable
124 ;; `org-publish-project-alist'.
126 ;; Of course, you don't have to publish to remote directories from
127 ;; within emacs. You can always just publish to local folders, and
128 ;; then use the synchronization/upload tool of your choice.
130 ;;; List of user-visible changes since version 1.27
132 ;; 1.78: Allow list-valued :publishing-function
133 ;; 1.77: Added :preparation-function, this allows you to use GNU Make etc.
134 ;; 1.65: Remove old "composite projects". They're redundant.
135 ;; 1.64: Allow meta-projects with :components
136 ;; 1.57: Timestamps flag is now called "org-publish-use-timestamps-flag"
137 ;; 1.52: Properly set default for :index-filename
138 ;; 1.48: Composite projects allowed.
139 ;; :include keyword allowed.
140 ;; 1.43: Index no longer includes itself in the index.
141 ;; 1.42: Fix "function definition is void" error
142 ;; when :publishing-function not set in org-publish-current-file.
143 ;; 1.41: Fixed bug where index isn't published on first try.
144 ;; 1.37: Added interactive function "org-publish". Prompts for particular
145 ;; project name to publish.
146 ;; 1.34: Added force-publish option to all interactive functions.
147 ;; 1.32: Fixed "index.org has changed on disk" error during index publishing.
148 ;; 1.30: Fixed startup error caused by (require 'em-unix)
150 ;;; Code:
152 (eval-when-compile
153 (require 'cl))
155 (eval-and-compile
156 (unless (fboundp 'declare-function)
157 (defmacro declare-function (fn file &optional arglist fileonly))))
159 (defgroup org-publish nil
160 "Options for publishing a set of Org-mode and related files."
161 :tag "Org Publishing"
162 :group 'org)
164 (defcustom org-publish-project-alist nil
165 "Association list to control publishing behavior.
166 Each element of the alist is a publishing 'project.' The CAR of
167 each element is a string, uniquely identifying the project. The
168 CDR of each element is in one of the following forms:
170 (:property value :property value ... )
174 (:components (\"project-1\" \"project-2\" ...))
176 When the CDR of an element of org-publish-project-alist is in
177 this second form, the elements of the list after :components are
178 taken to be components of the project, which group together files
179 requiring different publishing options. When you publish such a
180 project with M-x org-publish, the components all publish.
182 When a property is given a value in org-publish-project-alist, its
183 setting overrides the value of the corresponding user variable
184 (if any) during publishing. However, options set within a file
185 override everything.
187 Most properties are optional, but some should always be set:
189 :base-directory Directory containing publishing source files
190 :base-extension Extension (without the dot!) of source files.
191 This can be a regular expression.
192 :publishing-directory Directory (possibly remote) where output
193 files will be published
195 The :exclude property may be used to prevent certain files from
196 being published. Its value may be a string or regexp matching
197 file names you don't want to be published.
199 The :include property may be used to include extra files. Its
200 value may be a list of filenames to include. The filenames are
201 considered relative to the publishing directory.
203 When both :include and :exclude properties are given values, the
204 exclusion step happens first.
206 One special property controls which back-end function to use for
207 publishing files in the project. This can be used to extend the
208 set of file types publishable by org-publish, as well as the set
209 of output formats.
211 :publishing-function Function to publish file. The default is
212 org-publish-org-to-html, but other
213 values are possible. May also be a
214 list of functions, in which case
215 each function in the list is invoked
216 in turn.
218 Another property allows you to insert code that prepares a
219 project for publishing. For example, you could call GNU Make on a
220 certain makefile, to ensure published files are built up to date.
222 :preparation-function Function to be called before publishing
223 this project.
225 Some properties control details of the Org publishing process,
226 and are equivalent to the corresponding user variables listed in
227 the right column. See the documentation for those variables to
228 learn more about their use and default values.
230 :language org-export-default-language
231 :headline-levels org-export-headline-levels
232 :section-numbers org-export-with-section-numbers
233 :table-of-contents org-export-with-toc
234 :emphasize org-export-with-emphasize
235 :sub-superscript org-export-with-sub-superscripts
236 :TeX-macros org-export-with-TeX-macros
237 :fixed-width org-export-with-fixed-width
238 :tables org-export-with-tables
239 :table-auto-headline org-export-highlight-first-table-line
240 :style org-export-html-style
241 :convert-org-links org-export-html-link-org-files-as-html
242 :inline-images org-export-html-inline-images
243 :expand-quoted-html org-export-html-expand
244 :timestamp org-export-html-with-timestamp
245 :publishing-directory org-export-publishing-directory
246 :preamble org-export-html-preamble
247 :postamble org-export-html-postamble
248 :auto-preamble org-export-html-auto-preamble
249 :auto-postamble org-export-html-auto-postamble
250 :author user-full-name
251 :email user-mail-address
253 The following properties may be used to control publishing of an
254 index of files or summary page for a given project.
256 :auto-index Whether to publish an index during
257 org-publish-current-project or org-publish-all.
258 :index-filename Filename for output of index. Defaults
259 to 'index.org' (which becomes 'index.html')
260 :index-title Title of index page. Defaults to name of file.
261 :index-function Plugin function to use for generation of index.
262 Defaults to 'org-publish-org-index', which
263 generates a plain list of links to all files
264 in the project."
265 :group 'org-publish
266 :type 'alist)
268 (defcustom org-publish-use-timestamps-flag t
269 "When non-nil, use timestamp checking to publish only changed files.
270 When nil, do no timestamp checking and always publish all
271 files."
272 :group 'org-publish
273 :type 'boolean)
275 (defcustom org-publish-timestamp-directory "~/.org-timestamps/"
276 "Name of directory in which to store publishing timestamps."
277 :group 'org-publish
278 :type 'directory)
280 (defcustom org-publish-before-export-hook nil
281 "Hook run before export on the Org file.
282 If the functions in this hook modify the original Org buffer, the
283 modified buffer will be used for export, but the buffer will be
284 restored and saved back to its initial state after export."
285 :group 'org-publish
286 :type 'hook)
288 (defcustom org-publish-after-export-hook nil
289 "Hook run after export on the exported buffer.
290 If functions in this hook modify the buffer, it will be saved."
291 :group 'org-publish
292 :type 'hook)
294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
295 ;;; Timestamp-related functions
297 (defun org-publish-timestamp-filename (filename)
298 "Return path to timestamp file for filename FILENAME."
299 (while (string-match
300 (if (eq system-type 'windows-nt) "~\\|/\\|:" "~\\|/") filename)
301 (setq filename (replace-match "_" nil t filename)))
302 (concat org-publish-timestamp-directory filename ".timestamp"))
304 (defun org-publish-needed-p (filename)
305 "Return `t' if FILENAME should be published."
306 (if org-publish-use-timestamps-flag
307 (if (file-exists-p org-publish-timestamp-directory)
308 ;; first handle possible wrong timestamp directory
309 (if (not (file-directory-p org-publish-timestamp-directory))
310 (error "Org publish timestamp: %s is not a directory"
311 org-publish-timestamp-directory)
312 ;; there is a timestamp, check if FILENAME is newer
313 (file-newer-than-file-p
314 filename (org-publish-timestamp-filename filename))))
315 ;; don't use timestamps, always return t
318 (defun org-publish-update-timestamp (filename)
319 "Update publishing timestamp for file FILENAME.
320 If there is no timestamp, create one."
321 (let ((timestamp-file (org-publish-timestamp-filename filename))
322 newly-created-timestamp)
323 (if (not (file-exists-p timestamp-file))
324 ;; create timestamp file if needed
325 (with-temp-buffer
326 (make-directory (file-name-directory timestamp-file) t)
327 (write-file timestamp-file)
328 (setq newly-created-timestamp t)))
329 ;; Emacs 21 doesn't have `set-file-times'
330 (if (and (fboundp 'set-file-times)
331 (not newly-created-timestamp))
332 (set-file-times timestamp-file)
333 (call-process "touch" nil 0 nil timestamp-file))))
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336 ;;; Mapping files to project names
338 (defvar org-publish-files-alist nil
339 "Alist of files and their parent project.
340 Each element of this alist is of the form:
342 (file-name . project-name)")
344 (defvar org-publish-initial-buffer nil
345 "The buffer `org-publish' has been called from.")
346 (defvar org-publish-temp-files nil
347 "Temporary list of files to be published.")
349 (defun org-publish-initialize-files-alist (&optional refresh)
350 "Set `org-publish-files-alist' if it is not set.
351 Also set it if the optional argument REFRESH is non-nil."
352 (interactive "P")
353 (when (or refresh (not org-publish-files-alist))
354 (setq org-publish-files-alist
355 (org-publish-get-files org-publish-project-alist))))
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))
379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
380 ;;; Getting project information out of org-publish-project-alist
382 (defun org-publish-get-files (projects-alist &optional no-exclusion)
383 "Return the list of all publishable files for PROJECTS-ALIST.
384 If NO-EXCLUSION is non-nil, don't exclude files."
385 (let (all-files)
386 ;; add all projects
387 (mapc
388 (lambda(p)
389 (let* ((exclude (plist-get (cdr p) :exclude))
390 (files (and p (org-publish-get-base-files p exclude))))
391 ;; add all files from this project
392 (mapc (lambda(f)
393 (add-to-list 'all-files
394 (cons (expand-file-name f) (car p))))
395 files)))
396 (org-publish-expand-projects projects-alist))
397 all-files))
399 (defun org-publish-expand-projects (projects-alist)
400 "Expand projects contained in PROJECTS-ALIST."
401 (let (without-component with-component)
402 (mapc (lambda(p)
403 (add-to-list
404 (if (plist-get (cdr p) :components)
405 'with-component 'without-component) p))
406 projects-alist)
407 (org-publish-delete-dups
408 (append without-component
409 (car (mapcar (lambda(p) (org-publish-expand-components p))
410 with-component))))))
412 (defun org-publish-expand-components (project)
413 "Expand PROJECT into an alist of its components."
414 (let* ((components (plist-get (cdr project) :components)))
415 (org-publish-delete-dups
416 (delq nil (mapcar (lambda(c) (assoc c org-publish-project-alist))
417 components)))))
419 (defun org-publish-get-base-files-1 (base-dir &optional recurse match skip-file skip-dir)
420 "Set `org-publish-temp-files' with files from BASE-DIR directory.
421 If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is
422 non-nil, restrict this list to the files matching the regexp
423 MATCH. If SKIP-FILE is non-nil, skip file matching the regexp
424 SKIP-FILE. If SKIP-DIR is non-nil, don't check directories
425 matching the regexp SKIP-DIR when recursiing through BASE-DIR."
426 (mapc (lambda (f)
427 (let ((fd-p (car (file-attributes f)))
428 (fnd (file-name-nondirectory f)))
429 (if (and fd-p recurse
430 (not (string-match "^\\.+$" fnd))
431 (if skip-dir (not (string-match skip-dir fnd)) t))
432 (org-publish-get-base-files-1 f recurse match skip-file skip-dir)
433 (unless (or fd-p ;; this is a directory
434 (and skip-file (string-match skip-file fnd))
435 (not (string-match match fnd)))
436 (pushnew f org-publish-temp-files)))))
437 (directory-files base-dir t (unless recurse match))))
439 (defun org-publish-get-base-files (project &optional exclude-regexp)
440 "Return a list of all files in PROJECT.
441 If EXCLUDE-REGEXP is set, this will be used to filter out
442 matching filenames."
443 (let* ((project-plist (cdr project))
444 (base-dir (file-name-as-directory
445 (plist-get project-plist :base-directory)))
446 (include-list (plist-get project-plist :include))
447 (recurse (plist-get project-plist :recursive))
448 (extension (or (plist-get project-plist :base-extension) "org"))
449 (match (concat "^[^\\.].*\\.\\(" extension "\\)$")))
450 (setq org-publish-temp-files nil)
451 (org-publish-get-base-files-1 base-dir recurse match
452 ;; FIXME distinguish exclude regexp
453 ;; for skip-file and skip-dir?
454 exclude-regexp exclude-regexp)
455 org-publish-temp-files))
457 (defun org-publish-get-project-from-filename (filename)
458 "Return the project FILENAME belongs."
459 (let* ((project-name (cdr (assoc (expand-file-name filename)
460 org-publish-files-alist))))
461 (assoc project-name org-publish-project-alist)))
463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
464 ;;; Pluggable publishing back-end functions
466 (defun org-publish-org-to (format plist filename pub-dir)
467 "Publish an org file to FORMAT.
468 PLIST is the property list for the given project.
469 FILENAME is the filename of the org file to be published.
470 PUB-DIR is the publishing directory."
471 (require 'org)
472 (unless (file-exists-p pub-dir)
473 (make-directory pub-dir t))
474 (find-file filename)
475 (let ((init-buf (current-buffer))
476 (init-point (point))
477 (init-buf-string (buffer-string)) export-buf)
478 ;; run hooks before exporting
479 (run-hooks 'org-publish-before-export-hook)
480 ;; export the possibly modified buffer
481 (setq export-buf
482 (funcall (intern (concat "org-export-as-" format))
483 (plist-get plist :headline-levels)
484 nil plist nil nil pub-dir))
485 (set-buffer export-buf)
486 ;; run hooks after export and save export
487 (and (run-hooks 'org-publish-after-export-hook)
488 (if (buffer-modified-p) (save-buffer)))
489 (kill-buffer export-buf)
490 ;; maybe restore buffer's content
491 (set-buffer init-buf)
492 (when (buffer-modified-p init-buf)
493 (erase-buffer)
494 (insert init-buf-string)
495 (save-buffer)
496 (goto-char init-point))
497 (unless (eq init-buf org-publish-initial-buffer)
498 (kill-buffer init-buf))))
500 (defun org-publish-org-to-latex (plist filename pub-dir)
501 "Publish an org file to LaTeX.
502 See `org-publish-org-to' to the list of arguments."
503 (org-publish-org-to "latex" plist filename pub-dir))
505 (defun org-publish-org-to-html (plist filename pub-dir)
506 "Publish an org file to HTML.
507 See `org-publish-org-to' to the list of arguments."
508 (org-publish-org-to "html" plist filename pub-dir))
510 (defun org-publish-attachment (plist filename pub-dir)
511 "Publish a file with no transformation of any kind.
512 See `org-publish-org-to' to the list of arguments."
513 ;; make sure eshell/cp code is loaded
514 (eval-and-compile
515 (require 'eshell)
516 (require 'esh-maint)
517 (require 'em-unix))
518 (eshell/cp filename pub-dir))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
521 ;;; Publishing files, sets of files, and indices
523 (defun org-publish-file (filename &optional project)
524 "Publish file FILENAME from PROJECT."
525 (when (org-publish-needed-p filename)
526 (let* ((project
527 (or project
528 (or (org-publish-get-project-from-filename filename)
529 (if (y-or-n-p
530 (format "%s is not in a project. Re-read the list of projects files? "
531 (abbreviate-file-name filename)))
532 ;; If requested, re-initialize the list of projects files
533 (progn (org-publish-initialize-files-alist t)
534 (or (org-publish-get-project-from-filename filename)
535 (error "File %s not part of any known project"
536 (abbreviate-file-name filename))))
537 (error "Can't publish file outside of a project")))))
538 (project-plist (cdr project))
539 (publishing-function
540 (or (plist-get project-plist :publishing-function)
541 'org-publish-org-to-html))
542 (base-dir (file-name-as-directory
543 (file-truename (plist-get project-plist :base-directory))))
544 (pub-dir (file-name-as-directory
545 (file-truename (plist-get project-plist :publishing-directory))))
546 tmp-pub-dir)
547 (setq tmp-pub-dir
548 (file-name-directory
549 (concat pub-dir
550 (and (string-match (regexp-quote base-dir) filename)
551 (substring filename (match-end 0))))))
552 (if (listp publishing-function)
553 ;; allow chain of publishing functions
554 (mapc (lambda (f)
555 (funcall f project-plist filename tmp-pub-dir))
556 publishing-function)
557 (funcall publishing-function project-plist filename tmp-pub-dir)))
558 (org-publish-update-timestamp filename)))
560 (defun org-publish-projects (projects)
561 "Publish all files belonging to the PROJECTS alist.
562 If :auto-index is set, publish the index too."
563 (mapc
564 (lambda (project)
565 (let* ((project-plist (cdr project))
566 (exclude-regexp (plist-get project-plist :exclude))
567 (index-p (plist-get project-plist :auto-index))
568 (index-filename (or (plist-get project-plist :index-filename)
569 "index.org"))
570 (index-function (or (plist-get project-plist :index-function)
571 'org-publish-org-index))
572 (preparation-function (plist-get project-plist :preparation-function))
573 (files (org-publish-get-base-files project exclude-regexp)) file)
574 (when preparation-function (funcall preparation-function))
575 (if index-p (funcall index-function project index-filename))
576 (while (setq file (pop files))
577 (org-publish-file file project))))
578 (org-publish-expand-projects projects)))
580 (defun org-publish-org-index (project &optional index-filename)
581 "Create an index of pages in set defined by PROJECT.
582 Optionally set the filename of the index with INDEX-FILENAME.
583 Default for INDEX-FILENAME is 'index.org'."
584 (let* ((project-plist (cdr project))
585 (dir (file-name-as-directory
586 (plist-get project-plist :base-directory)))
587 (exclude-regexp (plist-get project-plist :exclude))
588 (files (org-publish-get-base-files project exclude-regexp))
589 (index-filename (concat dir (or index-filename "index.org")))
590 (index-buffer (find-buffer-visiting index-filename))
591 (ifn (file-name-nondirectory index-filename))
592 file)
593 ;; if buffer is already open, kill it to prevent error message
594 (if index-buffer
595 (kill-buffer index-buffer))
596 (with-temp-buffer
597 (while (setq file (pop files))
598 (let ((fn (file-name-nondirectory file)))
599 ;; index shouldn't index itself
600 (unless (string= fn ifn)
601 (insert (concat " + [[file:" fn "]["
602 (file-name-sans-extension fn)
603 "]]\n")))))
604 (write-file index-filename)
605 (kill-buffer (current-buffer)))))
607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
608 ;;; Interactive publishing functions
610 (defalias 'org-publish-project 'org-publish)
612 ;;;###autoload
613 (defun org-publish (project &optional force)
614 "Publish PROJECT."
615 (interactive "P")
616 (setq org-publish-initial-buffer (current-buffer))
617 (save-window-excursion
618 (let* ((force current-prefix-arg)
619 (org-publish-use-timestamps-flag
620 (if force nil org-publish-use-timestamps-flag)))
621 (org-publish-projects
622 (list (or project
623 (assoc (completing-read
624 "Publish project: "
625 org-publish-project-alist nil t)
626 org-publish-project-alist)))))))
628 ;;;###autoload
629 (defun org-publish-all (&optional force)
630 "Publish all projects.
631 With prefix argument, force publish all files."
632 (interactive "P")
633 (org-publish-initialize-files-alist)
634 (save-window-excursion
635 (let ((org-publish-use-timestamps-flag
636 (if force nil org-publish-use-timestamps-flag)))
637 (org-publish-projects org-publish-project-alist))))
639 ;;;###autoload
640 (defun org-publish-current-file (&optional force)
641 "Publish the current file.
642 With prefix argument, force publish the file."
643 (interactive "P")
644 (org-publish-initialize-files-alist)
645 (save-window-excursion
646 (let ((org-publish-use-timestamps-flag
647 (if force nil org-publish-use-timestamps-flag)))
648 (org-publish-file (buffer-file-name)))))
650 ;;;###autoload
651 (defun org-publish-current-project (&optional force)
652 "Publish the project associated with the current file.
653 With a prefix argument, force publishing of all files in
654 the project."
655 (interactive "P")
656 (org-publish-initialize-files-alist)
657 (save-window-excursion
658 (let ((project (org-publish-get-project-from-filename (buffer-file-name)))
659 (org-publish-use-timestamps-flag
660 (if force nil org-publish-use-timestamps-flag)))
661 (if (not project)
662 (error "File %s is not part of any known project" (buffer-file-name)))
663 (org-publish project))))
665 (provide 'org-publish)
668 ;; arch-tag: 72807f3c-8af0-4a6b-8dca-c3376eb25adb
669 ;;; org-publish.el ends here