GithubHelp home page GithubHelp logo

jgru / consult-org-roam Goto Github PK

View Code? Open in Web Editor NEW
111.0 111.0 6.0 91 KB

A bunch of convenience functions for operating org-roam with the help of consult

License: GNU General Public License v3.0

Emacs Lisp 100.00%

consult-org-roam's People

Contributors

fuzzbomb avatar hpfr avatar jedrz avatar jgru avatar martyone avatar meliache avatar sjrmanning avatar thisirs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

consult-org-roam's Issues

Feature Request / Idea

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!

Get only Org results

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.

Question: purpose of consult-org-roam-file-find

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.

consult-org-roam-buffer-after-buffers does not produce the expected outcome

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

Sorting (sort-fn) function does not work

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

:sort sort-fn
and everything worked out.

Change order of package name

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 ;)

consult-org-roam-forward-links is not working

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?

Change default `#'consult-org-roam-grep-func`

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!

consult-buffer doesn't show capture buffers

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).

Backtrace

How to jump to the search result?

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

`consult-buffer` slowness when using `consult-org-roam`

I've been experimenting with consult-org-roam but find that consult-buffer becomes very slow once it's activated.

profiler result w/o `consult-org-roam`

         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

profiler result w `consult-org-roam`

        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:

(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))

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.

consult-buffer shows duplicate capture buffers

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.

Why the order is not respected ?

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.

Add function to create dummy data for testing purposes

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

[BUG] cursor moved when previewing the same buffer and the first item is far from the current cursor

(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.

major-mode not applied in previews for consult-org-roam-node-read

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

Quick review

Hi,

thank you for this package! I quickly looked over the code and have a few comments and improvement proposals.

consult-org-roam-buffer, do not alter visiting order of buffers

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.

Rough idea: add source for consult-buffer

This is related to this issue over at the consult repo.

Feature request

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.

A start

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 main idea

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:

  1. A 'translation' mechanism that allows us to get buffers from titles and vice versa.
  2. Two functions that will mimic consult--buffer-preview and consult--buffer-action but which will work on titles of org-roam buffers rather than buffer names.
  3. A way of annotating the list of org-roam titles.

Where I am at

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.

Annotated proposal

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:

image

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))))))

image

None of this will work without enabling lexical binding. I learned it the hard way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.