branch: externals/consult-recoll commit 34e883562cfc689d96c35e4da7dda8c46aaa1227 Author: jao <j...@gnu.org> Commit: jao <j...@gnu.org>
initial implementation --- README.md | 3 -- consult-recoll.el | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE => license | 0 readme.org | 7 +++++ 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md deleted file mode 100644 index baeefd4ade..0000000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# consult-recoll - -recoll queries in emacs using consult \ No newline at end of file diff --git a/consult-recoll.el b/consult-recoll.el new file mode 100644 index 0000000000..1a57abb130 --- /dev/null +++ b/consult-recoll.el @@ -0,0 +1,86 @@ +;;; consult-recoll.el --- Recoll searches using consult -*- lexical-binding: t; -*- + +;; Author: Jose A Ortega Ruiz <j...@gnu.org> +;; Maintainer: Jose A Ortega Ruiz +;; Keywords: docs, convenience +;; License: GPL-3.0-or-later +;; Version: 0.1 +;; Package-Requires: ((emacs "26.1") (consult "0.5")) +;; Homepage: https://codeberg.org/jao/consult-recoll + +;; Copyright (C) 2021 Jose A Ortega Ruiz + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; A simple consult-recoll function to perform simple queries over +;; your Recoll (https://www.lesbonscomptes.com/recoll/) index. + +;;; Code: + +(require 'consult) + +(defvar consult-recoll--command + "recollq -a -F \"url title\" ARG" + "Command used to perform queries.") + +(defvar consult-recoll--open-fn #'find-file + "Function used to open candidate URL.") + +(defface consult-recoll-url-face '((t :inherit default)) + "Face used to display URLs of candidates.") + +(defface consult-recoll-title-face '((t :inherit italic)) + "Face used to display titles of candidates.") + +(defvar consult-recoll-history nil "History for `consult-recoll'.") + +(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))))) + +(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)))) + +(defun consult-recoll--search (&optional initial) + "Perform an asynchronous recoll search via `consult--read'. +If given, use INITIAL as the starting point of the query." + (consult--read (consult--async-command consult-recoll--command + (consult--async-filter (lambda (x) (not (null x)))) + (consult--async-map #'consult-recoll--transformer)) + :prompt "Recoll search: " + :require-match t + :initial (concat consult-async-default-split initial) + :history 'consult-recoll-history + :category 'recoll-result)) + +;;;###autoload +(defun consult-recoll () + "Consult recoll's local index." + (interactive) + (consult-recoll--open (consult-recoll--search))) + +(provide 'consult-recoll) +;;; consult-recoll.el ends here diff --git a/LICENSE b/license similarity index 100% rename from LICENSE rename to license diff --git a/readme.org b/readme.org new file mode 100644 index 0000000000..3b6a263f14 --- /dev/null +++ b/readme.org @@ -0,0 +1,7 @@ +#+title: consult-recoll + +[[(https://www.lesbonscomptes.com/recoll/][recoll]] queries in emacs using consult. + +This package requires a working recoll index, and ~recollq~ in your +path. =M-x consult-recoll= to perform a query on the index using +consult.