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.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse Project Maintainance
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 (require 'muse-publish
)
38 (defgroup muse-project nil
39 "Options controlling the behavior of Muse project handling."
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)"
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)"
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
)
63 (unless (muse-project ,project
)
64 (error "Can't find project %s" ,project
))
67 (setq muse-current-project
(muse-project ,project
))
68 (muse-project-set-variables)
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."
77 (setq muse-project-alist-using-customize t
)
78 (let* ((val (copy-alist (symbol-value sym
)))
81 (let ((head (car (cdar val
)))
83 ;; Turn settings of first part into cons cells, symbol->string
85 (cond ((stringp (car head
))
86 (add-to-list 'res
(car head
) t
)
87 (setq head
(cdr head
)))
89 (add-to-list 'res
(list (symbol-name (car head
))
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
98 (let ((head (cadr styles
))
101 (setq res
(plist-put res
(symbol-name (car head
))
103 (setq head
(cddr head
)))
104 (setcdr styles
(cons res
(cddr styles
))))
105 (setq styles
(cdr styles
))))
106 (setq val
(cdr val
)))
109 (defun muse-project-alist-set (sym val
)
110 "Turn customized version of `muse-project-alist' into something
111 Muse can make use of."
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
118 (let ((head (car (cdar val
)))
120 ;; Turn cons cells into flat list, string->symbol
122 (cond ((stringp (car head
))
123 (add-to-list 'res
(car head
) t
))
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
132 (let ((head (cadr styles
))
135 (setq res
(plist-put res
(intern (car 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."
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"
152 (string :tag
"Directory")
153 (list :tag
"Book function"
154 (const :tag
":book-funcall" ":book-funcall")
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")
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")
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")
190 (sexp :tag
"Unknown")))))
191 (repeat :tag
"Styles" :format
"%{%t%}:\n%v%i\n\n"
194 :tag
"Publishing style"
195 (const :tag
":base" ":base")
196 (string :tag
"Style"))
199 (const :tag
":base-url" ":base-url")
202 :tag
"Exclude matching"
203 (const :tag
":exclude" ":exclude")
206 :tag
"Include matching"
207 (const :tag
":include" ":include")
210 :tag
"Timestamps file"
211 (const :tag
":timestamps" ":timestamps")
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")
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}\\|,.*\\|\\.svn\\|"
237 "_darcs\\)\\(/\\|\\'\\)")
238 "A regexp matching files to be ignored in Muse directories.
240 You should set case-fold-search to nil before using this regexp
245 (defun muse-project-recurse-directory (base)
246 "Recusively retrieve all of the directories underneath BASE.
247 A list of these directories is returned.
249 Directories starting with \".\" will be ignored, as well as those
250 which match `muse-project-ignore-regexp'."
251 (let ((case-fold-search nil
)
253 (when (and (file-directory-p base
)
254 (not (string-match muse-project-ignore-regexp base
)))
255 (dolist (file (directory-files base t
"^[^.]"))
256 (when (and (file-directory-p file
)
257 (not (string-match muse-project-ignore-regexp file
)))
258 (setq dir
(file-name-nondirectory file
))
260 (nconc list
(mapcar #'(lambda (item)
261 (concat dir
"/" item
))
262 (muse-project-recurse-directory file
)))))
265 (defun muse-project-alist-styles (entry-dir output-dir style
)
266 "Return a list of styles to use in a `muse-project-alist' entry.
267 ENTRY-DIR is the top-level directory of the project.
268 OUTPUT-DIR is where Muse files are published, keeping directory structure.
269 STYLE is the publishing style to use.
271 For an example of the use of this function, see
272 `examples/mwolson/muse-init.el' from the Muse distribution."
273 (cons `(:base
,style
:path
,(expand-file-name output-dir
)
274 :include
,(concat "/" (file-name-nondirectory entry-dir
)
276 (mapcar (lambda (dir)
278 :path
,(expand-file-name dir output-dir
)
279 :include
,(concat "/" dir
"/[^/]+$")))
280 (muse-project-recurse-directory entry-dir
))))
282 (defun muse-project-alist-dirs (entry-dir)
283 "Return a list of directories to use in a `muse-project-alist' entry.
284 ENTRY-DIR is the top-level directory of the project.
286 For an example of the use of this function, see
287 `examples/mwolson/muse-init.el' from the Muse distribution."
288 (cons (expand-file-name entry-dir
)
289 (mapcar (lambda (dir) (expand-file-name dir entry-dir
))
290 (muse-project-recurse-directory entry-dir
))))
292 ;; Constructing the file-alist
294 (defvar muse-project-file-alist nil
295 "This variable is automagically constructed as needed.")
297 (defvar muse-project-file-alist-hook nil
298 "Functions that are to be exectuted immediately after updating
299 `muse-project-file-alist'.")
301 (defvar muse-current-project nil
302 "Project we are currently visiting.")
303 (make-variable-buffer-local 'muse-current-project
)
305 (defvar muse-current-output-style nil
306 "The output style that we are currently using for publishing files.")
308 (defsubst muse-project
(&optional project
)
309 "Resolve the given PROJECT into a full Muse project, if it is a string."
311 (or muse-current-project
312 (muse-project-of-file))
313 (if (stringp project
)
314 (assoc project muse-project-alist
)
315 (muse-assert (consp project
))
318 (defun muse-project-page-file (page project
&optional no-check-p
)
319 "Return a filename if PAGE exists within the given Muse PROJECT."
320 (setq project
(muse-project project
))
321 (let ((dir (file-name-directory page
)))
322 (when dir
(setq page
(file-name-nondirectory page
)))
323 (let ((files (muse-collect-alist
324 (muse-project-file-alist project no-check-p
)
330 (let ((pos (string-match (concat (regexp-quote dir
) "\\'")
331 (file-name-directory (cdr file
)))))
333 (setq matches
(cons (cons pos
(cdr file
))
335 (car (muse-sort-by-rating matches
)))
337 (setq matches
(cons (cons (length (cdr file
)) (cdr file
))
339 (car (muse-sort-by-rating matches
'<))))))
341 (defun muse-project-private-p (file)
342 "Return non-nil if NAME is a private page with PROJECT."
343 (unless muse-under-windows-p
344 (setq file
(file-truename file
))
345 (if (file-attributes file
) ; don't publish if no attributes exist
346 (or (when (eq ?-
(aref (nth 8 (file-attributes
347 (file-name-directory file
))) 7))
349 "The " (file-name-directory file
)
350 " directory must be readable by others"
351 " in order for its contents to be published.")))
352 (eq ?-
(aref (nth 8 (file-attributes file
)) 7)))
355 (defun muse-project-file-entries (path)
356 (let* ((names (list t
))
358 (case-fold-search nil
))
360 ((file-directory-p path
)
361 (dolist (file (directory-files
362 path t
(when (and muse-file-extension
363 (not (string= muse-file-extension
"")))
364 (concat "." muse-file-extension
"\\'"))))
365 (unless (or (string-match muse-project-ignore-regexp file
)
366 (file-directory-p file
))
368 (cons (cons (muse-page-name file
) file
) nil
))
369 (setq lnames
(cdr lnames
)))))
370 ((file-readable-p path
)
372 (cons (cons (muse-page-name path
) path
) nil
))
373 (setq lnames
(cdr lnames
)))
375 (muse-assert (file-name-directory path
))
376 (dolist (file (directory-files
377 (file-name-directory path
) t
378 (file-name-nondirectory path
)))
379 (unless (string-match muse-project-ignore-regexp file
)
381 (cons (cons (muse-page-name file
) file
) nil
))
382 (setq lnames
(cdr lnames
))))))
385 (defvar muse-updating-file-alist-p nil
386 "Make sure that recursive calls to `muse-project-file-alist' are bounded.")
388 (defun muse-project-file-alist (&optional project no-check-p
)
389 "Return member filenames for the given Muse PROJECT.
390 On UNIX, this list is only updated if one of the directories'
391 contents have changed. On Windows, it is always reread from
393 (setq project
(muse-project project
))
394 (let* ((file-alist (assoc (car project
) muse-project-file-alist
))
395 (last-mod (cdr (cdr file-alist
))))
396 ;; Determine the last modified of any directory mentioned in the
397 ;; project's pattern list
398 (unless (or muse-under-windows-p no-check-p
)
399 (let ((pats (cadr project
)))
401 (if (symbolp (car pats
))
402 (setq pats
(cddr pats
))
403 (let* ((fnd (file-name-directory (car pats
)))
404 (dir (cond ((file-directory-p (car pats
))
406 ((and (not (file-readable-p (car pats
)))
408 (file-directory-p fnd
))
411 (let ((mod-time (nth 5 (file-attributes dir
))))
412 (when (or (null last-mod
)
414 (muse-time-less-p last-mod mod-time
)))
415 (setq last-mod mod-time
)))))
416 (setq pats
(cdr pats
))))))
417 ;; Either return the currently known list, or read it again from
419 (if (or (and no-check-p
(cadr file-alist
))
420 muse-updating-file-alist-p
421 (not (or muse-under-windows-p
422 (null (cddr file-alist
))
424 (muse-time-less-p (cddr file-alist
) last-mod
))))
427 (setcdr (cdr file-alist
) last-mod
)
428 (setq file-alist
(cons (car project
) (cons nil last-mod
))
429 muse-project-file-alist
430 (cons file-alist muse-project-file-alist
)))
431 ;; Read in all of the file entries
432 (let ((muse-updating-file-alist-p t
))
437 (let* ((names (list t
))
438 (pats (cadr project
)))
440 (if (symbolp (car pats
))
441 (setq pats
(cddr pats
))
442 (nconc names
(muse-project-file-entries (car pats
)))
443 (setq pats
(cdr pats
))))
445 (run-hooks 'muse-project-file-alist-hook
))))))
447 (defun muse-project-of-file (&optional pathname
)
448 "Determine which project the given PATHNAME relates to.
449 If PATHNAME is nil, the current buffer's filename is used."
450 (if (and (null pathname
) muse-current-project
)
452 (unless pathname
(setq pathname
(muse-current-file)))
454 (when (and (stringp pathname
)
455 (not (string= pathname
""))
456 (not (let ((case-fold-search nil
))
457 (or (string-match muse-project-ignore-regexp
459 (string-match muse-project-ignore-regexp
460 (file-name-nondirectory
462 (let* ((file (file-truename pathname
))
463 (dir (file-name-directory file
))
464 (project-entry muse-project-alist
)
466 (while (and project-entry
(not found
))
467 (let ((pats (car (cdar project-entry
))))
468 (while (and pats
(not found
))
469 (if (symbolp (car pats
))
470 (setq pats
(cddr pats
))
471 (let ((truename (file-truename (car pats
))))
472 (if (or (string= truename file
)
473 (string= truename dir
)
474 (string-match (regexp-quote truename
) file
))
475 (setq found
(car project-entry
))))
476 (setq pats
(cdr pats
))))
477 (setq project-entry
(cdr project-entry
))))
480 (defun muse-project-after-save-hook ()
481 "Update Muse's file-alist if we are saving a Muse file."
482 (let ((project (muse-project-of-file)))
484 (muse-project-file-alist project
))))
486 (add-hook 'after-save-hook
'muse-project-after-save-hook
)
488 (defun muse-read-project (prompt &optional no-check-p no-assume
)
489 "Read a project name from the minibuffer, if it can't be figured
491 (if (null muse-project-alist
)
492 (error "There are no Muse projects defined; see `muse-project-alist'.")
493 (or (unless no-check-p
494 (muse-project-of-file))
495 (if (and (not no-assume
)
496 (= 1 (length muse-project-alist
)))
497 (car muse-project-alist
)
498 (assoc (completing-read prompt muse-project-alist
)
499 muse-project-alist
)))))
501 (defvar muse-project-page-history nil
)
503 (defun muse-read-project-file (project prompt
&optional default
)
504 (let ((name (completing-read prompt
(muse-project-file-alist project
)
505 nil nil nil
'muse-project-page-history
507 (cons name
(muse-project-page-file name project
))))
510 (defun muse-project-find-file (name project
&optional command directory
)
511 "Open the Muse page given by NAME in PROJECT.
512 If COMMAND is non-nil, it is the function used to visit the file.
513 If DIRECTORY is non-nil, it is the directory in which the page
514 will be created if it does not already exist. Otherwise, the
515 first directory within the project's fileset is used."
517 (let* ((project (muse-read-project "Find in project: "
519 (default (muse-get-keyword :default
(cadr project
)))
520 (entry (muse-read-project-file
522 (format "Find page: (default: %s) "
526 (list entry project
)))
527 (setq project
(muse-project project
))
528 (let ((project-name (car project
)))
529 (unless (interactive-p)
530 (setq project
(muse-project project
)
531 name
(cons name
(muse-project-page-file name project
))))
532 ;; If we're given a relative or absolute filename, open it as-is
535 (or (string-match muse-file-regexp
(car name
))
536 (string-match muse-image-regexp
(car name
)))))
537 (setcdr name
(car name
))
538 ;; At this point, name is (PAGE . FILE).
540 (let ((pats (cadr project
)))
541 (while (and pats
(null directory
))
542 (if (symbolp (car pats
))
543 (setq pats
(cddr pats
))
544 (if (file-directory-p (car pats
))
545 (setq directory
(car pats
) pats nil
)
546 (setq pats
(cdr pats
))))))
548 (let ((filename (expand-file-name
549 (if (and muse-file-extension
550 (not (string= muse-file-extension
"")))
551 (concat (car name
) "." muse-file-extension
)
554 (unless (file-exists-p directory
)
555 (make-directory directory t
))
556 (setcdr name filename
)))))
559 (funcall (or command
'find-file
) (cdr name
))
560 (error "There is no page %s in project %s."
561 (car name
) project-name
))))
563 (defun muse-project-choose-style (closure test styles
)
564 "Run TEST on STYLES and return first style where TEST yields non-nil.
565 TEST should take two arguments. The first is CLOSURE, which is
566 passed verbatim. The second if the current style to consider.
568 If no style passes TEST, return the first style."
570 (dolist (style styles
)
571 (when (funcall test closure style
)
572 (throw 'winner style
))))
575 (defun muse-project-choose-style-by-link-suffix (given-suffix style
)
576 "If the given STYLE has a link-suffix that equals GIVEN-SUFFIX,
578 (let ((link-suffix (muse-style-element :link-suffix style
)))
579 (and (stringp link-suffix
)
580 (string= given-suffix link-suffix
))))
582 (defun muse-project-applicable-styles (file styles
&optional ignore-regexp
)
583 "Given STYLES, return a list of the ones that are considered for FILE.
584 The name of a project may be used for STYLES."
585 (when (stringp styles
)
586 (setq styles
(cddr (muse-project styles
))))
587 (when (and file styles
)
588 (let ((used-styles nil
))
589 (dolist (style styles
)
590 (let ((include-regexp (muse-style-element :include style
))
591 (exclude-regexp (muse-style-element :exclude style
))
593 (when (and (or ignore-regexp
594 (and (null include-regexp
)
595 (null exclude-regexp
))
597 (setq rating
(string-match include-regexp file
))
598 (not (string-match exclude-regexp file
))))
599 (or (not (file-exists-p file
))
600 (not (muse-project-private-p file
))))
601 (setq used-styles
(cons (cons rating style
) used-styles
)))))
602 (muse-sort-by-rating (nreverse used-styles
)))))
604 (defun muse-project-get-applicable-style (file styles
)
605 "Choose a style from the STYLES that FILE can publish to.
606 The user is prompted if several styles are found."
607 (muse-publish-get-style
608 (mapcar (lambda (style)
609 (cons (muse-get-keyword :base style
) style
))
610 (muse-project-applicable-styles file styles
))))
612 (defun muse-project-resolve-link (page local-style remote-styles
)
613 "Return a published relative link from the output path of one file
616 The best match for PAGE is determined by comparing the link
617 suffix of the given local style and that of the remote styles.
619 The remote styles are usually populated by
620 `muse-project-applicable-styles'."
621 (let ((link-suffix (muse-style-element :link-suffix local-style
))
623 (if (not (stringp link-suffix
))
624 (setq remote-style
(car remote-styles
))
625 (setq remote-style
(muse-project-choose-style
627 #'muse-project-choose-style-by-link-suffix
629 (muse-publish-link-file
630 (if (null remote-style
)
632 (let ((prefix (muse-style-element :base-url remote-style
)))
635 (file-relative-name (expand-file-name
636 (file-name-nondirectory page
)
637 (muse-style-element :path remote-style
))
639 (muse-style-element :path local-style
))))))
642 (defun muse-project-current-output-style (&optional file project
)
643 (or muse-current-output-style
645 (unless file
(setq file
(muse-current-file)))
646 (unless project
(setq project
(muse-project-of-file file
)))
647 (car (muse-project-applicable-styles file
(cddr project
))))))
649 (defun muse-project-link-page (page)
650 (let ((project (muse-project-of-file)))
651 (muse-project-resolve-link page
652 (muse-project-current-output-style)
653 (muse-project-applicable-styles
654 (muse-project-page-file page project
)
657 (defun muse-project-publish-file (file styles
&optional force ignore-regexp
)
658 (setq styles
(muse-project-applicable-styles file styles ignore-regexp
))
660 (dolist (style styles
)
661 (let ((output-dir (muse-style-element :path style
))
662 (muse-current-output-style style
))
663 ;; ensure the publishing location is available
664 (unless (file-exists-p output-dir
)
665 (message "Creating publishing directory %s" output-dir
)
666 (make-directory output-dir t
))
667 ;; publish the member file!
668 (if (muse-publish-file file style output-dir force
)
669 (setq published t
))))
673 (defun muse-project-publish-this-file (&optional force
)
674 "Publish the currently-visited file according to `muse-project-alist',
675 prompting if more than one style applies.
677 If FORCE is given, publish the file even if it is up-to-date."
678 (interactive (list current-prefix-arg
))
679 (let* ((style (muse-project-get-applicable-style
680 buffer-file-name
(cddr muse-current-project
)))
681 (output-dir (muse-style-element :path style
)))
682 (unless (muse-publish-file buffer-file-name style output-dir force
)
683 (message (concat "The published version is up-to-date; use"
684 " C-u C-c C-t to force an update.")))))
686 (defun muse-project-save-buffers (&optional project
)
687 (setq project
(muse-project project
))
691 (and (buffer-modified-p buffer
)
692 (not (buffer-base-buffer buffer
))
693 (or (buffer-file-name buffer
)
696 (and buffer-offer-save
697 (> (buffer-size) 0))))
698 (with-current-buffer buffer
699 (let ((proj (muse-project-of-file)))
700 (and proj
(string= (car proj
)
702 (if (buffer-file-name buffer
)
703 (format "Save file %s? "
704 (buffer-file-name buffer
))
705 (format "Save buffer %s? "
706 (buffer-name buffer
))))))
712 '("buffer" "buffers" "save")
713 (if (boundp 'save-some-buffers-action-alist
)
714 save-some-buffers-action-alist
)))
717 (defun muse-project-publish (project &optional force
)
718 "Publish the pages of PROJECT that need publishing."
719 (interactive (list (muse-read-project "Publish project: " nil t
)
721 (setq project
(muse-project project
))
722 (let ((styles (cddr project
))
723 (muse-current-project project
)
725 ;; determine the style from the project, or else ask
727 (setq styles
(list (muse-publish-get-style))))
729 (error "Cannot find a project to publish"))
730 ;; prompt to save any buffers related to this project
731 (muse-project-save-buffers project
)
732 ;; run hook before publishing begins
733 (run-hook-with-args 'muse-before-project-publish-hook project
)
734 ;; publish all files in the project, for each style; the actual
735 ;; publishing will only happen if the files are newer than the
736 ;; last published output, or if the file is listed in
737 ;; :force-publish. Files in :force-publish will not trigger the
738 ;; "All pages need to be published" message.
739 (let ((forced-files (muse-get-keyword :force-publish
(cadr project
)))
740 (file-alist (muse-project-file-alist project
)))
741 (dolist (pair file-alist
)
742 (when (muse-project-publish-file (cdr pair
) styles force
)
743 (setq forced-files
(delete (car pair
) forced-files
))
745 (dolist (file forced-files
)
746 (muse-project-publish-file (cdr (assoc file file-alist
)) styles t
)))
747 ;; run hook after publishing ends
748 (run-hook-with-args 'muse-after-project-publish-hook project
)
749 ;; notify the user that everything is now done
751 (message "All pages in %s have been published." (car project
))
752 (message "No pages in %s need publishing at this time."
755 (defun muse-project-batch-publish ()
756 "Publish Muse files in batch mode."
757 (let ((muse-batch-publishing-p t
)
759 (if (string= "--force" (or (car command-line-args-left
) ""))
761 command-line-args-left
(cdr command-line-args-left
)))
762 (if command-line-args-left
763 (dolist (project command-line-args-left
)
764 (message "Publishing project %s ..." project
)
765 (muse-project-publish project force
))
766 (message "No projects specified."))))
769 (put 'make-local-hook
'byte-compile nil
))
771 (defun muse-project-set-variables ()
772 "Load project-specific variables."
773 (let ((vars (muse-get-keyword :set
(cadr muse-current-project
)))
776 (setq sym
(car vars
))
777 (setq custom-set
(or (get sym
'custom-set
) 'set
))
778 (setq var
(if (eq (get sym
'custom-type
) 'hook
)
779 (make-local-hook sym
)
780 (make-local-variable sym
)))
781 (funcall custom-set var
(car (cdr vars
)))
782 (setq vars
(cdr (cdr vars
))))))
784 (defun muse-project-delete-output-files (project)
786 (list (muse-read-project "Remove all output files for project: " nil t
)))
787 (setq project
(muse-project project
))
788 (let ((file-alist (muse-project-file-alist project
))
789 (styles (cddr project
))
791 (dolist (entry file-alist
)
792 (dolist (style styles
)
794 (and (setq path
(muse-style-element :path style
))
796 (concat (muse-style-element :prefix style
)
798 (or (muse-style-element :osuffix style
)
799 (muse-style-element :suffix style
)))
802 (muse-delete-file-if-exists output-file
))))))
804 (provide 'muse-project
)
806 ;;; muse-project.el ends here