summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-08-28 00:04:27 +0100
committerjao <jao@gnu.org>2021-08-28 00:35:28 +0100
commit2f83449a712b31855f58d0d448531477fe74ed58 (patch)
tree0ba3553f06fbdc80ff30720a5067d02ab2d71ea0 /lib/doc
parentbc5799d5149781d1aa39a48a6ea22166fa12afc4 (diff)
downloadelibs-2f83449a712b31855f58d0d448531477fe74ed58.tar.gz
elibs-2f83449a712b31855f58d0d448531477fe74ed58.tar.bz2
jao-org-notes: new consult async protocol
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-org-notes.el23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el
index 391fa47..2c328c5 100644
--- a/lib/doc/jao-org-notes.el
+++ b/lib/doc/jao-org-notes.el
@@ -24,35 +24,36 @@
;; backlinks approximation.
;;; Code:
-
(require 'org)
(require 'consult)
(defvar jao-org-notes-dir (expand-file-name "notes" org-directory))
-(defvar jao-org-notes--rg
- (concat "rg --null --line-buffered --color=ansi --max-columns=250"
- " --no-heading --line-number --smart-case"
- " . -e \"^(#.(title|filetags): .*)ARG\" OPTS"))
+(defun jao-org-notes--rg (str)
+ `("rg" "--null" "--line-buffered" "--color=never" "--max-columns=250"
+ "--no-heading" "--line-number" "--smart-case" "." "-e"
+ ,(format "^(#.(title|filetags): .*)%s" str)))
-(defvar jao-org-notes--trx ":[0-9]+:#\\+\\(file\\)?\\(title\\|tags\\):")
+(defvar jao-org-notes--trx "[0-9]+:#\\+\\(file\\)?\\(title\\|tags\\):")
(defun jao-org-notes--clean-match (m)
- (cons (replace-regexp-in-string jao-org-notes--trx " (\\2)" (car m)) (cdr m)))
+ (cons (format "%s %s"
+ (replace-regexp-in-string "^\\./" "" (car m))
+ (replace-regexp-in-string jao-org-notes--trx " (\\2)" (cadr m)))
+ (expand-file-name (car m) default-directory)))
(defun jao-org-notes--matches (lines)
- (let ((ms (consult--grep-matches lines)))
- (mapcar #'jao-org-notes--clean-match ms)))
+ (mapcar (lambda (l) (jao-org-notes--clean-match (split-string l "\0" t))) lines))
(defun jao-org-notes--lookup (_ cands cand)
- (or (cadr (assoc cand cands)) cand))
+ (or (cdr (assoc cand cands)) cand))
(defvar jao-org-notes--grep-history nil)
(defun jao-org--grep (prompt &optional cat no-req)
(let ((default-directory (expand-file-name (or cat "") jao-org-notes-dir)))
(consult--read
- (consult--async-command jao-org-notes--rg
+ (consult--async-command #'jao-org-notes--rg
(consult--async-transform jao-org-notes--matches))
:prompt prompt
:lookup #'jao-org-notes--lookup