summaryrefslogtreecommitdiffhomepage
path: root/lib/doc/jao-recoll.el
diff options
context:
space:
mode:
Diffstat (limited to 'lib/doc/jao-recoll.el')
-rw-r--r--lib/doc/jao-recoll.el61
1 files changed, 33 insertions, 28 deletions
diff --git a/lib/doc/jao-recoll.el b/lib/doc/jao-recoll.el
index 36780ad..b23106f 100644
--- a/lib/doc/jao-recoll.el
+++ b/lib/doc/jao-recoll.el
@@ -1,4 +1,4 @@
-;; jao-recoll.el -- Displaying recoll queries -*- lexical-binding: t; -*-
+;;; jao-recoll.el -- Displaying recoll queries -*- lexical-binding: t; -*-
;; Copyright (c) 2017, 2020, 2021, 2022 Jose Antonio Ortega Ruiz
@@ -22,11 +22,10 @@
;;; Comentary:
;; A simple interactive command to perform recoll queries and display
-;; its results using org-mode.
+;; its results using org markup.
;;; Code:
-
(require 'org)
(define-derived-mode recoll-mode org-mode "Recoll"
@@ -56,10 +55,31 @@
"*Recoll*"
(format "*Recoll: '%s'*" q))))
+(defun jao-recoll--format-snippets (lnk)
+ (when (looking-at-p "SNIPPETS")
+ (let ((kill-whole-line t))
+ (kill-line)
+ (while (and (not (eobp)) (not (looking-at-p "/SNIPPETS")))
+ (cond ((looking-at "^\\([1-9][0-9]*\\) : ")
+ (replace-match (format " - [[%s::\\1][\\1]] : " lnk)))
+ ((looking-at "^0 : \\(.[^\n]+\\)")
+ (let ((desc (match-string 1)))
+ (replace-match " - ")
+ (insert (org-make-link-string lnk desc))))
+ (t (insert " - ")))
+ (forward-line 1))
+ (unless (eobp) (kill-line)))))
+
+(defun jao-recoll--org-link (uri desc mime)
+ (cond ((string= mime "application/pdf")
+ (concat "doc:" (file-name-nondirectory uri)))
+ ((string= mime "message/rfc822") (concat "message:" (substring uri 7)))
+ ((string= mime "text/x-orgmode-sub") (concat uri "::*" desc))
+ (t uri)))
+
;;;###autoload
(defun jao-recoll (&optional prefix-query)
- "Performs a query using recoll and shows the results in a buffer
-using org mode."
+ "Performs a query using recoll and shows the results using org markup."
(interactive)
(let* ((query (read-string "Recoll query: " prefix-query))
(cmd (format "recoll %s -t %s"
@@ -84,30 +104,15 @@ using org mode."
(desc (match-string 3))
(start (match-beginning 0))
(end (match-end 0))
- (lnk (cond ((string= mime "application/pdf")
- (concat "doc:" (file-name-nondirectory ref)))
- ((string= mime "message/rfc822")
- (concat "message:" (substring ref 7)))
- ((string= mime "text/x-orgmode-sub")
- (concat ref "::*" desc))
- (t (match-string 2))))
- (desc (cond ((string= "text/x-orgmode-sub" mime)
- (concat (file-name-nondirectory ref)
- "/"
- (org-link-display-format desc)))
- (t desc))))
+ (lnk (jao-recoll--org-link ref desc mime))
+ (desc (if (string= mime "text/x-orgmode-sub")
+ (org-link-display-format
+ (concat (file-name-nondirectory ref) " :: " desc))
+ desc)))
(delete-region start end)
- (insert (format "* [[%s][%s]] (%s)" lnk desc mime))
+ (insert "* " (org-make-link-string lnk desc) " (" mime ")")
(forward-line)
- (when (looking-at-p "SNIPPETS")
- (let ((kill-whole-line t))
- (kill-line)
- (while (and (not (eobp)) (not (looking-at-p "/SNIPPETS")))
- (if (looking-at "^\\([1-9][0-9]*\\) : ")
- (replace-match (format " - [[%s::\\1][\\1]] : " lnk))
- (insert " - "))
- (forward-line 1))
- (unless (eobp) (kill-line))))))
+ (jao-recoll--format-snippets lnk)))
(pop-to-buffer (current-buffer))
(goto-char (point-min))
(org-next-visible-heading 1)
@@ -121,6 +126,6 @@ using org mode."
(define-key recoll-mode-map [?g] 'jao-recoll-requery)
(define-key recoll-mode-map [?w] 'jao-recoll-show-query)
-
+;;; .
(provide 'jao-recoll)
;;; jao-recoll.el ends here