[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult-recoll f36b727a91: search for snippet text in t
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult-recoll f36b727a91: search for snippet text in text mime types |
Date: |
Sun, 14 Aug 2022 14:57:25 -0400 (EDT) |
branch: externals/consult-recoll
commit f36b727a91c9c6a51dc50498a7074725ca130d17
Author: jao <jao@gnu.org>
Commit: jao <jao@gnu.org>
search for snippet text in text mime types
---
consult-recoll.el | 32 +++++++++++++++++++++++---------
readme.org | 7 ++++++-
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/consult-recoll.el b/consult-recoll.el
index d6b57bd274..1f31431b2d 100644
--- a/consult-recoll.el
+++ b/consult-recoll.el
@@ -131,19 +131,33 @@ Set to nil to use the default 'title (path)' format."
(defsubst consult-recoll--snippets (&optional candidate)
(get-text-property 0 'snippets (or candidate consult-recoll--current "")))
-(defsubst consult-recoll--find-file (file &optional _page) (find-file file))
+(defun consult-recoll--search-snippet (candidate mime)
+ "When CANDIDATE is the text of a snippet, search for it in current buffer."
+ (when (string-match "^\s+0 : " candidate)
+ (let ((txt (replace-match "" nil nil candidate)))
+ (goto-char (point-min))
+ (when (or (search-forward txt nil t)
+ (and (derived-mode-p 'org-mode)
+ (search-forward (replace-regexp-in-string "\\]\\].+" ""
+ txt nil t)))
+ (and (string= mime "text/html")
+ (search-forward (substring txt 0 (/ (length txt) 2)) nil
t)))
+ (goto-char (match-beginning 0))
+ (when (derived-mode-p 'org-mode) (org-reveal))))))
(defun consult-recoll--open (candidate)
"Open file of corresponding completion CANDIDATE."
(when candidate
- (let ((url (consult-recoll--candidate-url candidate))
- (open (alist-get (consult-recoll--candidate-mime candidate)
- consult-recoll-open-fns
- (or consult-recoll-open-fn
'consult-recoll--find-file)
- nil 'string=)))
- (if consult-recoll-inline-snippets
- (funcall open url (consult-recoll--candidate-page candidate))
- (funcall open url)))))
+ (let* ((url (consult-recoll--candidate-url candidate))
+ (mime (consult-recoll--candidate-mime candidate))
+ (open (or (cdr (assoc mime consult-recoll-open-fns))
+ consult-recoll-open-fn
+ (lambda (f &optional _ignored) (find-file f)))))
+ (if (not consult-recoll-inline-snippets)
+ (funcall open url)
+ (funcall open url (consult-recoll--candidate-page candidate))
+ (when (string-prefix-p "text/" mime)
+ (consult-recoll--search-snippet candidate mime))))))
(defun consult-recoll--transformer (str)
"Decode STR, as returned by recollq."
diff --git a/readme.org b/readme.org
index 738d29cca0..54e67a7416 100644
--- a/readme.org
+++ b/readme.org
@@ -160,7 +160,12 @@ it directly via =M-x package-install RET consult-recoll
RET=.
If ~consult-recoll-inline-snippets~ is set, the functions above take two
arguments: the URL of the file to open and, if present, the snippet page
number (or ~nil~ if it is not available, e.g., because the selected
candidate
- is the one showing the document data)
+ is the one showing the document data).
+
+ If the selected candidate is a snippet corresponding to a text MIME and the
+ page number of the snippet is 0 (as is often the case, since text files are
+ normally not paginated), ~consult-recoll~ will perform a search for the
+ snippet text after opening the file.
See also [[#embark][Integration with embark-collect]] for an alternative
way of listing
and opening search results using embark.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/consult-recoll f36b727a91: search for snippet text in text mime types,
ELPA Syncer <=