Browse Source

Implement include files for export.

Carsten Dominik 17 years ago
parent
commit
a738e446be
5 changed files with 106 additions and 8 deletions
  1. 4 0
      ChangeLog
  2. 43 3
      ORGWEBPAGE/Changes.org
  3. 20 2
      doc/org.texi
  4. 37 2
      lisp/org-exp.el
  5. 2 1
      lisp/org.el

+ 4 - 0
ChangeLog

@@ -1,5 +1,9 @@
 2008-05-07  Carsten Dominik  <dominik@science.uva.nl>
 2008-05-07  Carsten Dominik  <dominik@science.uva.nl>
 
 
+	* lisp/org-exp.el (org-export-handle-include-files): New function.
+	(org-export-preprocess-string): Call
+	`org-export-handle-include-files'.
+
 	* lisp/org.el (org-delete-property-globally)
 	* lisp/org.el (org-delete-property-globally)
 	(org-delete-property, org-set-property): Ignore case during
 	(org-delete-property, org-set-property): Ignore case during
 	completion.
 	completion.

+ 43 - 3
ORGWEBPAGE/Changes.org

@@ -10,8 +10,15 @@
 
 
 * Version 6.03
 * Version 6.03
 
 
+** Overview
+
 ** Incompatible changes
 ** Incompatible changes
 
 
+*** The in-buffer settings keywords may now be upper or lower case
+    
+    From now on, it makes no difference is you write =#+STARTUP=
+    or =#+startup=, similarly for all the in-buffer keywords.
+
 *** The text before the first headline is now exported by default
 *** The text before the first headline is now exported by default
 
 
     Previously, the default was to not include this text, but for
     Previously, the default was to not include this text, but for
@@ -52,10 +59,10 @@
 
 
     For quoting an entire paragraph as a citation, use
     For quoting an entire paragraph as a citation, use
 
 
-    : #+BEGIN_BLOCKQUOTE
+    : #+BEGIN_QUOTE
     : Everything shound be made as simple as possible,
     : Everything shound be made as simple as possible,
     : but not any simpler -- Albert Einstein
     : but not any simpler -- Albert Einstein
-    : #+BEGIN_BLOCKQUOTE
+    : #+BEGIN_QUOTE
 
 
 *** Clock task history, and moving entries with the running clock
 *** Clock task history, and moving entries with the running clock
 
 
@@ -94,6 +101,17 @@
     :   (if a (not b) b))
     :   (if a (not b) b))
     : #+END_SRC
     : #+END_SRC
 
 
+    In the export, this will then look like this (if you are now
+    looking at the ASCII export and do not see anything
+    interesting, go and check out the HTML version at
+    http://orgmode.org/Changes.html).
+
+#+BEGIN_SRC emacs-lisp
+(defun org-xor (a b)
+  "Exclusive or."
+  (if a (not b) b))
+#+END_SRC
+
     The string after the BEGIN_SRC is the name of the major emacs
     The string after the BEGIN_SRC is the name of the major emacs
     mode that should be used to fontify the code example.
     mode that should be used to fontify the code example.
 
 
@@ -101,12 +119,34 @@
     /htmlize.el/ package, version 1.34 or later.  For other
     /htmlize.el/ package, version 1.34 or later.  For other
     backends, such structures are simply exported as EXAMPLE.
     backends, such structures are simply exported as EXAMPLE.
 
 
+*** Include files for export
+
+    A line like
+
+    : #+INCLUDE: "file" markup lang
+
+    will lead to the inclusion of the contents of FILE at the
+    moment of publishing.  FILE ahould be surrounded by double
+    quotes, this is obligatory it if contains space characters.
+    The parameters MARKUP and LANG are optional.  MARKUP can be
+    "example", "quote", or "src".  If it is "src", LANG should be
+    the name of the Emacs mode that should be used for fontifying
+    the code.  For example:
+
+    : Here is my /.emacs/ file:
+    : #+include "~/.emacs" src emacs-lisp
+
 *** BBDB anniversaries much faster
 *** BBDB anniversaries much faster
+
     `bbdb-anniversaries' is now much faster, thanks to a new
     `bbdb-anniversaries' is now much faster, thanks to a new
     approach using a hash for birthdays.  Thanks to Thomas
     approach using a hash for birthdays.  Thanks to Thomas
     Baumann for a patch to this effect.
     Baumann for a patch to this effect.
 
 
-*** org-eval.el
+*** New file in the contrib directory: org-eval.el
+
+    This module allowes to include the result of the evaluation
+    of Lisp code into the buffer.  This is similar to the Muse
+    <lisp> tag.
 
 
 *** Bug fixes...
 *** Bug fixes...
 
 

+ 20 - 2
doc/org.texi

@@ -292,6 +292,7 @@ Markup rules
 * Lists::                       Plain lists are exported
 * Lists::                       Plain lists are exported
 * Paragraphs::                  What determines beginning and ending
 * Paragraphs::                  What determines beginning and ending
 * Literal examples::            Source code and other examples
 * Literal examples::            Source code and other examples
+* Include files::               Include the contents of a file during export
 * Tables exported::             Tables are exported richly
 * Tables exported::             Tables are exported richly
 * Footnotes::                   Numbers like [1]
 * Footnotes::                   Numbers like [1]
 * Emphasis and monospace::      To bold or not to bold
 * Emphasis and monospace::      To bold or not to bold
@@ -6608,6 +6609,7 @@ markup rule used in an Org mode buffer.
 * Lists::                       Plain lists are exported
 * Lists::                       Plain lists are exported
 * Paragraphs::                  What determines beginning and ending
 * Paragraphs::                  What determines beginning and ending
 * Literal examples::            Source code and other examples
 * Literal examples::            Source code and other examples
+* Include files::               Include the contents of a file during export
 * Tables exported::             Tables are exported richly
 * Tables exported::             Tables are exported richly
 * Footnotes::                   Numbers like [1]
 * Footnotes::                   Numbers like [1]
 * Emphasis and monospace::      To bold or not to bold
 * Emphasis and monospace::      To bold or not to bold
@@ -6715,7 +6717,7 @@ but not any simpler -- Albert Einstein
 #+end_quote
 #+end_quote
 @end example
 @end example
 
 
-@node Literal examples, Tables exported, Paragraphs, Markup rules
+@node Literal examples, Include files, Paragraphs, Markup rules
 @subheading Literal examples
 @subheading Literal examples
 
 
 You can include literal examples that should not be subjected to
 You can include literal examples that should not be subjected to
@@ -6751,7 +6753,23 @@ example:
 #+end_src
 #+end_src
 @end example
 @end example
 
 
-@node Tables exported, Footnotes, Literal examples, Markup rules
+@node Include files, Tables exported, Literal examples, Markup rules
+@subheading Include files
+
+During export, you can include the content of another file.  For example, to
+include your .emacs file, you could use:
+
+@example
+#+include "~/.emacs" src emacs-lisp
+@end example
+
+The optional second and third parameter are the markup (@samp{quote},
+@samp{example}, or @samp{src}), and, if the markup is @samp{src}, the
+language for formatting the contents.  The markup is optional, if it is not
+given, the text will be assumed to be in Org mode format and will be
+processed normally.
+
+@node Tables exported, Footnotes, Include files, Markup rules
 @subheading Tables
 @subheading Tables
 
 
 Both the native Org mode tables (@pxref{Tables}) and tables formatted with
 Both the native Org mode tables (@pxref{Tables}) and tables formatted with

+ 37 - 2
lisp/org-exp.el

@@ -707,7 +707,7 @@ modified) list.")
 		  (mapcar 'car org-export-inbuffer-options-extra))))
 		  (mapcar 'car org-export-inbuffer-options-extra))))
 	    p key val text options js-up js-main js-css js-opt a pr)
 	    p key val text options js-up js-main js-css js-opt a pr)
 	(while (re-search-forward re nil t)
 	(while (re-search-forward re nil t)
-	  (setq key (org-match-string-no-properties 1)
+	  (setq key (upcase (org-match-string-no-properties 1))
 		val (org-match-string-no-properties 2))
 		val (org-match-string-no-properties 2))
 	  (cond
 	  (cond
 	   ((setq a (assoc key org-export-inbuffer-options-extra))
 	   ((setq a (assoc key org-export-inbuffer-options-extra))
@@ -1197,6 +1197,9 @@ on this string to produce the exported version."
       (let ((org-inhibit-startup t)) (org-mode))
       (let ((org-inhibit-startup t)) (org-mode))
       (untabify (point-min) (point-max))
       (untabify (point-min) (point-max))
 
 
+      ;; Handle incude files
+      (org-export-handle-include-files)
+
       ;; Handle source code snippets
       ;; Handle source code snippets
       (org-export-replace-src-segments)
       (org-export-replace-src-segments)
 
 
@@ -1321,7 +1324,7 @@ on this string to produce the exported version."
 
 
       ;; Blockquotes
       ;; Blockquotes
       (goto-char (point-min))
       (goto-char (point-min))
-      (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)quote\\>.*" nil t)
+      (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t)
 	(replace-match (if (equal (downcase (match-string 1)) "end")
 	(replace-match (if (equal (downcase (match-string 1)) "end")
 			   "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
 			   "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
 			 t t))
 			 t t))
@@ -1566,6 +1569,38 @@ When LEVEL is non-nil, increase section numbers on that level."
 	  (setq string (replace-match "" t nil string))))
 	  (setq string (replace-match "" t nil string))))
     string))
     string))
 
 
+;;; Include files
+
+(defun org-export-handle-include-files ()
+  "Include the contents of include files, with proper formatting."
+  (let (params file markup lang start end)
+    (goto-char (point-min))
+    (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
+      (setq params (read (concat "(" (match-string 1) ")"))
+	    file (org-symname-or-string (pop params))
+	    markup (org-symname-or-string (pop params))
+	    lang (org-symname-or-string (pop params)))
+      (delete-region (match-beginning 0) (match-end 0))
+      (if (or (not file)
+	      (not (file-exists-p file))
+	      (not (file-readable-p file)))
+	  (insert (format "CANNOT INCLUDE FILE %s" file))
+	(when markup
+	  (if (equal (downcase markup) "src")
+	      (setq start (format "#+begin_src %s\n" (or lang "fundamental"))
+		    end "#+end_src")
+	    (setq start (format "#+begin_%s\n" markup)
+		  end  (format "#+end_%s" markup))))
+	(insert (or start ""))
+	(forward-char (nth 1 (insert-file-contents (expand-file-name file))))
+	(or (bolp) (newline))
+	(insert (or end ""))))))
+
+(defun org-symname-or-string (s)
+  (if (symbolp s)
+      (if s (symbol-name s) s)
+    s))
+
 ;;; Fontification of code
 ;;; Fontification of code
 ;; Currently only for th HTML backend, but who knows....
 ;; Currently only for th HTML backend, but who knows....
 (defun org-export-replace-src-segments ()
 (defun org-export-replace-src-segments ()

+ 2 - 1
lisp/org.el

@@ -2712,7 +2712,8 @@ means to push this value onto the list in the variable.")
 	  (widen)
 	  (widen)
 	  (goto-char (point-min))
 	  (goto-char (point-min))
 	  (while (re-search-forward re nil t)
 	  (while (re-search-forward re nil t)
-	    (setq key (match-string 1) value (org-match-string-no-properties 2))
+	    (setq key (upcase (match-string 1))
+		  value (org-match-string-no-properties 2))
 	    (cond
 	    (cond
 	     ((equal key "CATEGORY")
 	     ((equal key "CATEGORY")
 	      (if (string-match "[ \t]+$" value)
 	      (if (string-match "[ \t]+$" value)