-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconsult-web-notes.el
92 lines (77 loc) · 4.08 KB
/
consult-web-notes.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; consult-web-notes.el --- Consulting Notes -*- lexical-binding: t -*-
;; Copyright (C) 2024 Armin Darvish
;; Author: Armin Darvish
;; Maintainer: Armin Darvish
;; Created: 2024
;; Version: 0.1
;; Package-Requires: ((emacs "28.1") (consult "1.1"))
;; Homepage: https://github.com/armindarvish/consult-web
;; Keywords: convenience
;;; Commentary:
;;; Code:
(require 'consult-web)
(require 'consult-notes)
(defun consult-web--org-roam-note-preview (cand)
"Preview function for org-roam files."
(if cand
(let* ((title (get-text-property 0 :title cand))
(node (org-roam-node-from-title-or-alias title)))
(if (org-roam-node-p node)
(consult--file-action (org-roam-node-file node))
))))
(defun consult-web--org-headings-preview (cand)
"Preview function for org headings."
(if cand
(let* ((title (get-text-property 0 :title cand))
(marker (get-text-property 0 'consult--candidate title)))
(if marker
(consult--jump marker)))))
(defun consult-web--org-roam-note-callback (cand &rest args)
"Callback function for org-roam files."
(let* ((title (get-text-property 0 :title cand))
(node (org-roam-node-from-title-or-alias title)))
(org-roam-node-open node)))
(defun consult-web--org-headings-callback (cand &rest args)
"Callback function for org headings."
(if cand
(let* ((title (get-text-property 0 :title cand))
(marker (get-text-property 0 'consult--candidate title)))
(if marker
(let* ((buff (marker-buffer marker))
(pos (marker-position marker)))
(if buff (with-current-buffer buff
(if pos (goto-char pos))
(funcall consult--buffer-display buff)
(recenter nil t)
)))
))))
(when consult-notes-org-headings-mode
(consult-web--make-source-from-consult-source 'consult-notes-org-headings--source
:category 'file
:face 'consult-web-notes-source-face
:search-history 'consult-web--search-history
:selection-history 'consult-web--selection-history
:on-preview #'consult-web--org-headings-preview
:on-return #'identity
:on-callback #'consult-web--org-headings-callback
:search-history 'consult-web--search-history
:selection-history 'consult-web--selection-history
:preview-key 'consult-preview-key
:dynamic 'both
))
(when consult-notes-org-roam-mode
(cl-loop for source in '(consult-notes-org-roam--refs consult-notes-org-roam--nodes)
do (consult-web--make-source-from-consult-source source
:category 'file
:face 'consult-web-notes-source-face
:search-history 'consult-web--search-history
:selection-history 'consult-web--selection-history
:on-preview #'consult-web--org-roam-note-preview
:on-return #'identity
:on-callback #'consult-web--org-roam-note-callback
:preview-key 'consult-preview-key
:dynamic 'both)))
;;; provide `consult-web-notes' module
(provide 'consult-web-notes)
(add-to-list 'consult-web-sources-modules-to-load 'consult-web-notes)
;;; consult-web-notes.el ends here