diff options
| author | Eric Abrahamsen | 2020-11-04 21:13:03 -0800 |
|---|---|---|
| committer | Eric Abrahamsen | 2020-11-05 19:47:58 -0800 |
| commit | ac471ff09d9b7874c53447fdd2d06efd2d8b1e40 (patch) | |
| tree | 7ea589a61f96b26aa6a6964d66dbf2247e25c2a6 | |
| parent | 9ab69cc82f08234709168edb6153075e4470b2da (diff) | |
| download | emacs-ac471ff09d9b7874c53447fdd2d06efd2d8b1e40.tar.gz emacs-ac471ff09d9b7874c53447fdd2d06efd2d8b1e40.zip | |
Fixes and improvements to gnus-search
* lisp/gnus/gnus-search.el (gnus-search-default-engines): Change type
from a list of two-element lists, to alist. This matches nnir's old
option type, and should make transition easier.
(nnir-imap-default-search-key): Note that variable is obsolete.
(gnus-search-transform-expression): Interpret the "attachment" key as
"body" in imap searches. Allow specifying larger/smaller message size
values in KB or MB units.
(gnus-search-server-to-engine): Fix error in this function, and
clarify somewhat.
| -rw-r--r-- | lisp/gnus/gnus-search.el | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index 3053501fe74..15d96e3e0c8 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el | |||
| @@ -74,10 +74,6 @@ | |||
| 74 | ;; need a completely separate top-level command, since we wouldn't be | 74 | ;; need a completely separate top-level command, since we wouldn't be |
| 75 | ;; creating a group at all. | 75 | ;; creating a group at all. |
| 76 | 76 | ||
| 77 | ;; TODO: Do better with handling message size searches. Make sure | ||
| 78 | ;; we're providing for the usual shorthands (kb, M, etc), and that all | ||
| 79 | ;; the engines handle it properly. | ||
| 80 | |||
| 81 | ;;; Code: | 77 | ;;; Code: |
| 82 | 78 | ||
| 83 | (require 'gnus-group) | 79 | (require 'gnus-group) |
| @@ -134,6 +130,10 @@ transformed." | |||
| 134 | :type 'regexp | 130 | :type 'regexp |
| 135 | :group 'gnus-search) | 131 | :group 'gnus-search) |
| 136 | 132 | ||
| 133 | (make-obsolete-variable | ||
| 134 | 'nnir-imap-default-search-key | ||
| 135 | "specify imap search keys, or use parsed queries." "28.1") | ||
| 136 | |||
| 137 | ;; Engine-specific configuration options. | 137 | ;; Engine-specific configuration options. |
| 138 | 138 | ||
| 139 | (defcustom gnus-search-swish++-config-file | 139 | (defcustom gnus-search-swish++-config-file |
| @@ -930,11 +930,11 @@ quirks.") | |||
| 930 | (define-obsolete-variable-alias 'nnir-method-default-engines | 930 | (define-obsolete-variable-alias 'nnir-method-default-engines |
| 931 | 'gnus-search-default-engines "28.1") | 931 | 'gnus-search-default-engines "28.1") |
| 932 | 932 | ||
| 933 | (defcustom gnus-search-default-engines '((nnimap gnus-search-imap)) | 933 | (defcustom gnus-search-default-engines '((nnimap . gnus-search-imap)) |
| 934 | "Alist of default search engines keyed by server method." | 934 | "Alist of default search engines keyed by server method." |
| 935 | :version "26.1" | 935 | :version "26.1" |
| 936 | :group 'gnus-search | 936 | :group 'gnus-search |
| 937 | :type `(repeat (list (choice (const nnimap) (const nntp) (const nnspool) | 937 | :type `(repeat (cons (choice (const nnimap) (const nntp) (const nnspool) |
| 938 | (const nneething) (const nndir) (const nnmbox) | 938 | (const nneething) (const nndir) (const nnmbox) |
| 939 | (const nnml) (const nnmh) (const nndraft) | 939 | (const nnml) (const nnmh) (const nndraft) |
| 940 | (const nnfolder) (const nnmaildir)) | 940 | (const nnfolder) (const nnmaildir)) |
| @@ -1168,7 +1168,21 @@ means (usually the \"mark\" keyword)." | |||
| 1168 | (cl-case (car expr) | 1168 | (cl-case (car expr) |
| 1169 | (date (setcar expr 'on)) | 1169 | (date (setcar expr 'on)) |
| 1170 | (tag (setcar expr 'keyword)) | 1170 | (tag (setcar expr 'keyword)) |
| 1171 | (sender (setcar expr 'from))) | 1171 | (sender (setcar expr 'from)) |
| 1172 | (attachment (setcar expr 'body))) | ||
| 1173 | ;; Allow sizes specified as KB or MB. | ||
| 1174 | (let ((case-fold-search t) | ||
| 1175 | unit) | ||
| 1176 | (when (and (memq (car expr) '(larger smaller)) | ||
| 1177 | (string-match "\\(kb?\\|mb?\\)\\'" (cdr expr))) | ||
| 1178 | (setq unit (match-string 1 (cdr expr))) | ||
| 1179 | (setcdr expr | ||
| 1180 | (number-to-string | ||
| 1181 | (* (string-to-number | ||
| 1182 | (string-replace unit "" (cdr expr))) | ||
| 1183 | (if (string-prefix-p "k" unit) | ||
| 1184 | 1024 | ||
| 1185 | 1048576)))))) | ||
| 1172 | (cond | 1186 | (cond |
| 1173 | ((consp (car expr)) | 1187 | ((consp (car expr)) |
| 1174 | (format "(%s)" (gnus-search-transform engine expr))) | 1188 | (format "(%s)" (gnus-search-transform engine expr))) |
| @@ -1176,14 +1190,14 @@ means (usually the \"mark\" keyword)." | |||
| 1176 | (gnus-search-transform | 1190 | (gnus-search-transform |
| 1177 | engine (gnus-search-parse-query | 1191 | engine (gnus-search-parse-query |
| 1178 | (format | 1192 | (format |
| 1179 | "to:%s or cc:%s or bcc:%s" | 1193 | "to:%s or cc:%s or bcc:%s" |
| 1180 | (cdr expr) (cdr expr) (cdr expr))))) | 1194 | (cdr expr) (cdr expr) (cdr expr))))) |
| 1181 | ((eq (car expr) 'address) | 1195 | ((eq (car expr) 'address) |
| 1182 | (gnus-search-transform | 1196 | (gnus-search-transform |
| 1183 | engine (gnus-search-parse-query | 1197 | engine (gnus-search-parse-query |
| 1184 | (format | 1198 | (format |
| 1185 | "from:%s or to:%s or cc:%s or bcc:%s" | 1199 | "from:%s or to:%s or cc:%s or bcc:%s" |
| 1186 | (cdr expr) (cdr expr) (cdr expr) (cdr expr))))) | 1200 | (cdr expr) (cdr expr) (cdr expr) (cdr expr))))) |
| 1187 | ((memq (car expr) '(before since on sentbefore senton sentsince)) | 1201 | ((memq (car expr) '(before since on sentbefore senton sentsince)) |
| 1188 | ;; Ignore dates given as strings. | 1202 | ;; Ignore dates given as strings. |
| 1189 | (when (listp (cdr expr)) | 1203 | (when (listp (cdr expr)) |
| @@ -1949,28 +1963,32 @@ remaining string, then adds all that to the top-level spec." | |||
| 1949 | ;; server. | 1963 | ;; server. |
| 1950 | (defun gnus-search-server-to-engine (srv) | 1964 | (defun gnus-search-server-to-engine (srv) |
| 1951 | (let* ((method (gnus-server-to-method srv)) | 1965 | (let* ((method (gnus-server-to-method srv)) |
| 1966 | (engine-config (assoc 'gnus-search-engine (cddr method))) | ||
| 1952 | (server | 1967 | (server |
| 1953 | (or (assoc 'gnus-search-engine (cddr method)) | 1968 | (or (nth 1 engine-config) |
| 1954 | (assoc (car method) gnus-search-default-engines) | 1969 | (cdr-safe (assoc (car method) gnus-search-default-engines)) |
| 1955 | (when-let ((old (assoc 'nnir-search-engine | 1970 | (when-let ((old (assoc 'nnir-search-engine |
| 1956 | (cddr method)))) | 1971 | (cddr method)))) |
| 1957 | (nnheader-message | 1972 | (nnheader-message |
| 1958 | 8 "\"nnir-search-engine\" is no longer a valid parameter") | 1973 | 8 "\"nnir-search-engine\" is no longer a valid parameter") |
| 1959 | (pcase old | 1974 | (pcase (nth 1 old) |
| 1960 | ('notmuch 'gnus-search-notmuch) | 1975 | ('notmuch 'gnus-search-notmuch) |
| 1961 | ('namazu 'gnus-search-namazu) | 1976 | ('namazu 'gnus-search-namazu) |
| 1962 | ('find-grep 'gnus-search-find-grep))))) | 1977 | ('find-grep 'gnus-search-find-grep))))) |
| 1963 | (inst | 1978 | (inst |
| 1964 | (cond | 1979 | (cond |
| 1965 | ((null server) nil) | 1980 | ((null server) nil) |
| 1966 | ((eieio-object-p (cadr server)) | 1981 | ((eieio-object-p server) |
| 1967 | (cadr server)) | 1982 | server) |
| 1968 | ((class-p (cadr server)) | 1983 | ((class-p server) |
| 1969 | (make-instance (cadr server))) | 1984 | (make-instance server)) |
| 1970 | (t nil)))) | 1985 | (t nil)))) |
| 1971 | (if inst | 1986 | (if inst |
| 1972 | (when (cddr server) | 1987 | (when (cddr engine-config) |
| 1973 | (pcase-dolist (`(,key ,value) (cddr server)) | 1988 | ;; We're not being completely backward-compatible here, |
| 1989 | ;; because we're not checking for nnir-specific config | ||
| 1990 | ;; options in the server definition. | ||
| 1991 | (pcase-dolist (`(,key ,value) (cddr engine-config)) | ||
| 1974 | (condition-case nil | 1992 | (condition-case nil |
| 1975 | (setf (slot-value inst key) value) | 1993 | (setf (slot-value inst key) value) |
| 1976 | ((invalid-slot-name invalid-slot-type) | 1994 | ((invalid-slot-name invalid-slot-type) |