Comments (6)
Thank you for opening this issue, @aavanian.
I corrected and clarified the comment in commit 4f5e77d.
Your use case seems to be extreme, but the search for duplicates is indeed inefficient.
Actually, there should only be very few duplicate buffers in the list returned by org-roam-buffer-list
so looking for buffers with prefix CAPTURE-*
should be computationally more efficient.
If you want to come up with an improved solution, it would be greatly appreciated.
Best regards,
jgru
from consult-org-roam.
Hi @aavanian,
I experimented with just removing the buffers that are prefixed with CAPTURE-
.
Would you please test the following snippet whether it satisfies your performance requirements?
(defun consult-org-roam--remove-capture-dups (buffer-list)
"Remove CAPTURE-duplicates from BUFFER-LIST."
(let ((out-list buffer-list))
(dolist (x buffer-list)
(when (s-starts-with-p "CAPTURE-" (buffer-name x))
(setq out-list (delete x out-list))
))
out-list))
Best regards,
jgru
from consult-org-roam.
Thanks for the quick turn-around, however it only improve things marginally. I now realise that it's being called many times (for each candidate via the annotation lambda (defined in org-roam-buffer-source
).
I'm thinking the variable org-roam-buffer-open-buffer-list
should be set when/during consult-org-roam-buffer--get-roam-bufs
is called by the consult
mechanics.
I can read-ish the code but don't know much about emacs (and consult in particular) but here how it could look like (including your change for consult-org-roam--remove-capture-dups
):
diff --git a/consult-org-roam-buffer.el b/consult-org-roam-buffer.el
index 54373a8..089c07d 100644
--- a/consult-org-roam-buffer.el
+++ b/consult-org-roam-buffer.el
@@ -95,12 +95,11 @@
(defun consult-org-roam--remove-capture-dups (buffer-list)
"Remove CAPTURE-duplicates from BUFFER-LIST."
(let ((out-list buffer-list))
- (dolist (x buffer-list)
- (dolist (y buffer-list)
- (when (not (eq (buffer-name x) (buffer-name y)))
- (if (string-match-p (regexp-quote (buffer-name y)) (buffer-name x))
- (setq out-list (delete y buffer-list))))))
- buffer-list))
+ (dolist (x buffer-list)
+ (when (s-starts-with-p "CAPTURE-" (buffer-name x))
+ (setq out-list (delete x buffer-list))
+ ))
+ out-list))
(defun consult-org-roam--buffer-list-without-dups ()
"Return a list of all org-roam-buffers without duplicates.
@@ -110,28 +109,27 @@ sufficient to simply is org-roam-buffer-p caused by capture
process"
(consult-org-roam--remove-capture-dups (org-roam-buffer-list)))
-(defun consult-org-roam-buffer--update-open-buffer-list ()
- "Generate an alist of the form `(TITLE . BUF)’.
+(defun consult-org-roam-buffer--update-open-buffer-list (buffer-list)
+ "Generate an alist of the form `(TITLE . BUF) from BUFFER-LIST’.
Generate an alist of the form `(TITLE . BUF)’ where TITLE is the
title of an open org-roam buffer."
(setq org-roam-buffer-open-buffer-list
- (mapcar #'consult-org-roam-buffer--add-title
- (consult-org-roam--buffer-list-without-dups))))
+ (mapcar #'consult-org-roam-buffer--add-title buffer-list)))
(defun consult-org-roam-buffer--with-title (title)
"Find buffer name with TITLE from among the list of open org-roam buffers."
- (consult-org-roam-buffer--update-open-buffer-list)
(cdr (assoc title org-roam-buffer-open-buffer-list)))
(defun consult-org-roam-buffer--get-roam-bufs ()
"Return list of currently open org-roam buffers."
- (consult--buffer-query
+ (let ((buffer-list-no-dups (consult-org-roam--buffer-list-without-dups)))
+ (consult-org-roam-buffer--update-open-buffer-list buffer-list-no-dups)
+ (consult--buffer-query
:sort 'visibility
:as #'consult-org-roam-buffer--get-title
:filter t
:predicate (lambda (buf)
- (member buf
- (consult-org-roam--buffer-list-without-dups)))))
+ (member buf buffer-list-no-dups)))))
;; Define source for consult-buffer
(defvar org-roam-buffer-source
It's still slightly slower than I think it should but it's definitely usable for me now (I'll try to look further).
2 related points:
- shouldn't
(setq out-list (delete x buffer-list))
rather read(setq out-list (delete x out-list))
(otherwise you lose the previous deletes)? - shouldn't disabling
consult-org-roam-mode
removeorg-roam-buffer-source
fromconsult-buffer-sources
?
from consult-org-roam.
Hi @aavanian,
I'm thinking the variable
org-roam-buffer-open-buffer-list
should be
set when/duringconsult-org-roam-buffer--get-roam-bufs
is called by
theconsult
mechanics.
Indeed, thank you very much for this suggestion and drafting the code.
I reviewed and tested your patch, which looks good. I merged it in commit 5d1e4a7.
It's still slightly slower than I think it should but it's definitely
usable for me now (I'll try to look further).
I would be very happy if you would track this down even further and submit a PR (or a description of how to improve it even further). I rarely open more than 10 `org-roam``-buffers at once, so I did and do not experience any slowness.
Since you think that the current implementation is usable for you as well now, do you think that this issue can/should be closed?
- shouldn't
(setq out-list (delete x buffer-list))
rather read
(setq out-list (delete x out-list))
(otherwise you lose the
previous deletes)?
Definitely, I drafted this in a hurry, now it is corrected.
- shouldn't disabling
consult-org-roam-mode
remove
org-roam-buffer-source
fromconsult-buffer-sources
?
It should be removed, I think, and consider this to be a bug.
I track this as #21. Thank you so much for pointing this out.
Best regards,
jgru
from consult-org-roam.
Thanks, closing and will revert if I find something more.
from consult-org-roam.
Thank you for closing the issue, @aavanian.
I just want to let you know that I added the removal of the org-roam-buffer-source
from consult's consult-buffer-sources
when disabling the minor mode in commit 96c95e5. #21 is closed now.
I hope you enjoy using consult-org-roam
.
Best regards,
jgru
from consult-org-roam.
Related Issues (20)
- Add function to create dummy data for testing purposes HOT 1
- Question: purpose of consult-org-roam-file-find HOT 3
- Strip leading path of candidates presented by consult-org-roam-file-find
- [BUG] cursor moved when previewing the same buffer and the first item is far from the current cursor HOT 5
- consult-buffer doesn't show capture buffers HOT 4
- consult-buffer shows duplicate capture buffers
- Remove org-roam-buffer-source when disabling consult-org-roam-mode
- After using :preview-key M-., how to jump to the previewed file directly? HOT 3
- `org-roam-node-insert` failed to insert into correct place. HOT 2
- Sorting (sort-fn) function does not work HOT 7
- major-mode not applied in previews for consult-org-roam-node-read HOT 2
- consult-org-roam-buffer-after-buffers does not produce the expected outcome
- consult-org-roam-buffer, do not alter visiting order of buffers HOT 4
- How to jump to the search result? HOT 3
- Org heading node is not searched HOT 3
- consult-org-roam-forward-links is not working HOT 2
- Why the order is not respected ? HOT 6
- Get only Org results HOT 2
- Can I call `consult-org-roam-buffer` source as a command ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from consult-org-roam.