From fb7dde2cd10a358f84e491448801a21ca90416a9 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Fri, 22 Dec 2006 04:53:16 +0000 Subject: [PATCH] manual: Update book example * examples/johnw/muse-johnw.el: Update for preferred muse-derive-style usage. Rename to muse-init.el. * examples/mwolson/muse-init.el: Update. * lisp/muse-book.el (muse-book-publish-p): New function split from muse-book-publish. (muse-book-get-directives): New function that retrieves the publishing directives from the given file. (muse-book-publish): Use muse-book-get-directives to set the title if no title was specified. * texi/muse.texi (Book): Mention new way to publish books and provide an example, since the process may be non-obvious. git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-259 --- ChangeLog | 13 +++++ examples/johnw/{muse-johnw.el => muse-init.el} | 45 +++++++++-------- examples/mwolson/muse-init.el | 20 ++++---- lisp/muse-book.el | 68 +++++++++++++++++--------- texi/muse.texi | 48 ++++++++++++++++-- 5 files changed, 136 insertions(+), 58 deletions(-) rename examples/johnw/{muse-johnw.el => muse-init.el} (93%) diff --git a/ChangeLog b/ChangeLog index df4c3b3..9afc118 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,18 @@ 2006-12-21 Michael Olson + * examples/johnw/muse-johnw.el: Update for preferred + muse-derive-style usage. Rename to muse-init.el. + + * examples/mwolson/muse-init.el: Update. + * lisp/muse-book.el (muse-book-publish): New function split from muse-book-publish-project. This is used in the definitions for the book-latex and book-pdf styles. + (muse-book-publish-p): New function split from muse-book-publish. + (muse-book-get-directives): New function that retrieves the + publishing directives from the given file. + (muse-book-publish): Use muse-book-get-directives to set the title + if no title was specified. * lisp/muse-project.el (muse-project): Add :publish-project entry to widget. @@ -20,6 +30,9 @@ * lisp/muse-publish.el (muse-publish-file): Message fix. + * texi/muse.texi (Book): Mention new way to publish books and + provide an example, since the process may be non-obvious. + 2006-12-20 Michael Olson * lisp/muse-docbook.el (muse-docbook-munge-buffer): Split out diff --git a/examples/johnw/muse-johnw.el b/examples/johnw/muse-init.el similarity index 93% rename from examples/johnw/muse-johnw.el rename to examples/johnw/muse-init.el index 694f0c9..5ef9eb4 100644 --- a/examples/johnw/muse-johnw.el +++ b/examples/johnw/muse-init.el @@ -47,29 +47,28 @@ (setcdr (assq 'url-with-image muse-latex-markup-strings) "%% %s\n\\includegraphics[scale=0.6]{../%s}") -(unless (assoc "site-html" muse-publishing-styles) - (muse-derive-style "site-html" "html" - :maintainer "jwiegley@hotmail.com" - :before 'muse-maybe-convert-poem - :after 'muse-my-html-finalize-buffer - :final 'muse-site-html-set-mode - :header "~/Documents/site/header.html" - :footer "~/Documents/site/footer.html") - (muse-derive-style "site-journal-html" "journal-html" - :maintainer "jwiegley@hotmail.com" - :before 'muse-my-journal-find-entries - :after 'muse-my-journal-insert-contents - :final 'muse-site-html-set-mode - :header "~/Documents/site/header.html" - :footer "~/Documents/site/footer.html") - (muse-derive-style "newartisans-html" "html" - :maintainer "johnw@newartisans.com" - :header "~/Sites/newartisans/header.html" - :footer "~/Sites/newartisans/footer.html") - (muse-derive-style "newartisans-journal-html" "journal-html" - :maintainer "johnw@newartisans.com" - :header "~/Sites/newartisans/header.html" - :footer "~/Sites/newartisans/footer.html")) +(muse-derive-style "site-html" "html" + :maintainer "jwiegley@hotmail.com" + :before 'muse-maybe-convert-poem + :after 'muse-my-html-finalize-buffer + :final 'muse-site-html-set-mode + :header "~/Documents/site/header.html" + :footer "~/Documents/site/footer.html") +(muse-derive-style "site-journal-html" "journal-html" + :maintainer "jwiegley@hotmail.com" + :before 'muse-my-journal-find-entries + :after 'muse-my-journal-insert-contents + :final 'muse-site-html-set-mode + :header "~/Documents/site/header.html" + :footer "~/Documents/site/footer.html") +(muse-derive-style "newartisans-html" "html" + :maintainer "johnw@newartisans.com" + :header "~/Sites/newartisans/header.html" + :footer "~/Sites/newartisans/footer.html") +(muse-derive-style "newartisans-journal-html" "journal-html" + :maintainer "johnw@newartisans.com" + :header "~/Sites/newartisans/header.html" + :footer "~/Sites/newartisans/footer.html") (custom-set-variables '(muse-project-alist diff --git a/examples/mwolson/muse-init.el b/examples/mwolson/muse-init.el index bc7c8dd..e8d6399 100644 --- a/examples/mwolson/muse-init.el +++ b/examples/mwolson/muse-init.el @@ -32,17 +32,17 @@ ;; Here is an example of making a customized version of your favorite ;; publisher. All this does is run `my-muse-blosoxm-finalize' on the ;; published file immediately after saving it. +(muse-derive-style "my-blosxom" "blosxom-xhtml" + :final 'my-muse-blosxom-finalize) -(unless (assoc "my-blosxom" muse-publishing-styles) - (muse-derive-style "my-blosxom" "blosxom-xhtml" - :final 'my-muse-blosxom-finalize) +;; This turns relative links into absolute links +(muse-derive-style "my-pdf" "pdf" + :before 'my-muse-pdf-prepare-buffer) - (muse-derive-style "my-pdf" "pdf" - :before 'my-muse-pdf-prepare-buffer) - - (muse-derive-style "my-xhtml" "xhtml" - :header "~/personal-site/muse/header.html" - :footer "~/personal-site/muse/footer.html")) +;; This uses a different header and footer than normal +(muse-derive-style "my-xhtml" "xhtml" + :header "~/personal-site/muse/header.html" + :footer "~/personal-site/muse/footer.html") ;; Here is my master project listing. @@ -116,7 +116,7 @@ ("ArchWiki" . "http://gnuarch.org/gnuarchwiki/") ;; abbreviations ("CERIAS" . "http://www.cerias.purdue.edu/") - ("PlannerMode" . "http://www.plannerlove.com/") + ("PlannerMode" . "http://www.emacswiki.org/cgi-bin/wiki/PlannerMode") ("RememberMode" . "http://www.emacswiki.org/cgi-bin/wiki/RememberMode") ("GP2X" . "http://www.gp2x.co.uk/") ("UbuntuLinux" . "http://ubuntulinux.org/") diff --git a/lisp/muse-book.el b/lisp/muse-book.el index d1bd9ff..506b83a 100644 --- a/lisp/muse-book.el +++ b/lisp/muse-book.el @@ -34,6 +34,7 @@ (require 'muse-publish) (require 'muse-project) (require 'muse-latex) +(require 'muse-regexps) (defgroup muse-book nil "Module for publishing a series of Muse pages as a complete book. @@ -109,6 +110,42 @@ but treating the page as if it were a single chapter within a book." (muse-style-run-hooks :after style)) (goto-char end))) +(defun muse-book-publish-p (project target) + "Determine whether the book in PROJECT is out-of-date." + (let ((pats (cadr project))) + (catch 'publish + (while pats + (if (symbolp (car pats)) + (if (eq :book-end (car pats)) + (throw 'publish nil) + ;; skip past symbol-value pair + (setq pats (cddr pats))) + (dolist (entry (muse-project-file-entries (car pats))) + (when (and (not (muse-project-private-p (cdr entry))) + (file-newer-than-file-p (cdr entry) target)) + (throw 'publish t))) + (setq pats (cdr pats))))))) + +(defun muse-book-get-directives (file) + "Interpret any publishing directives contained in FILE. +This is meant to be called in a temp buffer that will later be +used for publishing." + (save-restriction + (narrow-to-region (point) (point)) + (unwind-protect + (progn + (insert-file-contents file) + (muse-publish-markup + "attributes" + `(;; Remove leading and trailing whitespace from the file + (100 "\\(\\`\n+\\|\n+\\'\\)" 0 "") + ;; Remove trailing whitespace from all lines + (200 ,(concat "[" muse-regexp-blank "]+$") 0 "") + ;; Handle any leading #directives + (300 "\\`#\\([a-zA-Z-]+\\)\\s-+\\(.+\\)\n+" + 0 muse-publish-markup-directive)))) + (delete-region (point-min) (point-max))))) + (defun muse-book-publish-project (project book title style &optional output-dir force) "Publish PROJECT under the name BOOK with the given TITLE and STYLE. @@ -139,52 +176,39 @@ changed since it was last published." (setq style (muse-style style)) (unless style (error "There is no style '%s' defined" style-name))) - (unless title - (setq title (muse-page-name file))) ;; Publish each page in the project as a chapter in one large book (let* ((output-path (muse-publish-output-file file output-dir style)) (output-suffix (muse-style-element :osuffix style)) (target output-path) (project muse-current-project) - (pats (cadr project)) - (publish force) (published nil)) (when output-suffix (setq target (concat (muse-path-sans-extension target) output-suffix))) ;; Unless force is non-nil, determine if the book needs publishing - (unless force - (while pats - (if (symbolp (car pats)) - (if (eq :book-end (car pats)) - (setq pats nil) - (setq pats (cddr pats))) - (let ((entries (muse-project-file-entries (car pats)))) - (while entries - (if (and (not (muse-project-private-p (cdar entries))) - (file-newer-than-file-p (cdar entries) target)) - (setq publish t entries nil) - (setq entries (cdr entries))))) - (setq pats (cdr pats))))) - ;; Create the book from all its component parts - (if (not publish) + (if (and (not force) + (not (muse-book-publish-p project target))) (message "The book \"%s\" is up-to-date." file) + ;; Create the book from all its component parts (muse-with-temp-buffer (let ((style-final (muse-style-element :final style t)) (style-header (muse-style-element :header style)) (style-footer (muse-style-element :footer style)) (muse-publishing-current-style style) (muse-publishing-directives - (list (cons "title" title) + (list (cons "title" (or title (muse-page-name file))) (cons "date" (format-time-string "%B %e, %Y")))) (muse-publishing-p t) (muse-current-project project) - nochapters) + (pats (cadr project)) + (nochapters nil)) (run-hooks 'muse-before-book-publish-hook) - (setq pats (cadr project)) (let ((style-final style-final) (style-header style-header) (style-footer style-footer)) + (unless title + (muse-book-get-directives file) + (setq title (muse-publishing-directive "title"))) (while pats (if (symbolp (car pats)) (cond diff --git a/texi/muse.texi b/texi/muse.texi index f2ee938..be44f1b 100644 --- a/texi/muse.texi +++ b/texi/muse.texi @@ -1360,9 +1360,51 @@ Each page will become a separate chapter in the book, unless the style keyword @option{:nochapters} is used, in which case they are all run together as if one giant chapter. -You will need to call the @code{muse-book-publish-project} function in -order to publish this style. An example of this may be found in John -Wiegley's configuration file at @file{examples/johnw/muse-johnw.el}. +One way of publishing a book is to make a project for it, add the +project to @code{muse-project-alist}, and use the @code{book-pdf} style +with a very specific @code{:include} value to specify some page whose +contents will be checked for the values of @code{#title} and +@code{#date}, and whose name will be used in the output file. Then to +publish the book, visit the aforementioned page and use @kbd{C-c C-t} or +@kbd{C-c C-p} to trigger the publishing process. An example +@code{muse-project-alist} for this method follows. + +@example +(setq muse-project-alist + '(("MyNotes" (:nochapters t ; do automatically add chapters + :book-chapter "Computer Science" + "~/Notes/cs" + :book-chapter "Mathematics" + "~/Notes/math" + :book-chapter "Emacs" + "~/Notes/emacs" + :book-end t ; the rest will not be placed in the book + "~/Notes" ; so we can find the notes-anthology page + "~/Notes/private" + :force-publish ("index") + :default "index") + (:base "book-pdf" + :include "/notes-anthology[^/]*$" + :path "~/public_html/notes") + ;; other publishing styles for each directory go here, + ;; if desired + ))) +@end example + +In this example, there would be a file called +@file{~/Notes/notes-anthology.muse}, which would contain just the +following. The resulting book would be published to +@file{~/public_html/notes/notes-anthology.pdf}. + +@example +#title My Technology Ramblings +@end example + +Another way is to call the @code{muse-book-publish-project} function +manually, with a custom project entry. An example of this may be found +in John Wiegley's configuration file at +@file{examples/johnw/muse-init.el}, in the @code{muse-publish-my-books} +function. @subheading Styles provided -- 2.11.4.GIT