From 1922ebcd047c4ea6ebdf8db1ee9bbabdaf54e687 Mon Sep 17 00:00:00 2001 From: Gustav Wikström Date: Mon, 22 Feb 2021 23:03:34 +0100 Subject: Speedup crawler by ... making it not crawl! --- nroam.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/nroam.el b/nroam.el index bbadffb..74fcbbb 100644 --- a/nroam.el +++ b/nroam.el @@ -44,6 +44,7 @@ (defvar-local nroam-start-marker nil) (defvar-local nroam-end-marker nil) +(defvar nroam-work-buffer " nroam-work") (defmacro with-nroam-markers (&rest body) "Evaluate BODY. Make the region inserted by BODY read-only, and marked with @@ -68,6 +69,7 @@ Make the region inserted by BODY read-only, and marked with :keymap nroam-mode-map (if nroam-mode (progn + (nroam--init-work-buffer) (add-hook 'before-save-hook #'nroam--prune-backlinks nil t) (add-hook 'after-save-hook #'nroam--update-backlinks-maybe nil t) (nroam-update-backlinks)) @@ -75,6 +77,12 @@ Make the region inserted by BODY read-only, and marked with (remove-hook 'after-save-hook #'nroam--update-backlinks-maybe t) (nroam--prune-backlinks))) +(defun nroam--init-work-buffer () + (get-buffer-create nroam-work-buffer t) + (with-current-buffer nroam-work-buffer + (delay-mode-hooks + (org-mode)))) + (defun nroam-ctrl-c-ctrl-c () "Update the backlinks for the current buffer, or fallback to `org-ctrl-c-ctrl-c'." (interactive) @@ -198,14 +206,14 @@ Make the region inserted by BODY read-only, and marked with (defun nroam--crawl-source (file point) "Return the source element in FILE at POINT." - (with-current-buffer (find-file-noselect file) - (save-excursion - (goto-char point) - (let ((elt (org-element-at-point))) - (let ((begin (org-element-property :begin elt)) - (end (org-element-property :end elt)) - (type (org-element-type elt))) - `(,type . ,(buffer-substring begin end))))))) + (with-current-buffer nroam-work-buffer + (insert-file-contents file nil nil nil 'replace) + (goto-char point) + (let ((elt (org-element-at-point))) + (let ((begin (org-element-property :begin elt)) + (end (org-element-property :end elt)) + (type (org-element-type elt))) + `(,type . ,(buffer-substring begin end)))))) (defun nroam--fix-links (content origin) "Correct all relative links in CONTENT from ORIGIN. -- cgit v1.2.3-54-g00ecf