[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [patch, ox] #+INCLUDE resolves links
From: |
Nicolas Goaziou |
Subject: |
Re: [O] [patch, ox] #+INCLUDE resolves links |
Date: |
Sun, 21 Sep 2014 15:53:18 +0200 |
Hello,
Rasmus <address@hidden> writes:
> Rasmus <address@hidden> writes:
>
>> This patch allows INCLUDE to have intuitive links as resolved by
>> `org-link'-search'. A couple of examples:
Thanks for the patch. Some comments follow.
>> #+INCLUDE: file.org::#custom_id :noheadline :lines "3-"
Is it `:only-contents' or `:no-headline'? Also ":kwd1 :kbd2 value" is
usually a shortcut for ":kwd1 nil :kbd2 value" (at least in export
attributes). Your example is thus confusing, you should include the
expected value.
#+INCLUDE: "file.org::#custom_id" :only-contents t :lines "3-"
> +elements.}. If the keyword @code{:only-contents} is used, only the contents
> +of the element in included. For headlines, drawers and properties
^^
> +assumed to be in Org mode format and will be processed normally. File-links
> +will be interpret as well:
^^^^^^^^^
> ;;; ox.el --- Generic Export Engine for Org Mode
> -
> ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
You can remove this chunk.
> + (only-contents
> + (and (string-match
> +
> ":\\(only-?contents?[[:space:]]*\\(?:'t\\|true\\|yes\\)?\\)" value)
This should be ":only-contents t" or ":only-contents nil".
":only-contents" alone can be tolerated as a shortcut for
":only-contents nil", but that's all.
> + (prog1 t
> + (setq value (replace-match "" nil nil value)))))
Since `replace-match' cannot return nil here, you can remove
(prog1 t ...)
wrapper. If you insist on ONLY-CONTENTS being t, then
(progn (setq ...) t)
is better.
> + (org-export--prepare-file-contents file location
> only-contents lines))))
Couldn't location, only-contents and lines be merged into a single
argument? At the moment, you are either short-circuiting or breaking
guard against circular inclusions (which relies on a combination of
file-name and lines).
IOW, each include keyword could be defined as a triplet of file name,
beginning and ending global positions. You could implement a helper
function to translate FILE LOCATION and ONLY-CONTENTS into this triplet,
which would then be passed to `org-export--prepare-file-contents'.
> -(defun org-export--prepare-file-contents (file &optional lines ind minlevel
> id)
> +(defun org-export--prepare-file-contents (file &optional location
> only-contents lines ind minlevel id)
> "Prepare the contents of FILE for inclusion and return them as a string.
>
> +When optional argument LOCATION is a string the matching element
> +identified using `org-link-search' is returned. Note that
> +`org-link-search-must-match-exact-headline' is locally set to
> +non-nil. When ONLY-CONTENTS is non-nil only the contents of the
> +matched element in included. If LOCATION is a headline and
> +ONLY-CONTENTS is non-nil, drawers and property-drawers
> +immediately following the first headline are also removed.
> +
> When optional argument LINES is a string specifying a range of
> lines, include only those lines.
>
> @@ -3420,6 +3437,26 @@ This is useful to avoid conflicts when more than one
> Org file
> with footnotes is included in a document."
> (with-temp-buffer
> (insert-file-contents file)
> + (org-mode)
You cannot enforce `org-mode' as the current major mode since you can
include other file types.
> + (when location
> + (condition-case err
> + ;; enforce consistency in search.
> + (let ((org-link-search-must-match-exact-headline t))
> + (org-link-search location))
> + ;; helpful error messages
> + (error (error (format "%s for %s::%s"
> + (error-message-string err) file location))))
> + (narrow-to-region
> + (org-element-property
> + (if only-contents :contents-begin :begin) (org-element-at-point))
> + (org-element-property (if only-contents :contents-end :end)
> (org-element-at-point)))
> + ;; get rid of drawers and properties
> + (when only-contents
> + (let ((element (org-element-at-point)))
> + (while (member (org-element-type element) '(drawer property-drawer))
> + (delete-region (org-element-property :begin element)
> + (org-element-property :end element))
> + (setq element (org-element-at-point))))))
This could be handled when building the triplet. However, please do not
skip drawers (property drawers are fine), as you cannot tell what the
contents are.
> (when lines
> (let* ((lines (split-string lines "-"))
> (lbeg (string-to-number (car lines)))
> @@ -3495,7 +3532,7 @@ with footnotes is included in a document."
> (org-element-normalize-string (buffer-string))))
>
> (defun org-export-execute-babel-code ()
> - "Execute every Babel code in the visible part of current buffer."
> + "ExecUte every Babel code in the visible part of current buffer."
You can remove this chunk too.
Regards,
--
Nicolas Goaziou
- [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/20
- Re: [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/21
- Re: [O] [patch, ox] #+INCLUDE resolves links,
Nicolas Goaziou <=
- Re: [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/23
- Re: [O] [patch, ox] #+INCLUDE resolves links, Nicolas Goaziou, 2014/09/24
- Re: [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/28
- Re: [O] [patch, ox] #+INCLUDE resolves links, Nicolas Goaziou, 2014/09/30
- Re: [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/30
- Re: [O] [patch, ox] #+INCLUDE resolves links, Nicolas Goaziou, 2014/09/30
- Re: [O] [patch, ox] #+INCLUDE resolves links, Rasmus, 2014/09/30