Add FILE support to +org-get-property & optimize

Can now be used to grab properties from remote org files. Also only
reads the first 2048 bytes of the document by default, for performance
reasons.
This commit is contained in:
Henrik Lissner
2018-06-04 18:43:51 +02:00
parent 5c5b4931cf
commit 23bd9d3efa

View File

@ -1,12 +1,23 @@
;;; org/org/autoload/org.el -*- lexical-binding: t; -*- ;;; org/org/autoload/org.el -*- lexical-binding: t; -*-
;;;###autoload (defun +org--get-property (name &optional bound)
(defun +org-get-property (name &optional _file) ; TODO Add FILE
"Get a propery from an org file."
(save-excursion (save-excursion
(goto-char 1) (let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name))))
(re-search-forward (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)) nil t) (goto-char (point-min))
(buffer-substring-no-properties (match-beginning 1) (match-end 1)))) (when (re-search-forward re bound t)
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
;;;###autoload
(defun +org-get-property (name &optional file bound)
"Get a document property named NAME (string) from an org FILE (defaults to
current file). Only scans first 2048 bytes of the document."
(unless bound
(setq bound 2048))
(if file
(with-temp-buffer
(insert-file-contents-literally file nil 0 bound)
(+org--get-property name))
(+org--get-property name bound)))
;; ;;