The Complete Computing Environment

Consult-Buffer Org Roam Source

LifeTechEmacsTopicsArcology

Okay, so Consult provides a composable, high performance buffer selector in the form of consult-buffer; it has extensible sources that are, basically, built to work with completing-read, so org-roam-find-file can work with it. This is exceedingly powerful as now any of my org-roam files are on my consult-buffer, at my fingertips.

jgru/consult-org-roam provides a bunch of nice features which should be bound in to my org-roam command prefix.. It's not in MELPA or anything, just another thing that expects me to use straight-use-package to load it — well here is some fucked up stuff for providing it to Arroyo Emacs's init generator via ARROYO_HOME_EPKGS.

(condition-case nil
    (use-package consult-org-roam
      :init
      (require 'consult-org-roam)
      ;; Activate the minor-mode
      (consult-org-roam-mode 1)
      :custom
      (consult-org-roam-grep-func #'consult-ripgrep)
      :config
      ;; Eventually suppress previewing for certain functions
      (consult-customize
       consult-org-roam-forward-links
       :preview-key (kbd "M-."))
      ;; restore behavior of consult-buffer overridden by consult-org-roam-buffer... prefer mine.
      (consult-customize
       consult--source-buffer
       :items (lambda ()
                (consult--buffer-query :sort 'visibility
                                       :as #'buffer-name)))
      :bind (:map org-roam-prefix-map)
      ("b" . consult-org-roam-backlinks)
      ("/" . consult-org-roam-search)
      :after (consult org-roam))
  (error nil))

(provide 'cce/consult-org-roam)
consult-org-roam = (let
  versions = pkgs.lib.pkgVersions.consult-org-roam;
  rev = pkgs.lib.pkgVersions.consult-org-roam-rev;
in epkgs.melpaBuild {
  pname = "consult-org-roam";
  version = "20220416.2107";
  commit = rev;

  src = pkgs.callPackage versions {};

  recipe = pkgs.writeText "recipe" ''
      (consult-org-roam
       :repo "jgru/consult-org-roam"
       :fetcher github)
    '';

  packageRequires = [ epkgs.consult epkgs.org-roam ];

  meta = {
    homepage = "https://github.com/jgru/consult-org-roam";
    license = lib.licenses.gpl3Plus;
  };
});

(condition-case nil
    (progn
      (require 'consult)
      (require 'consult-org-roam)

      (defface consult-org-roam
        '((t :inherit font-lock-function-name-face))
        "Face used to highlight org-roam entries in `consult-buffer'.")

      (defvar consult--source-org-roam
        `(
          :name     "Org Roam"
          :narrow   ?r
          :category org-roam
          :face     consult-org-roam
          :state    consult-org-roam--node-preview
          :action   ,(lambda (cand &optional restore)
                       (org-roam-node-visit
                        (get-text-property 0 'node cand)))
          :items    ,(lambda ()
                       (seq-map (lambda (item) (car item))
                                (org-roam-node-read--completions))))
        "Org-Roam candidate source for `consult-buffer'.")

      ;; disable builtin one which only shows buffers and not nodes...
      (setq consult-buffer-sources (delq 'org-roam-buffer-source consult-buffer-sources))
      (add-to-list 'consult-buffer-sources 'consult--source-org-roam t))
  (error nil)
  )
(provide 'cce/consult-buffer-org-roam)

NEXT figure out why this has to be crammed in to extraEmacsPackages in Arroyo Home Manager support for Emacs