emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: [patch, ox] #+INCLUDE resolves links
Date: Sun, 21 Sep 2014 15:53:18 +0200	[thread overview]
Message-ID: <87bnq984hd.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87lhpdurfh.fsf@gmx.us> (rasmus@gmx.us's message of "Sun, 21 Sep 2014 13:46:42 +0200")

Hello,

Rasmus <rasmus@gmx.us> writes:

> Rasmus <rasmus@gmx.us> 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

  reply	other threads:[~2014-09-21 13:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-21  0:51 [patch, ox] #+INCLUDE resolves links Rasmus
2014-09-21 11:46 ` Rasmus
2014-09-21 13:53   ` Nicolas Goaziou [this message]
2014-09-21 14:46     ` Rasmus
2014-09-21 19:51       ` Nicolas Goaziou
2014-09-23 23:25     ` Rasmus
2014-09-24 21:22       ` Nicolas Goaziou
2014-09-28 19:32         ` Rasmus
2014-09-30  8:07           ` Nicolas Goaziou
2014-09-30 10:18             ` Rasmus
2014-09-30 14:29               ` Nicolas Goaziou
2014-09-30 21:48                 ` Rasmus
2014-10-01 20:03                   ` Nicolas Goaziou
2014-10-01 21:27                     ` Rasmus
2014-10-02  7:29                       ` Xavier Garrido
2014-10-02  8:55                         ` Rasmus
2014-10-02 16:30                           ` Aaron Ecay
2014-10-02 16:53                           ` Nicolas Goaziou
2014-10-02 17:47                             ` Rasmus
2014-10-02 19:11                               ` Achim Gratz
2014-10-02 20:58                                 ` Rasmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnq984hd.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).