Function: org-export--inclusion-absolute-lines
org-export--inclusion-absolute-lines is a byte-compiled function
defined in ox.el.gz.
Signature
(org-export--inclusion-absolute-lines FILE LOCATION ONLY-CONTENTS LINES)
Documentation
Resolve absolute lines for an included file with file-link.
FILE is string file-name of the file to include. LOCATION is a
string name within FILE to be included (located via
org-link-search). If ONLY-CONTENTS is non-nil only the
contents of the named element will be included, as determined
Org-Element. If LINES is non-nil only those lines are included.
Return a string of lines to be included in the format expected by
org-export--prepare-file-contents.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export--inclusion-absolute-lines (file location only-contents lines)
"Resolve absolute lines for an included file with file-link.
FILE is string file-name of the file to include. LOCATION is a
string name within FILE to be included (located via
`org-link-search'). If ONLY-CONTENTS is non-nil only the
contents of the named element will be included, as determined
Org-Element. If LINES is non-nil only those lines are included.
Return a string of lines to be included in the format expected by
`org-export--prepare-file-contents'."
(with-temp-buffer
(insert (org-file-contents file))
(unless (eq major-mode 'org-mode)
(let ((org-inhibit-startup t)) (org-mode)))
(condition-case err
;; Enforce consistent search.
(let ((org-link-search-must-match-exact-headline nil))
(org-link-search location))
(error
(error "%s for %s::%s" (error-message-string err) file location)))
(let* ((element (org-element-at-point))
(contents-begin
(and only-contents (org-element-property :contents-begin element))))
(narrow-to-region
(or contents-begin (org-element-property :begin element))
(org-element-property (if contents-begin :contents-end :end) element))
(when (and only-contents
(memq (org-element-type element) '(headline inlinetask)))
;; Skip planning line and property-drawer.
(goto-char (point-min))
(when (looking-at-p org-planning-line-re) (forward-line))
(when (looking-at org-property-drawer-re) (goto-char (match-end 0)))
(unless (bolp) (forward-line))
(narrow-to-region (point) (point-max))))
(when lines
(org-skip-whitespace)
(beginning-of-line)
(let* ((lines (split-string lines "-"))
(lbeg (string-to-number (car lines)))
(lend (string-to-number (cadr lines)))
(beg (if (zerop lbeg) (point-min)
(goto-char (point-min))
(forward-line (1- lbeg))
(point)))
(end (if (zerop lend) (point-max)
(goto-char beg)
(forward-line (1- lend))
(point))))
(narrow-to-region beg end)))
(let ((end (point-max)))
(goto-char (point-min))
(widen)
(let ((start-line (line-number-at-pos)))
(format "%d-%d"
start-line
(save-excursion
(+ start-line
(let ((counter 0))
(while (< (point) end) (cl-incf counter) (forward-line))
counter))))))))