emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] <include> functionality


From: G.J. Teale
Subject: [emacs-wiki-discuss] <include> functionality
Date: Tue, 17 Jan 2006 17:49:00 +0000
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

I mentioned I'd done this on IRC about a week or so ago (time flies...).  

Please find attached a diff for muse-publish.el that provides some
basic <include> functionality.

Basically you place that line:

<include file="../path/to/your/include.file"/>

... anywhere in a muse file and it will pull the contents of the
stated file in prior to doing any further processing on the file.

Includes within the included file also work (*yay*), but be warned
this potentially leads to infinite loops (*boo*). 

--- orig/lisp/muse-publish.el
+++ mod/lisp/muse-publish.el
@@ -588,6 +588,23 @@
     (concat (file-name-directory file)
             (muse-publish-link-name file style))))
 
+(defun muse-process-next-include ()
+  "Convert the next <include> statement into content"
+  (if (re-search-forward 
+       "<include\\ file=\"\\(.*\\)\".*\/>"
+       nil t)
+      (let ((start (match-beginning 0))
+           (end (match-end 0))
+           (filename (match-string 1)))
+       (delete-region start end)
+       (insert-file-contents-literally (substring-no-properties filename)))
+    nil))
+
+(defun muse-process-all-includes-in-buffer ()
+  "Pull in data from <included> files"
+  (beginning-of-buffer)
+  (while (muse-process-next-include)))
+
 ;;;###autoload
 (defun muse-publish-file (file style &optional output-dir force)
   "Publish the given FILE in a particular STYLE to OUTPUT-DIR.
@@ -611,12 +628,14 @@
                   muse-publish-report-threshhold))
           (message "Publishing %s ..." file))
       (muse-with-temp-buffer
-        (insert-file-contents file)
-        (muse-publish-markup-buffer (muse-page-name file) style)
-        (let ((backup-inhibited t))
-          (write-file output-path))
-        (muse-style-run-hooks :final style file output-path target))
-      t)))
+       (insert-file-contents file)
+       (progn
+         (muse-process-all-includes-in-buffer)
+         (muse-publish-markup-buffer (muse-page-name file) style)
+         (let ((backup-inhibited t))
+           (write-file output-path))
+         (muse-style-run-hooks :final style file output-path target))
+       t))))
 
 ;;;###autoload
 (defun muse-publish-this-file (style output-dir &optional force)

-- 
G. J. Teale
Software Engineering Team Leader

Cmed Group Ltd.
Holmwood, Broadlands Business Campus,
Langhurstwood Road, Horsham, RH12 4QP, United Kingdom

T +44(0)1403 755 071
F +44(0)1403 755 051
M +44(0)7914 850 491
E address@hidden  
W www.cmedresearch.com
__________________________________________________________

Driven by technology. Guided by experience.
__________________________________________________________
Now I lay me down to sleep
I hear the sirens in the street
All my dreams are made of chrome
I have no way to get back home
- Tom Waits

reply via email to

[Prev in Thread] Current Thread [Next in Thread]