[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult-recoll 357654bedd 04/50: customisable formatter
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult-recoll 357654bedd 04/50: customisable formatter and candidate openers |
Date: |
Sat, 6 Aug 2022 18:57:40 -0400 (EDT) |
branch: externals/consult-recoll
commit 357654beddf3de0e13ebb41eb3a59c7c0890dfd1
Author: jao <jao@gnu.org>
Commit: jao <jao@gnu.org>
customisable formatter and candidate openers
---
consult-recoll.el | 56 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/consult-recoll.el b/consult-recoll.el
index 62cf1bc60c..70268d085d 100644
--- a/consult-recoll.el
+++ b/consult-recoll.el
@@ -1,4 +1,4 @@
-;;; consult-recoll.el --- Recoll searches using consult -*- lexical-binding:
t; -*-
+;;; consult-recoll.el --- Recoll queries using consult -*- lexical-binding:
t; -*-
;; Author: Jose A Ortega Ruiz <jao@gnu.org>
;; Maintainer: Jose A Ortega Ruiz
@@ -25,8 +25,10 @@
;;; Commentary:
-;; A simple consult-recoll function to perform simple queries over
-;; your Recoll (https://www.lesbonscomptes.com/recoll/) index.
+;; A `consult-recoll' command to perform simple interactive queries
+;; over your Recoll (https://www.lesbonscomptes.com/recoll/) index.
+;; See the corresponding custumization group for ways to tweak its
+;; behaviour to your needs.
;;; Code:
@@ -37,10 +39,20 @@
:group 'consult)
(defcustom consult-recoll-open-fn #'find-file
- "Function used to open candidate URL.
-It receives a single argument, the full path to the file to open."
+ "Default function used to open candidate URL.
+It receives a single argument, the full path to the file to open.
+See also `consult-recoll-open-fns'"
:type 'function)
+(defcustom consult-recoll-open-fns ()
+ "Alist mapping mime types to functions to open a selected candidate."
+ :type '(alist :key-type string :value-type function))
+
+(defcustom consult-recoll-format-candidate nil
+ "A function taking title, path and mime type, and formatting them for
display.
+Set to nil to use the default 'title (path)' format."
+ :type '(choice (const nil) function))
+
(defface consult-recoll-url-face '((t :inherit default))
"Face used to display URLs of candidates.")
@@ -50,25 +62,35 @@ It receives a single argument, the full path to the file to
open."
(defvar consult-recoll-history nil "History for `consult-recoll'.")
(defvar consult-recoll--command
- "recollq -a -F \"url title\" ARG"
+ "recollq -a -F \"url title mtype\" ARG"
"Command used to perform queries.")
(defun consult-recoll--transformer (str)
"Decode STR, as returned by recollq."
(unless (string-match-p "^\\(Recoll query:\\|[0-9]+ results\\| *$\\)" str)
- (let* ((cmps (split-string str " " t))
- (url+title (seq-map #'base64-decode-string cmps))
- (url (car url+title))
- (title (or (cadr url+title) (file-name-base url)))
- (url (if (string-prefix-p "file://" url) (substring url 7) url)))
- (format "%s (%s)"
- (propertize title 'face 'consult-recoll-title-face)
- (propertize url 'face 'consult-recoll-url-face)))))
+ (let* ((cmps (split-string str " "))
+ (fields (seq-map #'base64-decode-string cmps))
+ (url (car fields))
+ (title (cadr fields))
+ (title (if (string= "" title) (file-name-base url) title))
+ (urln (if (string-prefix-p "file://" url) (substring url 7) url))
+ (mime (nth 2 fields))
+ (cand (if consult-recoll-format-candidate
+ (funcall consult-recoll-format-candidate title urln mime)
+ (format "%s (%s)"
+ (propertize title 'face 'consult-recoll-title-face)
+ (propertize urln 'face 'consult-recoll-url-face)))))
+ (propertize cand 'mime-type mime 'url urln))))
(defun consult-recoll--open (candidate)
"Open file of corresponding completion CANDIDATE."
- (when (string-match ".+ (\\(.+\\))$" (or candidate ""))
- (funcall consult-recoll-open-fn (match-string 1 candidate))))
+ (when candidate
+ (let ((url (get-text-property 0 'url candidate))
+ (opener (alist-get (get-text-property 0 'mime-type candidate)
+ consult-recoll-open-fns
+ (or consult-recoll-open-fn #'find-file)
+ nil 'string=)))
+ (funcall opener url))))
(defun consult-recoll--search (&optional initial)
"Perform an asynchronous recoll search via `consult--read'.
@@ -78,6 +100,8 @@ If given, use INITIAL as the starting point of the query."
(consult--async-map #'consult-recoll--transformer))
:prompt "Recoll search: "
:require-match t
+ :lookup (lambda (_ cs c)
+ (seq-find (lambda (x) (string= c x)) cs))
:initial (concat consult-async-default-split initial)
:history 'consult-recoll-history
:category 'recoll-result))
- [elpa] externals/consult-recoll c8e0849308 06/50: readme tweaks, (continued)
- [elpa] externals/consult-recoll c8e0849308 06/50: readme tweaks, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll b0fa4831e0 15/50: fix: using recoll's candidate ordering rather than alphabetical, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 0ba5ae1b53 17/50: fix for consult-recoll's input history, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll ba3fcb8bae 28/50: readme: melpa badges, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 9ce929510f 47/50: fix: reset index and current for every new search term, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll d550a76ffb 24/50: a bit more structure, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 85a527af31 27/50: wee commentary tweaks, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 57f2a5552f 31/50: Version bump, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 0105066d19 32/50: readme nits and screenshot, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 370a31d1c4 09/50: MELPA review, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 357654bedd 04/50: customisable formatter and candidate openers,
ELPA Syncer <=
- [elpa] externals/consult-recoll 1b21fa157b 16/50: version bump, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll c824a2fea2 21/50: fix for C-u consult-recoll, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 8ba4d4b9b8 39/50: hide cursor in non-selected preview windows, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 3399c32322 23/50: readme, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll a2ee98e057 45/50: version bump, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 91ff9793b5 25/50: readme improvements, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 8e45c4d3df 42/50: new feature: inline snippets, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll eab09d7fe6 44/50: documentation nits (section levels), ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll d9bb5e191e 33/50: docstring nit, ELPA Syncer, 2022/08/06
- [elpa] externals/consult-recoll 42dea1d40f 18/50: consult-recoll: prefix argument to ask for initial input, ELPA Syncer, 2022/08/06