muse-blosxom: Perform extra check on category in new entry.
[muse-el.git] / lisp / muse-project.el
blob4d2ffc9643e3530777daab4641bb8fcb588a7397
1 ;;; muse-project.el --- handle Muse projects
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 ;;; Commentary:
24 ;;; Contributors:
26 ;;; Code:
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse Project Maintainance
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'muse)
35 (require 'muse-publish)
36 (require 'cus-edit)
38 (defgroup muse-project nil
39 "Options controlling the behavior of Muse project handling."
40 :group 'muse)
42 (defcustom muse-before-project-publish-hook nil
43 "A hook run before a project is published.
44 Each function is passed the project object, a cons with the format
45 (PROJNAME . SETTINGS)"
46 :type 'hook
47 :group 'muse-project)
49 (defcustom muse-after-project-publish-hook nil
50 "A hook run after a project is published.
51 Each function is passed the project object, a cons with the format
52 (PROJNAME . SETTINGS)"
53 :type 'hook
54 :group 'muse-project)
56 (defvar muse-project-alist-using-customize nil
57 "Used internally by Muse to indicate whether `muse-project-alist'
58 has been modified via the customize interface.")
59 (make-variable-buffer-local 'muse-project-alist-using-customize)
61 (defmacro with-muse-project (project &rest body)
62 `(progn
63 (unless (muse-project ,project)
64 (error "Can't find project %s" ,project))
65 (with-temp-buffer
66 (muse-mode)
67 (setq muse-current-project (muse-project ,project))
68 (muse-project-set-variables)
69 ,@body)))
71 (put 'with-muse-project 'lisp-indent-function 0)
72 (put 'with-muse-project 'edebug-form-spec '(sexp body))
74 (defun muse-project-alist-get (sym)
75 "Turn `muse-project-alist' into something we can customize easily."
76 (when (boundp sym)
77 (setq muse-project-alist-using-customize t)
78 (let* ((val (copy-alist (symbol-value sym)))
79 (head val))
80 (while val
81 (let ((head (car (cdar val)))
82 res)
83 ;; Turn settings of first part into cons cells, symbol->string
84 (while head
85 (cond ((stringp (car head))
86 (add-to-list 'res (car head) t)
87 (setq head (cdr head)))
88 ((symbolp (car head))
89 (add-to-list 'res (list (symbol-name (car head))
90 (cadr head)) t)
91 (setq head (cddr head)))
93 (setq head (cdr head)))))
94 (setcdr (car val) (cons res (cdr (cdar val)))))
95 (let ((styles (cdar val)))
96 ;; Symbol->string in every style
97 (while (cdr styles)
98 (let ((head (cadr styles))
99 res)
100 (while (consp head)
101 (setq res (plist-put res (symbol-name (car head))
102 (cadr head)))
103 (setq head (cddr head)))
104 (setcdr styles (cons res (cddr styles))))
105 (setq styles (cdr styles))))
106 (setq val (cdr val)))
107 head)))
109 (defun muse-project-alist-set (sym val)
110 "Turn customized version of `muse-project-alist' into something
111 Muse can make use of."
112 (set sym val)
113 (when muse-project-alist-using-customize
114 ;; Make sure the unescaped version is written to .emacs
115 (put sym 'saved-value (list (custom-quote val)))
116 ;; Perform unescaping
117 (while val
118 (let ((head (car (cdar val)))
119 res)
120 ;; Turn cons cells into flat list, string->symbol
121 (while head
122 (cond ((stringp (car head))
123 (add-to-list 'res (car head) t))
124 ((consp (car head))
125 (add-to-list 'res (intern (caar head)) t)
126 (add-to-list 'res (car (cdar head)) t)))
127 (setq head (cdr head)))
128 (setcdr (car val) (cons res (cdr (cdar val)))))
129 (let ((styles (cdar val)))
130 ;; String->symbol in every style
131 (while (cdr styles)
132 (let ((head (cadr styles))
133 res)
134 (while (consp head)
135 (setq res (plist-put res (intern (car head))
136 (cadr head)))
137 (setq head (cddr head)))
138 (setcdr styles (cons res (cddr styles))))
139 (setq styles (cdr styles))))
140 (setq val (cdr val)))))
142 (define-widget 'muse-project 'default
143 "A widget that defines a Muse project."
144 :format "\n%v"
145 :value-create 'muse-widget-type-value-create
146 :value-get 'muse-widget-child-value-get
147 :value-delete 'ignore
148 :match 'muse-widget-type-match
149 :type '(cons :format " %v"
150 (repeat :tag "Settings" :format "%{%t%}:\n%v%i\n\n"
151 (choice
152 (string :tag "Directory")
153 (list :tag "Book function"
154 (const :tag ":book-funcall" ":book-funcall")
155 (choice (function)
156 (sexp :tag "Unknown")))
157 (list :tag "Book part"
158 (const :tag ":book-part" ":book-part")
159 (string :tag "Name"))
160 (list :tag "Book style"
161 (const :tag ":book-style" ":book-style")
162 (string :tag "Style"))
163 (list :tag "Default file"
164 (const :tag ":default" ":default")
165 (string :tag "File"))
166 (list :tag "End of book"
167 (const :tag ":book-end" ":book-end")
168 (const t))
169 (list :tag "Force publishing"
170 (const :tag ":force-publish" ":force-publish")
171 (repeat (string :tag "File")))
172 (list :tag "Major mode"
173 (const :tag ":major-mode" ":major-mode")
174 (choice (function :tag "Mode")
175 (sexp :tag "Unknown")))
176 (list :tag "New chapter"
177 (const :tag ":book-chapter" ":book-chapter")
178 (string :tag "Name"))
179 (list :tag "No chapters"
180 (const :tag ":nochapters" ":nochapters")
181 (const t))
182 (list :tag "Set variables"
183 (const :tag ":set" ":set")
184 (repeat (list :inline t
185 (symbol :tag "Variable")
186 (sexp :tag "Setting"))))
187 (list :tag "Visit links using"
188 (const :tag ":visit-link" ":visit-link")
189 (choice (function)
190 (sexp :tag "Unknown")))))
191 (repeat :tag "Styles" :format "%{%t%}:\n%v%i\n\n"
192 (set :tag "Style"
193 (list :inline t
194 :tag "Publishing style"
195 (const :tag ":base" ":base")
196 (string :tag "Style"))
197 (list :inline t
198 :tag "Base URL"
199 (const :tag ":base-url" ":base-url")
200 (string :tag "URL"))
201 (list :inline t
202 :tag "Exclude matching"
203 (const :tag ":exclude" ":exclude")
204 (regexp))
205 (list :inline t
206 :tag "Include matching"
207 (const :tag ":include" ":include")
208 (regexp))
209 (list :inline t
210 :tag "Timestamps file"
211 (const :tag ":timestamps" ":timestamps")
212 (file))
213 (list :inline t
214 :tag "Path"
215 (const :tag ":path" ":path")
216 (string :tag "Path"))))))
218 (defcustom muse-project-alist nil
219 "An alist of Muse projects.
220 A project defines a fileset, and a list of custom attributes for use
221 when publishing files in that project."
222 :type '(choice (const :tag "No projects defined." nil)
223 (repeat (cons :format "%{%t%}:\n\n%v"
224 :tag "Project" :indent 4
225 (string :tag "Project name")
226 muse-project))
227 (sexp :tag "Cannot parse expression"))
228 :get 'muse-project-alist-get
229 :set 'muse-project-alist-set
230 :group 'muse-project)
232 ;; Make it easier to specify a muse-project-alist entry
234 (defcustom muse-project-ignore-regexp
235 (concat "\\`\\(.*\\.?#.*\\|.*,v\\|.*~\\|\\.\\.?\\|,.*\\)\\'\\|"
236 "/\\(CVS\\|RCS\\|\\.arch-ids\\|{arch}\\|,.*\\)\\(/\\|\\'\\)")
237 "A regexp matching files to be ignored in Wiki directories.
239 You should set case-fold-search to nil before using this regexp
240 in code."
241 :type 'regexp
242 :group 'muse-regexp)
244 (defun muse-project-recurse-directory (base)
245 "Recusively retrieve all of the directories underneath BASE.
246 A list of these directories is returned.
247 Directories starting with \".\" will be ignored, as well as those
248 which match `muse-project-ignore-regexp'."
249 (let ((case-fold-search nil)
250 list dir)
251 (when (and (file-directory-p base)
252 (not (string-match muse-project-ignore-regexp base)))
253 (dolist (file (directory-files base t "^[^.]"))
254 (when (and (file-directory-p file)
255 (not (string-match muse-project-ignore-regexp file)))
256 (setq dir (file-name-nondirectory file))
257 (push dir list)
258 (nconc list (mapcar #'(lambda (item)
259 (concat dir "/" item))
260 (muse-project-recurse-directory file)))))
261 list)))
263 (defun muse-project-alist-styles (entry-dir output-dir style)
264 "Return a list of styles to use in a `muse-project-alist' entry.
265 ENTRY-DIR is the top-level directory of the project.
266 OUTPUT-DIR is where Muse files are published, keeping directory structure.
267 STYLE is the publishing style to use.
269 For an example of the use of this function, see
270 `examples/mwolson/muse-init.el' from the Muse distribution."
271 (cons `(:base ,style :path ,(expand-file-name output-dir)
272 :include ,(concat "/" (file-name-nondirectory entry-dir)
273 "/[^/]+$"))
274 (mapcar (lambda (dir);
275 `(:base ,style
276 :path ,(expand-file-name dir output-dir)
277 :include ,(concat "/" dir "/[^/]+$")))
278 (muse-project-recurse-directory entry-dir))))
280 (defun muse-project-alist-dirs (entry-dir)
281 "Return a list of directories to use in a `muse-project-alist' entry.
282 ENTRY-DIR is the top-level directory of the project.
284 For an example of the use of this function, see
285 `examples/mwolson/muse-init.el' from the Muse distribution."
286 (cons (expand-file-name entry-dir)
287 (mapcar (lambda (dir) (expand-file-name dir entry-dir))
288 (muse-project-recurse-directory entry-dir))))
290 ;; Constructing the file-alist
292 (defvar muse-project-file-alist nil
293 "This variable is automagically constructed as needed.")
295 (defvar muse-project-file-alist-hook nil
296 "Functions that are to be exectuted immediately after updating
297 `muse-project-file-alist'.")
299 (defvar muse-current-project nil
300 "Project we are currently visiting.")
301 (make-variable-buffer-local 'muse-current-project)
303 (defsubst muse-project (&optional project)
304 "Resolve the given PROJECT into a full Muse project, if it is a string."
305 (if (null project)
306 (or muse-current-project
307 (muse-project-of-file))
308 (if (stringp project)
309 (assoc project muse-project-alist)
310 (muse-assert (consp project))
311 project)))
313 (defsubst muse-project-page-file (page project &optional no-check-p)
314 "Return a filename if PAGE exists within the given Muse PROJECT."
315 (setq project (muse-project project))
316 (cdr (assoc page (muse-project-file-alist project no-check-p))))
318 (defun muse-project-private-p (file)
319 "Return non-nil if NAME is a private page with PROJECT."
320 (unless muse-under-windows-p
321 (setq file (file-truename file))
322 (if (file-attributes file) ; don't publish if no attributes exist
323 (or (when (eq ?- (aref (nth 8 (file-attributes
324 (file-name-directory file))) 7))
325 (message (concat
326 "The " (file-name-directory file)
327 " directory must be readable by others"
328 " in order for its contents to be published.")))
329 (eq ?- (aref (nth 8 (file-attributes file)) 7)))
330 t)))
332 (defun muse-project-file-entries (path)
333 (let* ((names (list t))
334 (lnames names)
335 (case-fold-search nil))
336 (cond
337 ((file-directory-p path)
338 (dolist (file (directory-files
339 path t (when (and muse-file-extension
340 (not (string= muse-file-extension "")))
341 (concat "." muse-file-extension "\\'"))))
342 (unless (or (string-match muse-project-ignore-regexp file)
343 (file-directory-p file))
344 (setcdr lnames
345 (cons (cons (muse-page-name file) file) nil))
346 (setq lnames (cdr lnames)))))
347 ((file-readable-p path)
348 (setcdr lnames
349 (cons (cons (muse-page-name path) path) nil))
350 (setq lnames (cdr lnames)))
351 (t ; regexp
352 (muse-assert (file-name-directory path))
353 (dolist (file (directory-files
354 (file-name-directory path) t
355 (file-name-nondirectory path)))
356 (unless (string-match muse-project-ignore-regexp file)
357 (setcdr lnames
358 (cons (cons (muse-page-name file) file) nil))
359 (setq lnames (cdr lnames))))))
360 (cdr names)))
362 (defvar muse-updating-file-alist-p nil
363 "Make sure that recursive calls to `muse-project-file-alist' are bounded.")
365 (defun muse-project-file-alist (&optional project no-check-p)
366 "Return member filenames for the given Muse PROJECT.
367 On UNIX, this list is only updated if one of the directories'
368 contents have changed. On Windows, it is always reread from
369 disk."
370 (setq project (muse-project project))
371 (let* ((file-alist (assoc (car project) muse-project-file-alist))
372 (last-mod (cdr (cdr file-alist))))
373 ;; Determine the last modified of any directory mentioned in the
374 ;; project's pattern list
375 (unless (or muse-under-windows-p no-check-p)
376 (let ((pats (cadr project)))
377 (while pats
378 (if (symbolp (car pats))
379 (setq pats (cddr pats))
380 (let* ((fnd (file-name-directory (car pats)))
381 (dir (cond ((file-directory-p (car pats))
382 (car pats))
383 ((and (not (file-readable-p (car pats)))
385 (file-directory-p fnd))
386 fnd))))
387 (when dir
388 (let ((mod-time (nth 5 (file-attributes dir))))
389 (when (or (null last-mod)
390 (and mod-time
391 (muse-time-less-p last-mod mod-time)))
392 (setq last-mod mod-time)))))
393 (setq pats (cdr pats))))))
394 ;; Either return the currently known list, or read it again from
395 ;; disk
396 (if (or (and no-check-p (cadr file-alist))
397 muse-updating-file-alist-p
398 (not (or muse-under-windows-p
399 (null (cddr file-alist))
400 (null last-mod)
401 (muse-time-less-p (cddr file-alist) last-mod))))
402 (cadr file-alist)
403 (if file-alist
404 (setcdr (cdr file-alist) last-mod)
405 (setq file-alist (cons (car project) (cons nil last-mod))
406 muse-project-file-alist
407 (cons file-alist muse-project-file-alist)))
408 ;; Read in all of the file entries
409 (let ((muse-updating-file-alist-p t))
410 (prog1
411 (save-match-data
412 (setcar
413 (cdr file-alist)
414 (let* ((names (list t))
415 (pats (cadr project)))
416 (while pats
417 (if (symbolp (car pats))
418 (setq pats (cddr pats))
419 (nconc names (muse-project-file-entries (car pats)))
420 (setq pats (cdr pats))))
421 (cdr names))))
422 (run-hooks 'muse-project-file-alist-hook))))))
424 (defun muse-project-of-file (&optional pathname)
425 "Determine which project the given PATHNAME relates to.
426 If PATHNAME is nil, the current buffer's filename is used."
427 (if (and (null pathname) muse-current-project)
428 muse-current-project
429 (unless pathname (setq pathname (muse-current-file)))
430 (save-match-data
431 (when (and (stringp pathname)
432 (not (string= pathname ""))
433 (not (let ((case-fold-search nil))
434 (string-match muse-project-ignore-regexp pathname))))
435 (let* ((file (file-truename pathname))
436 (dir (file-name-directory file))
437 (project-entry muse-project-alist)
438 found)
439 (while (and project-entry (not found))
440 (let ((pats (car (cdar project-entry))))
441 (while (and pats (not found))
442 (if (symbolp (car pats))
443 (setq pats (cddr pats))
444 (let ((truename (file-truename (car pats))))
445 (if (or (string= truename file)
446 (string= truename dir)
447 (string-match (regexp-quote truename) file))
448 (setq found (car project-entry))))
449 (setq pats (cdr pats))))
450 (setq project-entry (cdr project-entry))))
451 found)))))
453 (defun muse-project-after-save-hook ()
454 "Update Muse's file-alist if we are saving a Muse file."
455 (let ((project (muse-project-of-file)))
456 (when project
457 (muse-project-file-alist project))))
459 (add-hook 'after-save-hook 'muse-project-after-save-hook)
461 (defun muse-read-project (prompt &optional no-check-p no-assume)
462 "Read a project name from the minibuffer, if it can't be figured
463 out."
464 (if (null muse-project-alist)
465 (error "There are no Muse projects defined; see `muse-project-alist'.")
466 (or (unless no-check-p
467 (muse-project-of-file))
468 (if (and (not no-assume)
469 (= 1 (length muse-project-alist)))
470 (car muse-project-alist)
471 (assoc (completing-read prompt muse-project-alist)
472 muse-project-alist)))))
474 (defvar muse-project-page-history nil)
476 (defun muse-read-project-file (project prompt &optional default)
477 (let ((name (completing-read prompt (muse-project-file-alist project)
478 nil nil nil 'muse-project-page-history
479 default)))
480 (cons name (muse-project-page-file name project))))
482 ;;;###autoload
483 (defun muse-project-find-file (name project &optional command directory)
484 "Open the Muse page given by NAME in PROJECT.
485 If COMMAND is non-nil, it is the function used to visit the file.
486 If DIRECTORY is non-nil, it is the directory in which the page
487 will be created if it does not already exist. Otherwise, the
488 first directory within the project's fileset is used."
489 (interactive
490 (let* ((project (muse-read-project "Find in project: "
491 current-prefix-arg))
492 (default (muse-get-keyword :default (cadr project)))
493 (entry (muse-read-project-file
494 project (if default
495 (format "Find page: (default: %s) "
496 default)
497 "Find page: ")
498 default)))
499 (list entry project)))
500 (setq project (muse-project project))
501 (let ((project-name (car project)))
502 (unless (interactive-p)
503 (setq project (muse-project project)
504 name (cons name (muse-project-page-file name project))))
505 ;; If we're given a relative or absolute filename, open it as-is
506 (if (and (car name)
507 (save-match-data
508 (or (string-match muse-file-regexp (car name))
509 (string-match muse-image-regexp (car name)))))
510 (setcdr name (car name))
511 ;; At this point, name is (PAGE . FILE).
512 (unless (cdr name)
513 (let ((pats (cadr project)))
514 (while (and pats (null directory))
515 (if (symbolp (car pats))
516 (setq pats (cddr pats))
517 (if (file-directory-p (car pats))
518 (setq directory (car pats) pats nil)
519 (setq pats (cdr pats))))))
520 (when directory
521 (let ((filename (expand-file-name
522 (if (and muse-file-extension
523 (not (string= muse-file-extension "")))
524 (concat (car name) "." muse-file-extension)
525 (car name))
526 directory)))
527 (unless (file-exists-p directory)
528 (make-directory directory t))
529 (setcdr name filename)))))
530 ;; Open the file
531 (if (cdr name)
532 (funcall (or command 'find-file) (cdr name))
533 (error "There is no page %s in project %s."
534 (car name) project-name))))
536 (defun muse-project-choose-style (closure test styles)
537 "Run TEST on STYLES and return first style where TEST yields non-nil.
538 TEST should take two arguments. The first is CLOSURE, which is
539 passed verbatim. The second if the current style to consider.
541 If no style passes TEST, return the first style."
542 (or (catch 'winner
543 (dolist (style styles)
544 (when (funcall test closure style)
545 (throw 'winner style))))
546 (car styles)))
548 (defun muse-project-applicable-styles (file styles &optional ignore-regexp)
549 "Given STYLES, return a list of the ones that are considered for FILE.
550 The name of a project may be used for STYLES."
551 (when (stringp styles)
552 (setq styles (cddr (muse-project styles))))
553 (when (and file styles)
554 (let (used-styles)
555 (dolist (style styles)
556 (let ((include-regexp (muse-style-element :include style))
557 (exclude-regexp (muse-style-element :exclude style)))
558 (when (and (or ignore-regexp
559 (and (null include-regexp)
560 (null exclude-regexp))
561 (if include-regexp
562 (string-match include-regexp file)
563 (not (string-match exclude-regexp file))))
564 (or (not (file-exists-p file))
565 (not (muse-project-private-p file))))
566 (setq used-styles (cons style used-styles)))))
567 (nreverse used-styles))))
569 (defun muse-project-publish-file (file styles &optional force ignore-regexp)
570 (setq styles (muse-project-applicable-styles file styles ignore-regexp))
571 (let (published)
572 (dolist (style styles)
573 (let ((output-dir (muse-style-element :path style)))
574 ;; ensure the publishing location is available
575 (unless (file-exists-p output-dir)
576 (message "Creating publishing directory %s" output-dir)
577 (make-directory output-dir t))
578 ;; publish the member file!
579 (if (muse-publish-file file style output-dir force)
580 (setq published t))))
581 published))
583 (defun muse-project-save-buffers (&optional project)
584 (setq project (muse-project project))
585 (map-y-or-n-p
586 (function
587 (lambda (buffer)
588 (and (buffer-modified-p buffer)
589 (not (buffer-base-buffer buffer))
590 (or (buffer-file-name buffer)
591 (progn
592 (set-buffer buffer)
593 (and buffer-offer-save
594 (> (buffer-size) 0))))
595 (with-current-buffer buffer
596 (let ((proj (muse-project-of-file)))
597 (and proj (string= (car proj)
598 (car project)))))
599 (if (buffer-file-name buffer)
600 (format "Save file %s? "
601 (buffer-file-name buffer))
602 (format "Save buffer %s? "
603 (buffer-name buffer))))))
604 (function
605 (lambda (buffer)
606 (set-buffer buffer)
607 (save-buffer)))
608 (buffer-list)
609 '("buffer" "buffers" "save")
610 (if (boundp 'save-some-buffers-action-alist)
611 save-some-buffers-action-alist)))
613 ;;;###autoload
614 (defun muse-project-publish (project &optional force)
615 "Publish the pages of PROJECT that need publishing."
616 (interactive (list (muse-read-project "Publish project: " nil t)
617 current-prefix-arg))
618 (setq project (muse-project project))
619 (let ((styles (cddr project))
620 (muse-current-project project)
621 published)
622 ;; determine the style from the project, or else ask
623 (unless styles
624 (setq styles (list (muse-publish-get-style))))
625 (unless project
626 (error "Cannot find a project to publish"))
627 ;; prompt to save any buffers related to this project
628 (muse-project-save-buffers project)
629 ;; run hook before publishing begins
630 (run-hook-with-args 'muse-before-project-publish-hook project)
631 ;; publish all files in the project, for each style; the actual
632 ;; publishing will only happen if the files are newer than the
633 ;; last published output, or if the file is listed in
634 ;; :force-publish. Files in :force-publish will not trigger the
635 ;; "All pages need to be published" message.
636 (let ((forced-files (muse-get-keyword :force-publish (cadr project)))
637 (file-alist (muse-project-file-alist project)))
638 (dolist (pair file-alist)
639 (when (muse-project-publish-file (cdr pair) styles force)
640 (setq forced-files (delete (car pair) forced-files))
641 (setq published t)))
642 (dolist (file forced-files)
643 (muse-project-publish-file (cdr (assoc file file-alist)) styles t)))
644 ;; run hook after publishing ends
645 (run-hook-with-args 'muse-after-project-publish-hook project)
646 ;; notify the user that everything is now done
647 (if published
648 (message "All pages in %s have been published." (car project))
649 (message "No pages in %s need publishing at this time."
650 (car project)))))
652 (defun muse-project-batch-publish ()
653 "Publish Muse files in batch mode."
654 (let ((muse-batch-publishing-p t)
655 force)
656 (if (string= "--force" (or (car command-line-args-left) ""))
657 (setq force t
658 command-line-args-left (cdr command-line-args-left)))
659 (if command-line-args-left
660 (dolist (project command-line-args-left)
661 (message "Publishing project %s ..." project)
662 (muse-project-publish project force))
663 (message "No projects specified."))))
665 (eval-when-compile
666 (put 'make-local-hook 'byte-compile nil))
668 (defun muse-project-set-variables ()
669 "Load project-specific variables."
670 (let ((vars (muse-get-keyword :set (cadr muse-current-project)))
671 sym custom-set var)
672 (while vars
673 (setq sym (car vars))
674 (setq custom-set (or (get sym 'custom-set) 'set))
675 (setq var (if (eq (get sym 'custom-type) 'hook)
676 (make-local-hook sym)
677 (make-local-variable sym)))
678 (funcall custom-set var (car (cdr vars)))
679 (setq vars (cdr (cdr vars))))))
681 (defun muse-project-delete-output-files (project)
682 (interactive
683 (list (muse-read-project "Remove all output files for project: " nil t)))
684 (setq project (muse-project project))
685 (let ((file-alist (muse-project-file-alist project))
686 (styles (cddr project))
687 output-file path)
688 (dolist (entry file-alist)
689 (dolist (style styles)
690 (setq output-file
691 (and (setq path (muse-style-element :path style))
692 (expand-file-name
693 (concat (muse-style-element :prefix style)
694 (car entry)
695 (or (muse-style-element :osuffix style)
696 (muse-style-element :suffix style)))
697 path)))
698 (if output-file
699 (muse-delete-file-if-exists output-file))))))
701 (provide 'muse-project)
703 ;;; muse-project.el ends here