From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch, ox] #+INCLUDE resolves links Date: Sun, 21 Sep 2014 15:53:18 +0200 Message-ID: <87bnq984hd.fsf@nicolasgoaziou.fr> References: <87k34x6bjd.fsf@gmx.us> <87lhpdurfh.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVhZK-0002oQ-KM for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 09:52:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVhZC-00036Q-Gl for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 09:52:50 -0400 Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]:33116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVhZC-00035n-7a for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 09:52:42 -0400 In-Reply-To: <87lhpdurfh.fsf@gmx.us> (rasmus@gmx.us's message of "Sun, 21 Sep 2014 13:46:42 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: emacs-orgmode@gnu.org Hello, Rasmus writes: > Rasmus 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