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: [bug, patch, ox] INCLUDE and footnotes
Date: Thu, 18 Dec 2014 00:30:29 +0100	[thread overview]
Message-ID: <87y4q57t2i.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87388j9qbv.fsf@gmx.us> (rasmus@gmx.us's message of "Sat, 13 Dec 2014 22:45:24 +0100")

Hello,

Rasmus <rasmus@gmx.us> writes:

> Attached is a patch that enables footnotes in INCLUDEd documents when
> using :lines and friends.  It stores the footnotes in a hash-table
> initialized in `org-export-expand-include-keyword' and updated via
> `org-export--prepare-file-contents'.  The footnotes are then inserted when
> all include keywords are expanded.

Thanks. Some more comments follow.

> At the moment only footnotes from INCLUDEs with :lines-like arguments will
> be picket up here.  But I think it might be nice to also use this
> functionality with footnotes when whole documents are included, and not
> include the footnote section directly from these documents.  Though I
> expect the to be accused of worm-nurturing, do consider this curious example:

[...]

>    2. fix the "bug" (IMO) that is that
>           #+INCLUDE: "/tmp/t00.org"
>           #+INCLUDE: "/tmp/t01.org"
>       Is "read" as
>           #+INCLUDE: "/tmp/t00.org" :minlevel N
>           #+INCLUDE: "/tmp/t01.org" :minlevel N+1
>       The easiest way I can think of would be to do a pre-scan of the
>       buffer to see if there exists any instances where include is only
>       separated by whitespace in which case they should have the same
>       level.

AFAICT, there's no reason to include a rule about whitespace separating
anything. Just make sure that any INCLUDE keyword that doesn't have
a :minlevel property gets one set to 1+N, where N is the current level
(or 0 if at top level).

Another option is to delay insertion of included files: expand them
completely in different strings, then replace keywords with appropriate
strings. IOW, just make sure expansion doesn't happen sequentially.

>  Objects can be extracted via =#+INCLUDE= using file links.  It is
> -possible to include only the contents of the object.  See manual for
> +possible to include only the contents of the object.  Further,
> +footnotes are now supported when using =#+INCLUDE=.  See manual for

This is not quite true. Footnotes are already supported with INCLUDE
keywords. This is the combination of :lines and footnotes that is new.
It is more a bugfix than a new feature.

> +	(footnotes (or footnotes (make-hash-table :test 'equal))))

Nitpick: (make-hash-table :test #'equal)

> +		   (goto-char (point-min))
> +		   (while (and (search-forward-regexp org-footnote-re nil t))
> +		     (let* ((reference (org-element-context))
> +			    (type (org-element-type reference))
> +			    (label (org-element-property :label reference)))
> +		       (when (and label (eq type 'footnote-reference))
> +			 (unless (org-footnote-get-definition label)
> +			   (save-excursion
> +			     (org-footnote-create-definition label)
> +			     ;; We do not need an error here since ox
> +			     ;; will complain if a footnote is missing.
> +			     (insert (or (gethash label footnotes) "")))))))

Why is the above necessary? Shouldn't you only insert footnotes
definitions at the end of the master document (i.e. when INCLUDED is
nil)? I think a `maphash' is enough.

Also, looking for every footnote reference sounds tedious. You should
simply insert every footnote definition collected there, and filter out
unnecessary definitions at another level (e.g., before storing it in the
hash table).

> +      (when id
> +	(unless (eq major-mode 'org-mode)
> +	  (let ((org-inhibit-startup t)) (org-mode)))

Is it necessary?

> +	(goto-char (point-min))
> +	(while (re-search-forward org-footnote-re nil t)
> +	  (let* ((reference (org-element-context))
> +		 (type (org-element-type reference))
> +		 (footnote-type (org-element-property :type reference))
> +                 (label (org-element-property :label reference)))
> +	    (when (and (eq type 'footnote-reference))
                   ^^^
Typo.

> +	      (goto-char (org-element-property :begin reference))
> +	      (when label
> +		(goto-char (org-element-property :begin reference))

You are already at reference beginning.

> +		(forward-char 4)
> +		(insert (format "%d-" id))
> +		(and (not (eq footnote-type 'inline))
> +		     (let ((new-label (org-element-property
> +				       :label (org-element-context))))

Why do you need to parse the new label, since you know it already:

  (concat (format "%d-" id) label)

> +		       (save-restriction
> +			 (save-excursion
> +			   (widen)

`save-restriction' + `save-excursion' + `widen' = `org-with-wide-buffer'

> +			   (org-footnote-goto-definition label)
> +			   (let ((definition (org-element-context)))
> +			     (and include-footnotes

Nitpick:

  (when include-footnotes ...

> +				  (puthash new-label
> +					   (org-element-normalize-string
> +					    (buffer-substring
> +					     (org-element-property
> +					      :contents-begin definition)
> +					     (org-element-property
> +					      :contents-end definition)))
> +					   footnotes))

Here you could check if :contents-begin is within LINES, in which case
the definition needs not be inserted at the end of the master document.

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2014-12-17 23:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09 11:44 [bug, patch, ox] INCLUDE and footnotes Rasmus
2014-12-09 19:10 ` Rasmus
2014-12-09 19:14 ` Nicolas Goaziou
2014-12-09 21:21   ` Rasmus
2014-12-09 21:37     ` Nicolas Goaziou
2014-12-10  0:57       ` Rasmus
2014-12-10 11:21         ` Nicolas Goaziou
2014-12-10 11:58           ` Rasmus
2014-12-10 15:44             ` Nicolas Goaziou
2014-12-13 21:45               ` Rasmus
2014-12-17 23:30                 ` Nicolas Goaziou [this message]
2014-12-18 17:37                   ` Rasmus
2014-12-19 16:44                     ` Rasmus
2014-12-21 21:04                       ` Nicolas Goaziou
2014-12-21 22:39                         ` Rasmus
2014-12-21 23:38                           ` Nicolas Goaziou
2014-12-22  1:42                             ` Rasmus
2014-12-22  9:05                               ` Nicolas Goaziou
2014-12-24 18:03                                 ` Rasmus
2014-12-24 21:14                                   ` Nicolas Goaziou
2014-12-25  1:38                                     ` Rasmus
2014-12-25  2:04                                     ` Rasmus
2014-12-21 20:52                     ` Nicolas Goaziou
2014-12-22  1:49                       ` Rasmus
2014-12-22 11:10                         ` Nicolas Goaziou
2014-12-22 12:36                           ` Rasmus
2014-12-22 20:54                             ` Nicolas Goaziou
2014-12-22 22:11                               ` Rasmus
2014-12-22 22:51                                 ` Nicolas Goaziou
2014-12-23  2:09                                   ` Rasmus
2014-12-24 17:54                                   ` Rasmus
2014-12-24 18:10                                     ` [git-101] How to push a branch and avoid merge-message? (was: [bug, patch, ox] INCLUDE and footnotes) Rasmus
2014-12-24 21:09                                       ` [git-101] How to push a branch and avoid merge-message? Nicolas Goaziou

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=87y4q57t2i.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).