-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Jan edited this page Dec 11, 2022
·
9 revisions
To test the package, resort to the following elisp snippet that uses straight to install a minimal setup using the current HEAD of this repo.
Fire up emacs -Q
and paste the snippet into the scratch buffer and then execute eval-buffer
.
;; Minimal setup to test the package
(setq test-org-roam-directory (make-temp-file "roam-" t))
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq package-enable-at-startup nil)
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
;; disable verbose warnings related to native-compilation
(require 'comp nil t)
(when (fboundp 'native-compile)
(setq native-comp-async-report-warnings-errors nil))
;; Minibuffer-Completion UI
(use-package vertico
;; Instruct straight to link extensions as well
:straight '( vertico :files (:defaults "extensions/*")
:includes (vertico-buffer
vertico-directory
vertico-flat
vertico-indexed
vertico-mouse
vertico-quick
vertico-repeat
vertico-reverse))
:defer nil
:bind (:map vertico-map
("C-n" . vertico-next)
("C-p" . vertico-previous)
("C-<return>" . vertico-exit-input)
("C-f" . vertico-exit)
("C-j" . vertico-insert)
("C-d" . vertico-directory-enter)
("M-d" . backward-kill-word))
:custom
(vertico-resize nil)
(vertico-cycle t)
:config
;; Add a visual indicator in the form of an arrow
(advice-add #'vertico--format-candidate :around
(lambda (orig cand prefix suffix index _start)
(setq cand (funcall orig cand prefix suffix index _start))
(concat
(if (= vertico--index index)
(propertize "> " 'face 'vertico-current)
" ")
cand)))
:init
(vertico-mode))
(use-package consult
:straight (:host github :repo "minad/consult")
:hook (completion-list-mode . consult-preview-at-point-mode)
:init
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(setq register-preview-delay 0
register-preview-function #'consult-register-format)
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
(advice-add #'register-preview :override #'consult-register-window)
;; Optionally replace `completing-read-multiple' with an enhanced version.
(advice-add #'completing-read-multiple :override #'consult-completing-read-multiple)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
;; Configure other variables and modes in the :config section,
;; after lazily loading the package.
:config
;; any key triggers the preview.
(setq consult-preview-key 'any)
(setq consult-narrow-key (kbd "C-+" )))
(use-package org-roam
:straight (:host github :repo "org-roam/org-roam"
:files (:defaults "extensions/*"))
:after (org) ;;emacsql-sqlite-builtin)
:hook
(org-roam-backlinks-mode . turn-on-visual-line-mode)
;; Get `org-roam-preview-visit' and friends to replace the main window. This
;; should be applicable only when `org-roam-mode' buffer is displayed in a
;; side-window.
(org-roam-mode-hook .
(lambda ()
(setq-local display-buffer--same-window-action
'(display-buffer-use-some-window
(main)))))
:init
(setq org-roam-v2-ack t)
:custom
;; Do not exclude "data/"
(org-roam-file-exclude-regexp nil)
;; FIXME: Add the path to the org-roam-directory here
(org-roam-directory test-org-roam-directory)
(org-roam-link-use-custom-faces 'everywhere)
;; Make org-roam buffer sticky; i.e. don't replace it when opening a
;; file with an *-other-window command.
(org-roam-buffer-window-parameters '((no-delete-other-windows . t)))
(org-roam-completion-everywhere t)
(org-roam-completion-system 'vertico)
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert)
("C-c n c" . +org-roam-custom-capture-with-link)
("C-c n l" . org-roam-buffer-toggle))
:config
(org-roam-setup)
(setq org-roam-node-display-template
(concat "${title:*} "
(propertize "${tags:10}" 'face 'org-tag)))
(org-roam-db-autosync-mode)
;; Customize Size and placement of org-roam buffer
(add-to-list 'display-buffer-alist
'("\\*org-roam\\*"
(display-buffer-in-side-window)
(dedicated . t)
(side . right)
(slot . 0)
(window-width . 0.25)
(preserve-size . (t nil))
;; (window-parameters . ((no-other-window . nil)
;; (no-delete-other-windows . t))))
))
;;(setq pop-up-windows nil)
;; Make org-open-at-point open in the same window
(setf (cdr (assoc 'file org-link-frame-setup)) 'find-file)
(advice-remove #'org-roam-capture #'+org-roam-custom-capture-with-link)
(advice-add #'org-roam-capture :before #'+org-roam-custom-capture-with-link))
(use-package f
:straight t)
(use-package consult-org-roam
:straight (:host github :repo "jgru/consult-org-roam")
;; For local changes, use something like
;; :load-path "./my-lisp/consult-org-roam"
:after org-roam
:init
(require 'consult-org-roam)
(consult-org-roam-mode 1)
:custom
(consult-org-roam-grep-func #'consult-ripgrep)
:bind
("C-c n e" . consult-org-roam-file-find)
("C-c n b" . consult-org-roam-backlinks)
("C-c n s" . consult-org-roam-search))
(with-eval-after-load 'org-roam
(defun create-org-roam-dummy-note (title body)
"Create an org-roam note file with TITLE and content BODY."
(let* ((slug (org-roam-node-slug (org-roam-node-create :title title)))
(filename (concat (file-name-as-directory org-roam-directory)
(format "%d-%s.org"
(time-convert (current-time) 'integer)
slug)))
(org-id-overriding-file-name filename)
id)
(with-temp-buffer
filename
(insert ":PROPERTIES:\n:ID: \n:END:\n#+title: "
title)
(goto-char 25)
(setq id (org-id-get-create))
(goto-char (point-max))
(newline 2)
(insert body)
(write-file filename)
(org-roam-db-update-file filename))))
(defun populate-org-roam-with-dummy-notes ()
"Create some test notes in org-roam-directory."
(let ((elems '("alpha" "bravo" "charlie" "delta" "echo" "foxtrot")))
;; Check existence of org-roam-directory
(when (not (file-directory-p org-roam-directory))
(make-directory org-roam-directory))
;; Create the single notes
(dolist (elt elems )
(create-org-roam-dummy-note elt
(concat "This is the body of a note about " elt)))))
(populate-org-roam-with-dummy-notes))
To use that minimal sample config, just run:
emacs -Q -l ./minimal-setup.el
Here, is an approach that builds off of consult-ripgrep
search both in org-roam
and org-agenda
at the same time.
The following snippet has been contributed by @jsilve24 during the discussion on #11:
(setq +org-directory (concat default-data-directory "org/"))
(defun +consult-org-roam-and-agenda-search-headlines (&optional initial)
"Run Ripgrep on org-directory only on *.org files."
(interactive)
(let* ((heading-regexp "^*+\\ ")
(consult-ripgrep-args "rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number -g \"*.org\" ."))
(if initial
(funcall consult-org-roam-grep-func +org-directory (format "%s" (concat heading-regexp initial)))
(funcall consult-org-roam-grep-func +org-directory (format "%s" heading-regexp)))))