jgru / consult-org-roam Goto Github PK
View Code? Open in Web Editor NEWA bunch of convenience functions for operating org-roam with the help of consult
License: GNU General Public License v3.0
A bunch of convenience functions for operating org-roam with the help of consult
License: GNU General Public License v3.0
Hi there!
Related to #28 : the proposed solution does not work :(
When I try to do this :
(setq consult-org-roam-buffer-enabled nil)
(setq org-roam-node-default-sort 'file-atime)
I always get the same order, regardless of whether the consult-org-roam-buffer-enabled variable is nil or t by the way.
I don't understand why I have this behaviour. The desired behaviour would be when I don't activate consult-org-roam (I use vertico-prescient, and I simply have a sort by date of node visited, which is very good) but I no longer have the preview (which is disturbing, because I really love that one).
Is there a solution? Have I misunderstood something?
Thank you in advance for your reply.
thank you the package
I wonder if it would be possible to add a variable that will permit the buffers to be kept in their visited order (last visited top) instead of moving them all to their own section.
Here is my use case: I use org-roam dailies. So I am constantly going back to the buffer of today.
With consult-org-roam-mode enabled, today's note is now way down and I have to type first n to be able to see it. Which means every time I am switching buffers I have to think: is this a roam node or not before I can see in the list of buffers.
it is nice though to have the option to narrow the buffers using n though.
Thanks for this package! All of the provided functionality looks very useful, but I'm a little confused about the purpose of consult-org-roam-file-find
. It seems to do the same thing as the normal org-roam-node-find
with consult-org-roam-mode
turned on; both of them search through the org-roam notes with consult completing. Just want to understand if I'm missing anything.
As proposed by @apc in the course of the discussion regarding #13, there should be a pre-populated org-roam-directory
so that the package could be easily tested. To achieve this, a function should be created and documented in the wiki to make the configuration for testing purposes more complete and comprehensive.
About the test config, have you considered just having some test files that can be downloaded as part of the repo, which could be what org-roam-dir is set to according to your minimal config? I think citar has something like that setup and I think it works fine.
-- @apc
Hello!
May I suggest setting the default value #'consult-org-roam-grep-func
to #'consult-grep
?
This change would ensure that users who do not have ripgrep installed are able to use this package OOTB.
Thank you!
I've been experimenting with consult-org-roam
but find that consult-buffer
becomes very slow once it's activated.
152 41% + #<compiled 0xe42e24cbeb30d77>
45 12% + file-truename
33 8% + #<compiled 0xe0ec30bfd1027e9>
29 7% + #<compiled -0x1dff16fac04ec833>
24 6% + read-from-minibuffer
22 5% Automatic GC
10 2% + #<compiled 0x12cd0dc741558ae2>
10 2% + file-relative-name
7 1% + which-key--propertize-description
5 1% + mapcar
4 1% + marginalia--function-doc
2 0% + vertico--update
2 0% + #<compiled -0x1cf2072e101497a4>
2 0% + all-completions
1 0% + #<compiled 0x1dc193f24a4f>
1 0% + which-key--key-description<
1 0% + which-key--extract-key
1 0% + advice--make-docstring
1 0% + which-key--maybe-add-docstring
1 0% + which-key--list-to-pages
1 0% + which-key--echo
1 0% + delete-window
1 0% + consult--buffer-sort-visibility
1 0% + abbreviate-file-name
1 0% + powerline-render
1 0% + #<compiled -0xf611ae1d4c5bae2>
1 0% + timerp
1 0% + #<compiled 0xf22d8c2e0fb90a9>
1 0% + complete-with-action
1 0% + seq-contains-p
1 0% + mapc
1 0% + vertico-sort-history-length-alpha
1 0% + jit-lock-context-fontify
1 0% + marginalia-annotate-binding
1 0% + profiler-stop
8675 48% + consult-org-roam--remove-capture-dups
5386 30% + file-truename
1939 10% + file-relative-name
1200 6% Automatic GC
227 1% + #<compiled -0x1dff16ed9485c833>
147 0% + #<compiled 0xe42e24cbeb30d77>
95 0% + #<compiled 0x1b94a7bbc16b79ff>
64 0% + #<compiled 0xe0ec30bfd1027e9>
45 0% + consult-org-roam--buffer-list-without-dups
28 0% + read-from-minibuffer
13 0% + #<compiled 0x12cd0dc741558ae2>
11 0% + #<compiled -0x1db98559d8fa03f>
7 0% + org-roam-buffer-list
6 0% + all-completions
5 0% + mapcar
4 0% + org-get-limited-outline-regexp
4 0% + apply
4 0% + #<compiled 0xf22d8c2e0fb90a9>
3 0% + replace-regexp-in-string
3 0% + complete-with-action
3 0% + #<compiled -0x1dff16ffaea7c833>
2 0% + org-roam-descendant-of-p
2 0% + consult--buffer-query
2 0% + org-element--current-element
2 0% + org-roam-file-p
2 0% + org-element-keyword-parser
2 0% + emacsql-escape-scalar
2 0% + abbreviate-file-name
2 0% + #<compiled -0x1cf2072e101497a4>
2 0% + marginalia--function-doc
2 0% + profiler-stop
1 0% + default-font-width
1 0% + org-roam-db--get-connection
1 0% + outline-on-heading-p
1 0% + org-element--collect-affiliated-keywords
1 0% + assq-delete-all
1 0% + smartparens-strict-mode
1 0% + vertico--update
1 0% + #<compiled -0x144835aa48fc5bcc>
1 0% + sort
1 0% + substitute-command-keys
1 0% + timer-activate-when-idle
1 0% + marginalia-annotate-binding
1 0% + timer--time-less-p
1 0% + timer-event-handler
In both cases, I start the profiler, call consult-buffer
via C-x b
, abort with C-g
and stop the profiler.
I do have a lot of buffers (roam's: 265) open at the same time so looking into consult-org-roam--buffer-list-without-dups
:
consult-org-roam/consult-org-roam-buffer.el
Lines 95 to 103 in b93cc85
it seems to do a string match on (length (org-roam-buffer-list))^2
(most of them are not duplicates).
It should probably faster to just look for CAPTURE-.*
first then look for the original buffer?
Tough I don't fully understand the description of consult-org-roam--buffer-list-without-dups
(seems a word is missing) so maybe something evades me.
After executing consult-org-roam-forward-links
I get an error message:
consult--key-parse: [134217774] is not a valid key definition; see ‘key-valid-p’
I found a related issue: minad/consult#747 but I have not figured out how to fix this problem. Can you help?
I personally love consult-org-agenda. I used it 50 times a day. Now I am moving some stuff into org-roam and I would love an analogous function for org-roam. Basically, its just a restriction to headlines with nice faces and fontifying coolness that makes it easy to quickly see the level of a headline.
Currently I am using consult-org-roam-search and just starting searches with * [search]
and that works ok but it has some false positives and nowhere near the cleanliness of consult-org-agenda. The alter also has nice features like showing tags and such.
Just an idea. If I get a chance one day I will try to put it together myself.
Thanks for the great package!
Hello I thik my issue could be trivial but I could not find an answer in the readme.
I'm using consult-org-roam with pretty default config:
(use-package consult-org-roam
:after org-roam
:init
(require 'consult-org-roam)
;; Activate the minor mode
(consult-org-roam-mode 1)
:custom
;; Use `ripgrep' for searching with `consult-org-roam-search'
(consult-org-roam-grep-func #'consult-ripgrep)
;; Configure a custom narrow key for `consult-buffer'
(consult-org-roam-buffer-narrow-key ?r)
;; Display org-roam buffers right after non-org-roam buffers
;; in consult-buffer (and not down at the bottom)
(consult-org-roam-buffer-after-buffers t)
:config
;; Eventually suppress previewing for certain functions
(consult-customize
consult-org-roam-forward-links
:preview-key (kbd "M-."))
:bind
;; Define some convenient keybindings as an addition
("C-c n e" . consult-org-roam-file-find)
("C-c n b" . consult-org-roam-backlinks)
("C-c n r" . consult-org-roam-search))
When I'm using consult-org-roam-search
, the searching itself works good and I see list of results but can't easily jump to the current highlighted search result.
I have tried <RET>
, C-j
, M-j
but they all produce the same message to the Messages buffer:
Wrong type argument: number-or-marker-p, nil
When an org-roam-capture process is in progress, two version of the same capture buffer are listed by consult-buffer
.
Example:
CAPTURE-20221105125319-test.org
20221105125319-test.org
This is not a bug specific to consult-buffer
or even consult-org-roam
because org-roam-buffer-list
lists those duplicates prefixed with "CAPTURE-" as well; nevertheless, it would be preferable to hide those duplicates in consult-org-roam-buffer-source
.
Hi,
thank you for this package! I quickly looked over the code and have a few comments and improvement proposals.
consult-org-roam-no-preview-functions
is unnecessary. You can use consult-customize
to selectively disable preview per command.consult-org-roam/consult-org-roam.el
Line 43 in 3348f97
consult-org-roam--preview-functions
can be removed.consult-org-roam/consult-org-roam.el
Line 239 in 3348f97
add-to-list
I recommend to use push
followed by a subsequent delete-dups
on the final list. It will be more efficient.consult-org-roam/consult-org-roam.el
Line 107 in 3348f97
consult-org-roam--temporary-nodes
looks like consult--temporary-files
. Better reuse consult--temporary-files
such that you avoid the code duplication and such that you profit from future improvements to that function.consult-org-roam/consult-org-roam.el
Line 156 in 3348f97
org-roam-ref-annotation-function
directly. There is no need for the lambda.consult-org-roam/consult-org-roam.el
Line 233 in 3348f97
define-minor-mode
.consult-org-roam/consult-org-roam.el
Line 250 in 3348f97
define-minor-mode
, the message
calls are unnecessary.consult-org-roam/consult-org-roam.el
Line 266 in 3348f97
Hi,
just tested org-roam-consult
and it works as expected, love it!
As a matter of consistency with naming consult extensions, I would suggest naming it consult-org-roam
.
Thanks.
Edit: I did get some warnings, but that's expected with a WIP ;)
With consult-org-roam enabled, capture buffers are no longer listed with consult-buffer. They are visible with switch-to-buffer or when I disable this package.
And not sure if this is related to this bug or even related to this package, or more Consult / Marginalia related, but an error appears when I press the narrow button for the org-roam category while having a capture open (wrong-type-argument stringp nil).
Calling consult-org-roam-file-find
does not search Org heading by default
(require 'org-roam)
(require 'vertico)
(require 'consult)
(require 'consult-org-roam)
(consult-org-roam-mode 1)
(vertico-mode 1)
(setq consult-preview-key 'any)
:PROPERTIES:
:ID: 5f19bb99-cac4-4fff-a607-b6b2ee58fe70
:END:
#+title: test
* heading1
:PROPERTIES:
:ID: 6c640360-7e68-40d3-93c2-19d466071591
:END:
[contents longer than the buffer]
* heading2
:PROPERTIES:
:ID: 02a0aea1-27d7-477f-852e-f8d1437998f3
:END:
[cursor]
The above is a minimal example code and org file. If you place the cursor at the end of the buffer, and then invoke org-roam-node-insert, and then search for "test" item, the previewing function of consult will let you see the title of this buffer, and the cursor will be moved away from its original position. Then if you hit enter, the item will not be inserted to the expected position.
This is related to this issue over at the consult repo.
I'm looking for a way of getting consult-buffer
to treat org-roam buffers in a way that's more useful (to me at least). Basically, I'd want org-roam buffers to be listed among the candidates generated by consult-buffers
using the title rather than the buffer name. The main reason is that I name all my org-roam files using just a timestamp, and that isn't especially informative when trying to find a particular buffer.
As a starting point, I came up with something that sort of works. The main idea is simple and I think on the right track, but the implementation is not quite there yet.
The proposal is to define a new source to add to consult-buffer-sources
which will consist of those buffers listed in (org-roam-buffer-list)
. This source will list items by passing to consult--buffer-query
' a conversion function that will extract the title of the buffer. The key is to make sure that the state function knows to find the corresponding buffer given a title.
A few things are needed:
consult--buffer-preview
and consult--buffer-action
but which will work on titles of org-roam buffers rather than buffer names.Thanks to @minad, I have what is at least a good enough solution to 2.
As for 3, I haven't figured out how to do it in a consult only way. But using marginalia it's fairly straightforward.
The sticking point is 1. I have a solution that sort of works but it's probably not good enough. For one thing, it presupposes no too org-roam buffers have the same title, which is not a reasonable presupposition to make.
Here at last is what I got. I'm sure it can be improved upon in many ways, so take this just as a starting point.
First, we need a translation mechanism. The buffer-to-title translation is easy. The title-to-buffer translation needs some work.
(defun org-roam-buffer-get-title (buffer)
"Get title for BUFFER when it corresponds to an org-roam buffer"
(when (org-roam-buffer-p buffer)
(with-current-buffer buffer (org-roam-db--file-title))))
(defun org-roam-buffer-add-title (buffer)
"Build a cons consisting of the BUFFER title and the BUFFER name"
(cons (org-roam-buffer-get-title buffer) buffer))
(defun org-roam-buffer-update-open-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 #'org-roam-buffer-add-title (org-roam-buffer-list))))
(defun org-roam-buffer-with-title (title)
"Find buffer name with TITLE from among the list of open org-roam
buffers"
(org-roam-buffer-update-open-buffer-list)
(cdr (assoc title org-roam-buffer-open-buffer-list)))
I could not find a sort of 'inverse' of org-roam-db--tile-title
, but if there is one that may be a better bet than what I did to define org-roam-buffer-with-title
.
We then need to define the analogue of consult--buffer-state
(I think @minad had something even more efficient in mind, but I couldn't get his suggestion to work somehow):
(defun org-roam-buffer-state nil
(let
((preview
(consult--buffer-preview)))
(lambda
(action cand)
(funcall preview action (org-roam-buffer-with-title cand))
(when
(and cand
(eq action 'return))
(consult--buffer-action (org-roam-buffer-with-title cand))))))
We can now define a new source for consult-buffer
. Note that I'm using a custom category, which will be useful later when adding an annotator function for marginalia:
(autoload 'org-roam-buffer-list "org-roam")
(defvar org-roam-buffer-source
`(:name "Org-roam"
:hidden nil
:narrow ?r
:category org-roam-buffer
:state ,#'org-roam-buffer-state
:items ,(lambda () (consult--buffer-query :sort 'visibility :as #'org-roam-buffer-get-title :filter nil :predicate (lambda (buf) (org-roam-buffer-p buf))))))
(add-to-list 'consult-buffer-sources 'org-roam-buffer-source 'append)
Finally, an annotator to use with marginalia:
(defun marginalia-annotate-org-roam-buffer (cand)
"Annotate org-roam buffer titled CAND with modification status, file name and major mode."
(when (assoc cand org-roam-buffer-open-buffer-list)
(marginalia-annotate-buffer (org-roam-buffer-with-title cand)))
(add-to-list 'marginalia-annotator-registry
'(org-roam-buffer marginalia-annotate-org-roam-buffer builtin none))
If we put all of this together, we will still see the org-roam buffers included in consult--source-buffer
:
In my case, I can filter them out using consult-buffer-filter
, since all and only my org-roam files match a specific regexp. A more sophisticated approach would perhaps involve modifying the value of the :items
key in consult--source-buffer
so as to exclude org-roam-buffers. I haven't tested this, but presumably:
(consult-customize consult--source-buffer :items (lambda () (consult--buffer-query :sort 'visibility :as #'buffer-name :predicate (lambda (buf) (not (org-roam-buffer-p buf))))))
None of this will work without enabling lexical binding. I learned it the hard way.
I am sorry for the dumb question, and I am also aware that it might be more of a consult
issue. I am new to emacs, and I have been trying for a while to understand how consult-multi
and sources work, but it is going to be a slow process.
Since my primary motivation is to bind consult-org-roam-buffer
to a key instead of calling consult-buffer
and then narrowing it, I thought I'd ask after a lot of unsuccessful attempts.
Is it even possible to call consult-buffer
already 'narrowed' to a source ?
Thanks for your time.
When I took a custom sort function and passed it to consult-org-roam-node-read
, it didn't work.
I'm not an expert in this, but it looks like consult package somehow affects it.
After reading consult's docs, about consult--read in particular, I changed the value of :sort
to nil
consult-org-roam/consult-org-roam.el
Line 157 in 2e6427a
Hi,
When consult-org-roam-node-read
displays node previews, I noticed that sometimes org-mode
is not applied : no text highlighting at all. If I switch to such a node, orgmode is applied correctly.
It appears that whenever there is a latex src block within the node (or the file I do not know), the latex/MPS
major mode takes precedence over orgmode
because of poly-org
which changes the major mode from orgmode
to latex/MPS
whenever the cursor is over a latex src block or fragment.
I tried to prevent this change following the piece of advice here.
It does work for files but not for previews. Is there a way to enforce the major-mode for previews ?
EDIT : previews also try to switch to python-mode when there is a python src block.
Regards
For people who maintain other type of files under their roam directory, the search might be not very efficient by default. I believe there should be an option to search only org files.
My current workflow with ripgrep is appending -- -g *.org
in the search query, not sure if that possible when using consult-grep as a consult-org-roam-grep-func value.
Thanks for this package. It seems that there is a one offset in the processing of the consult-org-roam-buffer-after-buffers
variable. The roam buffers get added before the buffers, not after when I set it to true. More specifically, I get the following (consult--source-hidden-buffer consult--source-modified-buffer org-roam-buffer-source consult--source-buffer consult--source-recent-file consult--source-file-register consult--source-bookmark consult--source-project-buffer-hidden consult--source-project-recent-file-hidden)
. I think the problem is that you have a 1 error offset in the way that you calculate the index here
Remove org-roam-buffer-source
from consult-buffer-sources
when disabling consult-org-roam-mode.
thank you for your wonderful package. It help me a lot.
I have a question I don't know how to solve : After using :preview-key M-. to preview, how to jump to the previewed file directly rather than return back to the origin file when pressing enter?
Strip leading path of candidates presented by consult-org-roam-file-find
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.