From 3d59326fcfe8fb6a37f843dd9ade4c0d063dfa86 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 2 Jul 2008 13:29:45 -0700 Subject: [PATCH] Allow prefixes in include file statements. --- contrib/ChangeLog | 5 +++++ contrib/lisp/org-mtags.el | 13 +++++++++---- doc/org.texi | 9 ++++++++- lisp/ChangeLog | 6 ++++++ lisp/org-exp.el | 37 +++++++++++++++++++++++++++++++++---- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/contrib/ChangeLog b/contrib/ChangeLog index 061a31934..16a5d295a 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,8 @@ +2008-07-02 Carsten Dominik + + * lisp/org-mtags.el (org-mtags-replace): Allow prefix and prefix1 + as options in the include directive. + 2008-06-18 Christian Egli * scripts/org2hpda (DIARY): Make the location of the diary file diff --git a/contrib/lisp/org-mtags.el b/contrib/lisp/org-mtags.el index 81f9aa330..868ff9ba6 100644 --- a/contrib/lisp/org-mtags.el +++ b/contrib/lisp/org-mtags.el @@ -72,7 +72,7 @@ ;; Needs to be on a line by itself, similarly the tag. ;; Will be translated into Org's BEGIN_SRC construct. ;; -;; +;; ;; Needs to be on a line by itself. ;; Will be translated into Org's #+INCLUDE construct. ;; @@ -128,7 +128,7 @@ The is done in the entire buffer." (let ((re (concat "^[ \t]*\\(\\)")) - info tag rpl style markup lang file) + info tag rpl style markup lang file prefix prefix1) ;; First, do the
tag (goto-char (point-min)) (while (re-search-forward "
[ \t]*$" nil t) @@ -177,12 +177,17 @@ The is done in the entire buffer." ((equal tag "include") (setq file (plist-get info :file) markup (downcase (plist-get info :markup)) - lang (plist-get info :lang)) + lang (plist-get info :lang) + prefix (plist-get info :prefix) + prefix1 (plist-get info :prefix1)) (setq rpl "#+INCLUDE") (when markup (setq rpl (concat rpl " " markup)) (when (and (equal markup "src") lang) - (setq rpl (concat rpl " " lang)))))) + (setq rpl (concat rpl " " lang)))) + (setq rpl (concat rpl + " :prefix " prin1-to-string prefix + " :prefix1 " prin1-to-string prefix1)))) (when rpl (goto-char (plist-get info :match-beginning)) (delete-region (point-at-bol) (plist-get info :match-end)) diff --git a/doc/org.texi b/doc/org.texi index c06d2939f..ac6206b03 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6941,7 +6941,14 @@ 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. +processed normally. The include line will also allow additional keyword +parameters @code{:prefix1} and @code{:prefix} to specify prefixes for the +first line and for each following line. For example, to include a file as an +item, use + +@example +#+INCLUDE: "~/snippets/xx" :prefix1 " + " :prefix " " +@end example @table @kbd @kindex C-c ' diff --git a/lisp/ChangeLog b/lisp/ChangeLog index df6a0c0b2..871b9ba38 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2008-07-02 Carsten Dominik + + * org-exp.el (org-get-file-contents) + (org-get-and-remove-property): New functions. + (org-export-handle-include-files): Handle the new prefix options. + 2008-07-01 Carsten Dominik * org.el (org-time=, org-time<, org-time<=, org-time>) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index b42d408d5..bec520a91 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1895,10 +1895,12 @@ TYPE must be a string, any of: (defun org-export-handle-include-files () "Include the contents of include files, with proper formatting." (let ((case-fold-search t) - params file markup lang start end) + params file markup lang start end prefix prefix1) (goto-char (point-min)) (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t) (setq params (read (concat "(" (match-string 1) ")")) + prefix (org-get-and-remove-property 'params :prefix) + prefix1 (org-get-and-remove-property 'params :prefix1) file (org-symname-or-string (pop params)) markup (org-symname-or-string (pop params)) lang (org-symname-or-string (pop params))) @@ -1914,17 +1916,45 @@ TYPE must be a string, any of: (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)))) + (insert (org-get-file-contents (expand-file-name file) prefix prefix1)) (or (bolp) (newline)) (insert (or end "")))))) +(defun org-get-file-contents (file &optional prefix prefix1) + "Get the contents of FILE and return them as a string. +If PREFIX is a string, prepend it to each line. If PREFIX1 +is a string, prepend it to the first line instead of PREFIX." + (with-temp-buffer + (insert-file-contents file) + (when (or prefix prefix1) + (goto-char (point-min)) + (while (not (eobp)) + (insert (or prefix1 prefix)) + (setq prefix1 nil) + (beginning-of-line 2))) + (buffer-string))) + +(defun org-get-and-remove-property (listvar prop) + "Check if the value of LISTVAR contains PROP as a property. +If yes, return the value of that property (i.e. the element following +in the list) and remove property and value from the list in LISTVAR." + (let ((list (symbol-value listvar)) m v) + (when (setq m (member prop list)) + (setq v (nth 1 m)) + (if (equal (car list) prop) + (set listvar (cddr list)) + (setcdr (nthcdr (- (length list) (length m) 1) list) + (cddr m)) + (set listvar list))) + v)) + (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.... +;; Currently only for the HTML backend, but who knows.... (defun org-export-replace-src-segments () "Replace source code segments with special code for export." (let ((case-fold-search t) @@ -4371,4 +4401,3 @@ The XOXO buffer is named *xoxo-*" ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95 ;;; org-exp.el ends here - -- 2.11.4.GIT