diff options
| author | Eric Abrahamsen | 2018-10-23 10:51:37 +0800 |
|---|---|---|
| committer | Eli Zaretskii | 2018-11-03 10:39:20 +0200 |
| commit | 4e9644475727ff718c2c8b0d2ef091aaf3e751c8 (patch) | |
| tree | 9047b87cb4309704277589d404e3eb5a37fe7a90 | |
| parent | 1f38454e00826c958807340d156302a78158966f (diff) | |
| download | emacs-4e9644475727ff718c2c8b0d2ef091aaf3e751c8.tar.gz emacs-4e9644475727ff718c2c8b0d2ef091aaf3e751c8.zip | |
Allow use of Gnus search groups as notmuch path: search term
* lisp/gnus/nnir.el (nnir-notmuch-filter-group-names-function): New
option governing whether and how to use Gnus' search groups as path:
search terms to notmuch.
(nnir-run-notmuch): Check and possibly use above variable.
(Bug#33122)
| -rw-r--r-- | lisp/gnus/nnir.el | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/lisp/gnus/nnir.el b/lisp/gnus/nnir.el index 7e5f56e4dd0..ea7257d0c9b 100644 --- a/lisp/gnus/nnir.el +++ b/lisp/gnus/nnir.el | |||
| @@ -518,6 +518,26 @@ that it is for notmuch, not Namazu." | |||
| 518 | :type '(regexp) | 518 | :type '(regexp) |
| 519 | :group 'nnir) | 519 | :group 'nnir) |
| 520 | 520 | ||
| 521 | (defcustom nnir-notmuch-filter-group-names-function | ||
| 522 | #'gnus-group-short-name | ||
| 523 | "Whether and how to use Gnus group names as \"path:\" search terms. | ||
| 524 | When nil, the groups being searched in are not used as notmuch | ||
| 525 | :path search terms. It's still possible to use \"path:\" terms | ||
| 526 | manually within the search query, however. | ||
| 527 | |||
| 528 | When a function, map this function over all the group names. By | ||
| 529 | default this runs them through `gnus-group-short-name', and it is | ||
| 530 | recommended to use this transform, at least. Further | ||
| 531 | transforms (for instance, converting \".\" to \"/\") can be | ||
| 532 | added like so: | ||
| 533 | |||
| 534 | \(add-function :filter-return | ||
| 535 | nnir-notmuch-filter-group-names-function | ||
| 536 | (lambda (g) (replace-regexp-in-string \"\\\\.\" \"/\" g)))" | ||
| 537 | :version "27.1" | ||
| 538 | :type '(choice function | ||
| 539 | nil)) | ||
| 540 | |||
| 521 | ;;; Developer Extension Variable: | 541 | ;;; Developer Extension Variable: |
| 522 | 542 | ||
| 523 | (defvar nnir-engines | 543 | (defvar nnir-engines |
| @@ -1505,23 +1525,30 @@ Tested with Namazu 2.0.6 on a GNU/Linux system." | |||
| 1505 | (> (nnir-artitem-rsv x) | 1525 | (> (nnir-artitem-rsv x) |
| 1506 | (nnir-artitem-rsv y))))))))) | 1526 | (nnir-artitem-rsv y))))))))) |
| 1507 | 1527 | ||
| 1508 | (defun nnir-run-notmuch (query server &optional _group) | 1528 | (defun nnir-run-notmuch (query server &optional groups) |
| 1509 | "Run QUERY against notmuch. | 1529 | "Run QUERY against notmuch. |
| 1510 | Returns a vector of (group name, file name) pairs (also vectors, | 1530 | Returns a vector of (group name, file name) pairs (also vectors, |
| 1511 | actually)." | 1531 | actually). If GROUPS is a list of group names, use them to |
| 1512 | 1532 | construct path: search terms (see the variable | |
| 1513 | ;; (when group | 1533 | `nnir-notmuch-filter-group-names-function')." |
| 1514 | ;; (error "The notmuch backend cannot search specific groups")) | ||
| 1515 | 1534 | ||
| 1516 | (save-excursion | 1535 | (save-excursion |
| 1517 | (let ( (qstring (cdr (assq 'query query))) | 1536 | (let* ((qstring (cdr (assq 'query query))) |
| 1518 | (groupspec (cdr (assq 'notmuch-group query))) | ||
| 1519 | (prefix (nnir-read-server-parm 'nnir-notmuch-remove-prefix server)) | 1537 | (prefix (nnir-read-server-parm 'nnir-notmuch-remove-prefix server)) |
| 1520 | artlist | 1538 | artlist |
| 1521 | (article-pattern (if (string-match "\\`nnmaildir:" | 1539 | (article-pattern (if (string-match "\\`nnmaildir:" |
| 1522 | (gnus-group-server server)) | 1540 | (gnus-group-server server)) |
| 1523 | ":[0-9]+" | 1541 | ":[0-9]+" |
| 1524 | "^[0-9]+$")) | 1542 | "^[0-9]+$")) |
| 1543 | (groups (when nnir-notmuch-filter-group-names-function | ||
| 1544 | (mapcar nnir-notmuch-filter-group-names-function | ||
| 1545 | groups))) | ||
| 1546 | (pathquery (when groups | ||
| 1547 | (concat "(" | ||
| 1548 | (mapconcat (lambda (g) | ||
| 1549 | (format " path:%s" g)) | ||
| 1550 | groups " or") | ||
| 1551 | ")"))) | ||
| 1525 | artno dirnam filenam) | 1552 | artno dirnam filenam) |
| 1526 | 1553 | ||
| 1527 | (when (equal "" qstring) | 1554 | (when (equal "" qstring) |
| @@ -1530,10 +1557,14 @@ actually)." | |||
| 1530 | (set-buffer (get-buffer-create nnir-tmp-buffer)) | 1557 | (set-buffer (get-buffer-create nnir-tmp-buffer)) |
| 1531 | (erase-buffer) | 1558 | (erase-buffer) |
| 1532 | 1559 | ||
| 1533 | (if groupspec | 1560 | (if groups |
| 1534 | (message "Doing notmuch query %s on %s..." qstring groupspec) | 1561 | (message "Doing notmuch query %s on %s..." |
| 1562 | qstring (mapconcat #'identity groups " ")) | ||
| 1535 | (message "Doing notmuch query %s..." qstring)) | 1563 | (message "Doing notmuch query %s..." qstring)) |
| 1536 | 1564 | ||
| 1565 | (when groups | ||
| 1566 | (setq qstring (concat qstring pathquery))) | ||
| 1567 | |||
| 1537 | (let* ((cp-list `( ,nnir-notmuch-program | 1568 | (let* ((cp-list `( ,nnir-notmuch-program |
| 1538 | nil ; input from /dev/null | 1569 | nil ; input from /dev/null |
| 1539 | t ; output | 1570 | t ; output |
| @@ -1571,10 +1602,7 @@ actually)." | |||
| 1571 | (when (string-match article-pattern artno) | 1602 | (when (string-match article-pattern artno) |
| 1572 | (when (not (null dirnam)) | 1603 | (when (not (null dirnam)) |
| 1573 | 1604 | ||
| 1574 | ;; maybe limit results to matching groups. | 1605 | (nnir-add-result dirnam artno "" prefix server artlist)))) |
| 1575 | (when (or (not groupspec) | ||
| 1576 | (string-match groupspec dirnam)) | ||
| 1577 | (nnir-add-result dirnam artno "" prefix server artlist))))) | ||
| 1578 | 1606 | ||
| 1579 | (message "Massaging notmuch output...done") | 1607 | (message "Massaging notmuch output...done") |
| 1580 | 1608 | ||