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