From 0369a12e2715719e60768ab0b57c65a04f438c4b Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 15 Jun 2022 01:43:14 +0100 Subject: jao-recoll: better display of text/x-orgmode-sub links --- lib/doc/jao-recoll.el | 54 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/doc/jao-recoll.el b/lib/doc/jao-recoll.el index f43451f..36780ad 100644 --- a/lib/doc/jao-recoll.el +++ b/lib/doc/jao-recoll.el @@ -1,4 +1,4 @@ -;; jao-recoll.el -- Displaying recoll queries +;; jao-recoll.el -- Displaying recoll queries -*- lexical-binding: t; -*- ;; Copyright (c) 2017, 2020, 2021, 2022 Jose Antonio Ortega Ruiz @@ -34,7 +34,7 @@ (read-only-mode 1)) (defvar jao-recoll--file-regexp - "\\(\\w+/.+\\)\t+\\[\\([^]]+\\)\\]\t+\\[\\([^]]+\\)\\].+") + "\\(\\w+/.+\\)\t+\\[\\([^]]+\\)\\]\t+\\[\\([^\t]+\\)\\].+") (defvar jao-recoll-flags "-A -p 5 -n 100") @@ -64,8 +64,7 @@ using org mode." (let* ((query (read-string "Recoll query: " prefix-query)) (cmd (format "recoll %s -t %s" jao-recoll-flags (shell-quote-argument query))) - (inhibit-read-only t) - (lnk nil)) + (inhibit-read-only t)) (with-current-buffer (jao-recoll--buffer query) (recoll-mode) (delete-region (point-min) (point-max)) @@ -80,24 +79,35 @@ using org mode." (forward-line 2)) (open-line 1) (while (search-forward-regexp jao-recoll--file-regexp nil t) - (setq lnk - (cond ((string= (match-string 1) "application/pdf") - (concat "doc:" - (file-name-nondirectory (match-string 2)))) - ((string= (match-string 1) "message/rfc822") - (concat "message:" (substring (match-string 2) 7))) - (t (match-string 2)))) - (replace-match (format "* [[%s][\\3]] (\\1)" lnk)) - (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))))) + (let* ((mime (match-string 1)) + (ref (match-string 2)) + (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)))) + (delete-region start end) + (insert (format "* [[%s][%s]] (%s)" 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)))))) (pop-to-buffer (current-buffer)) (goto-char (point-min)) (org-next-visible-heading 1) -- cgit v1.2.3