From a738e446bed40451b193b75cc3f9dc66ee1b0eed Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 7 May 2008 13:57:00 +0200 Subject: [PATCH] Implement include files for export. --- ChangeLog | 4 ++++ ORGWEBPAGE/Changes.org | 46 +++++++++++++++++++++++++++++++++++++++++++--- doc/org.texi | 22 ++++++++++++++++++++-- lisp/org-exp.el | 39 +++++++++++++++++++++++++++++++++++++-- lisp/org.el | 3 ++- 5 files changed, 106 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 500c6cf56..3773159be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2008-05-07 Carsten Dominik + * 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) (org-delete-property, org-set-property): Ignore case during completion. diff --git a/ORGWEBPAGE/Changes.org b/ORGWEBPAGE/Changes.org index 90a811145..dcc1061a3 100644 --- a/ORGWEBPAGE/Changes.org +++ b/ORGWEBPAGE/Changes.org @@ -10,8 +10,15 @@ * Version 6.03 +** Overview + ** 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 Previously, the default was to not include this text, but for @@ -52,10 +59,10 @@ For quoting an entire paragraph as a citation, use - : #+BEGIN_BLOCKQUOTE + : #+BEGIN_QUOTE : Everything shound be made as simple as possible, : but not any simpler -- Albert Einstein - : #+BEGIN_BLOCKQUOTE + : #+BEGIN_QUOTE *** Clock task history, and moving entries with the running clock @@ -94,6 +101,17 @@ : (if a (not b) b)) : #+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 mode that should be used to fontify the code example. @@ -101,12 +119,34 @@ /htmlize.el/ package, version 1.34 or later. For other 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' is now much faster, thanks to a new approach using a hash for birthdays. Thanks to Thomas 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 + tag. *** Bug fixes... diff --git a/doc/org.texi b/doc/org.texi index 040c2f05c..9400d86fc 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -292,6 +292,7 @@ Markup rules * Lists:: Plain lists are exported * Paragraphs:: What determines beginning and ending * Literal examples:: Source code and other examples +* Include files:: Include the contents of a file during export * Tables exported:: Tables are exported richly * Footnotes:: Numbers like [1] * 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 * Paragraphs:: What determines beginning and ending * Literal examples:: Source code and other examples +* Include files:: Include the contents of a file during export * Tables exported:: Tables are exported richly * Footnotes:: Numbers like [1] * Emphasis and monospace:: To bold or not to bold @@ -6715,7 +6717,7 @@ but not any simpler -- Albert Einstein #+end_quote @end example -@node Literal examples, Tables exported, Paragraphs, Markup rules +@node Literal examples, Include files, Paragraphs, Markup rules @subheading Literal examples You can include literal examples that should not be subjected to @@ -6751,7 +6753,23 @@ example: #+end_src @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 Both the native Org mode tables (@pxref{Tables}) and tables formatted with diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 22888116f..e49311a9f 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -707,7 +707,7 @@ modified) list.") (mapcar 'car org-export-inbuffer-options-extra)))) p key val text options js-up js-main js-css js-opt a pr) (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)) (cond ((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)) (untabify (point-min) (point-max)) + ;; Handle incude files + (org-export-handle-include-files) + ;; Handle source code snippets (org-export-replace-src-segments) @@ -1321,7 +1324,7 @@ on this string to produce the exported version." ;; Blockquotes (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") "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START") t t)) @@ -1566,6 +1569,38 @@ When LEVEL is non-nil, increase section numbers on that level." (setq string (replace-match "" t nil 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 ;; Currently only for th HTML backend, but who knows.... (defun org-export-replace-src-segments () diff --git a/lisp/org.el b/lisp/org.el index cb59c0c82..bc8ac0c8e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2712,7 +2712,8 @@ means to push this value onto the list in the variable.") (widen) (goto-char (point-min)) (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 ((equal key "CATEGORY") (if (string-match "[ \t]+$" value) -- 2.11.4.GIT