From 9b3f21a9bcd5c7783a162a3f069a2e311ee10442 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 26 Oct 2019 01:55:16 -0400 Subject: [PATCH] Optimize doom/help-search Yields a ~80% decrease in indexing time. --- modules/lang/org/autoload/org.el | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index d9c6adeb7..ccde1b011 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -110,24 +110,24 @@ (when (bound-and-true-p evil-local-mode) (evil-insert 1)))) +(defun +org--get-property (name &optional bound) + (save-excursion + (let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)))) + (goto-char (point-min)) + (when (re-search-forward re bound t) + (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))) + ;;;###autoload -(defun +org-get-global-property (property &optional file) - "Get #+PROPERTY from an org FILE (defaults to current file)." +(defun +org-get-global-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 256)) (if file - (let ((bound 256)) - (with-temp-buffer - (insert-file-contents-literally file nil 0 bound) - (goto-char (point-min)) - (and (re-search-forward (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)) - bound t) - (buffer-substring-no-properties (match-beginning 1) - (match-end 1))))) - (org-element-property - :value - (car (org-element-map (org-element-parse-buffer) 'keyword - (lambda (el) - (and (string-match-p property (org-element-property :key el)) - el))))))) + (with-temp-buffer + (insert-file-contents-literally file nil 0 bound) + (+org--get-property name)) + (+org--get-property name bound))) ;;;###autoload (defun +org-get-todo-keywords-for (&optional keyword)