diff options
| author | Stefan Monnier | 2020-03-27 16:38:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-03-27 16:38:52 -0400 |
| commit | 3fdb53b13ac06af91763410925ca71158bcff6da (patch) | |
| tree | 0ae2cbbe61b2eb551985c2f08469191629a5a638 | |
| parent | 6075a7c5ae3fa456cd099946f6e042b57e925263 (diff) | |
| download | emacs-3fdb53b13ac06af91763410925ca71158bcff6da.tar.gz emacs-3fdb53b13ac06af91763410925ca71158bcff6da.zip | |
* lisp/gnus/gnus-registry.el: Use lexical-binding
(gnus-registry-install-shortcuts): Use a closure (with dynamic :documentation)
(gnus-registry-user-format-function-M): Use define-obsolete-function-alias.
(gnus-registry-article-marks-to-names): η-reduce.
| -rw-r--r-- | lisp/gnus/gnus-registry.el | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/lisp/gnus/gnus-registry.el b/lisp/gnus/gnus-registry.el index fd2b44f7424..480ed80ef81 100644 --- a/lisp/gnus/gnus-registry.el +++ b/lisp/gnus/gnus-registry.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; gnus-registry.el --- article registry for Gnus | 1 | ;;; gnus-registry.el --- article registry for Gnus -*- lexical-binding: t; -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2002-2020 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2002-2020 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -62,10 +62,10 @@ | |||
| 62 | 62 | ||
| 63 | ;; show the marks as single characters (see the :char property in | 63 | ;; show the marks as single characters (see the :char property in |
| 64 | ;; `gnus-registry-marks'): | 64 | ;; `gnus-registry-marks'): |
| 65 | ;; (defalias 'gnus-user-format-function-M 'gnus-registry-article-marks-to-chars) | 65 | ;; (defalias 'gnus-user-format-function-M #'gnus-registry-article-marks-to-chars) |
| 66 | 66 | ||
| 67 | ;; show the marks by name (see `gnus-registry-marks'): | 67 | ;; show the marks by name (see `gnus-registry-marks'): |
| 68 | ;; (defalias 'gnus-user-format-function-M 'gnus-registry-article-marks-to-names) | 68 | ;; (defalias 'gnus-user-format-function-M #'gnus-registry-article-marks-to-names) |
| 69 | 69 | ||
| 70 | ;; TODO: | 70 | ;; TODO: |
| 71 | 71 | ||
| @@ -588,7 +588,7 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." | |||
| 588 | subject | 588 | subject |
| 589 | (< gnus-registry-minimum-subject-length (length subject))) | 589 | (< gnus-registry-minimum-subject-length (length subject))) |
| 590 | (let ((groups (apply | 590 | (let ((groups (apply |
| 591 | 'append | 591 | #'append |
| 592 | (mapcar | 592 | (mapcar |
| 593 | (lambda (reference) | 593 | (lambda (reference) |
| 594 | (gnus-registry-get-id-key reference 'group)) | 594 | (gnus-registry-get-id-key reference 'group)) |
| @@ -615,7 +615,7 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." | |||
| 615 | sender | 615 | sender |
| 616 | gnus-registry-unfollowed-addresses))) | 616 | gnus-registry-unfollowed-addresses))) |
| 617 | (let ((groups (apply | 617 | (let ((groups (apply |
| 618 | 'append | 618 | #'append |
| 619 | (mapcar | 619 | (mapcar |
| 620 | (lambda (reference) | 620 | (lambda (reference) |
| 621 | (gnus-registry-get-id-key reference 'group)) | 621 | (gnus-registry-get-id-key reference 'group)) |
| @@ -644,7 +644,7 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." | |||
| 644 | (not (gnus-grep-in-list | 644 | (not (gnus-grep-in-list |
| 645 | recp | 645 | recp |
| 646 | gnus-registry-unfollowed-addresses))) | 646 | gnus-registry-unfollowed-addresses))) |
| 647 | (let ((groups (apply 'append | 647 | (let ((groups (apply #'append |
| 648 | (mapcar | 648 | (mapcar |
| 649 | (lambda (reference) | 649 | (lambda (reference) |
| 650 | (gnus-registry-get-id-key reference 'group)) | 650 | (gnus-registry-get-id-key reference 'group)) |
| @@ -663,7 +663,7 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." | |||
| 663 | ;; filter the found groups and return them | 663 | ;; filter the found groups and return them |
| 664 | ;; the found groups are NOT the full groups | 664 | ;; the found groups are NOT the full groups |
| 665 | (setq found (gnus-registry-post-process-groups | 665 | (setq found (gnus-registry-post-process-groups |
| 666 | "recipients" (mapconcat 'identity recipients ", ") found))) | 666 | "recipients" (mapconcat #'identity recipients ", ") found))) |
| 667 | 667 | ||
| 668 | ;; after the (cond) we extract the actual value safely | 668 | ;; after the (cond) we extract the actual value safely |
| 669 | (car-safe found))) | 669 | (car-safe found))) |
| @@ -791,7 +791,8 @@ Consults `gnus-registry-ignored-groups' and | |||
| 791 | ((stringp g) g) | 791 | ((stringp g) g) |
| 792 | ((and (listp g) (nth 1 g)) | 792 | ((and (listp g) (nth 1 g)) |
| 793 | (nth 0 g)) | 793 | (nth 0 g)) |
| 794 | (t nil))) gnus-registry-ignored-groups))) | 794 | (t nil))) |
| 795 | gnus-registry-ignored-groups))) | ||
| 795 | ;; only use `gnus-parameter-registry-ignore' if | 796 | ;; only use `gnus-parameter-registry-ignore' if |
| 796 | ;; `gnus-registry-ignored-groups' is a list of lists | 797 | ;; `gnus-registry-ignored-groups' is a list of lists |
| 797 | ;; (it can be a list of regexes) | 798 | ;; (it can be a list of regexes) |
| @@ -871,7 +872,7 @@ Addresses without a name will say \"noname\"." | |||
| 871 | 872 | ||
| 872 | (defun gnus-registry-sort-addresses (&rest addresses) | 873 | (defun gnus-registry-sort-addresses (&rest addresses) |
| 873 | "Return a normalized and sorted list of ADDRESSES." | 874 | "Return a normalized and sorted list of ADDRESSES." |
| 874 | (sort (mapcan 'gnus-registry-extract-addresses addresses) 'string-lessp)) | 875 | (sort (mapcan #'gnus-registry-extract-addresses addresses) 'string-lessp)) |
| 875 | 876 | ||
| 876 | (defun gnus-registry-simplify-subject (subject) | 877 | (defun gnus-registry-simplify-subject (subject) |
| 877 | (if (stringp subject) | 878 | (if (stringp subject) |
| @@ -961,16 +962,15 @@ Uses `gnus-registry-marks' to find what shortcuts to install." | |||
| 961 | (intern (format function-format variant-name))) | 962 | (intern (format function-format variant-name))) |
| 962 | (shortcut (format "%c" (if remove (upcase data) data)))) | 963 | (shortcut (format "%c" (if remove (upcase data) data)))) |
| 963 | (defalias function-name | 964 | (defalias function-name |
| 964 | ;; If it weren't for the function's docstring, we could | 965 | (lambda (&rest articles) |
| 965 | ;; use a closure, with lexical-let :-( | 966 | (:documentation |
| 966 | `(lambda (&rest articles) | 967 | (format |
| 967 | ,(format | 968 | "%s the %s mark over process-marked ARTICLES." |
| 968 | "%s the %s mark over process-marked ARTICLES." | 969 | (upcase-initials variant-name) |
| 969 | (upcase-initials variant-name) | 970 | mark)) |
| 970 | mark) | 971 | (interactive |
| 971 | (interactive | 972 | (gnus-summary-work-articles current-prefix-arg)) |
| 972 | (gnus-summary-work-articles current-prefix-arg)) | 973 | (gnus-registry--set/remove-mark mark remove articles))) |
| 973 | (gnus-registry--set/remove-mark ',mark ',remove articles))) | ||
| 974 | (push function-name keys-plist) | 974 | (push function-name keys-plist) |
| 975 | (push shortcut keys-plist) | 975 | (push shortcut keys-plist) |
| 976 | (push (vector (format "%s %s" | 976 | (push (vector (format "%s %s" |
| @@ -990,14 +990,11 @@ Uses `gnus-registry-marks' to find what shortcuts to install." | |||
| 990 | nil | 990 | nil |
| 991 | (cons "Registry Marks" gnus-registry-misc-menus)))))) | 991 | (cons "Registry Marks" gnus-registry-misc-menus)))))) |
| 992 | 992 | ||
| 993 | (make-obsolete 'gnus-registry-user-format-function-M | 993 | (define-obsolete-function-alias 'gnus-registry-user-format-function-M |
| 994 | 'gnus-registry-article-marks-to-chars "24.1") ? | 994 | #'gnus-registry-article-marks-to-chars "24.1") |
| 995 | |||
| 996 | (defalias 'gnus-registry-user-format-function-M | ||
| 997 | 'gnus-registry-article-marks-to-chars) | ||
| 998 | 995 | ||
| 999 | ;; use like this: | 996 | ;; use like this: |
| 1000 | ;; (defalias 'gnus-user-format-function-M 'gnus-registry-article-marks-to-chars) | 997 | ;; (defalias 'gnus-user-format-function-M #'gnus-registry-article-marks-to-chars) |
| 1001 | (defun gnus-registry-article-marks-to-chars (headers) | 998 | (defun gnus-registry-article-marks-to-chars (headers) |
| 1002 | "Show the marks for an article by the :char property." | 999 | "Show the marks for an article by the :char property." |
| 1003 | (if gnus-registry-enabled | 1000 | (if gnus-registry-enabled |
| @@ -1013,20 +1010,20 @@ Uses `gnus-registry-marks' to find what shortcuts to install." | |||
| 1013 | "")) | 1010 | "")) |
| 1014 | 1011 | ||
| 1015 | ;; use like this: | 1012 | ;; use like this: |
| 1016 | ;; (defalias 'gnus-user-format-function-M 'gnus-registry-article-marks-to-names) | 1013 | ;; (defalias 'gnus-user-format-function-M #'gnus-registry-article-marks-to-names) |
| 1017 | (defun gnus-registry-article-marks-to-names (headers) | 1014 | (defun gnus-registry-article-marks-to-names (headers) |
| 1018 | "Show the marks for an article by name." | 1015 | "Show the marks for an article by name." |
| 1019 | (if gnus-registry-enabled | 1016 | (if gnus-registry-enabled |
| 1020 | (let* ((id (mail-header-message-id headers)) | 1017 | (let* ((id (mail-header-message-id headers)) |
| 1021 | (marks (when id (gnus-registry-get-id-key id 'mark)))) | 1018 | (marks (when id (gnus-registry-get-id-key id 'mark)))) |
| 1022 | (mapconcat (lambda (mark) (symbol-name mark)) marks ",")) | 1019 | (mapconcat #'symbol-name marks ",")) |
| 1023 | "")) | 1020 | "")) |
| 1024 | 1021 | ||
| 1025 | (defun gnus-registry-read-mark () | 1022 | (defun gnus-registry-read-mark () |
| 1026 | "Read a mark name from the user with completion." | 1023 | "Read a mark name from the user with completion." |
| 1027 | (let ((mark (gnus-completing-read | 1024 | (let ((mark (gnus-completing-read |
| 1028 | "Label" | 1025 | "Label" |
| 1029 | (mapcar 'symbol-name (mapcar 'car gnus-registry-marks)) | 1026 | (mapcar #'symbol-name (mapcar #'car gnus-registry-marks)) |
| 1030 | nil nil nil | 1027 | nil nil nil |
| 1031 | (symbol-name gnus-registry-default-mark)))) | 1028 | (symbol-name gnus-registry-default-mark)))) |
| 1032 | (when (stringp mark) | 1029 | (when (stringp mark) |
| @@ -1050,7 +1047,7 @@ Uses `gnus-registry-marks' to find what shortcuts to install." | |||
| 1050 | show-message) | 1047 | show-message) |
| 1051 | "Apply or remove MARK across a list of ARTICLES." | 1048 | "Apply or remove MARK across a list of ARTICLES." |
| 1052 | (let ((article-id-list | 1049 | (let ((article-id-list |
| 1053 | (mapcar 'gnus-registry-fetch-message-id-fast articles))) | 1050 | (mapcar #'gnus-registry-fetch-message-id-fast articles))) |
| 1054 | (dolist (id article-id-list) | 1051 | (dolist (id article-id-list) |
| 1055 | (let* ((marks (delq mark (gnus-registry-get-id-key id 'mark))) | 1052 | (let* ((marks (delq mark (gnus-registry-get-id-key id 'mark))) |
| 1056 | (marks (if remove marks (cons mark marks)))) | 1053 | (marks (if remove marks (cons mark marks)))) |
| @@ -1173,34 +1170,34 @@ only the last one's marks are returned." | |||
| 1173 | (gnus-registry-install-shortcuts) | 1170 | (gnus-registry-install-shortcuts) |
| 1174 | (if (gnus-alive-p) | 1171 | (if (gnus-alive-p) |
| 1175 | (gnus-registry-load) | 1172 | (gnus-registry-load) |
| 1176 | (add-hook 'gnus-read-newsrc-el-hook 'gnus-registry-load))) | 1173 | (add-hook 'gnus-read-newsrc-el-hook #'gnus-registry-load))) |
| 1177 | 1174 | ||
| 1178 | (defun gnus-registry-install-hooks () | 1175 | (defun gnus-registry-install-hooks () |
| 1179 | "Install the registry hooks." | 1176 | "Install the registry hooks." |
| 1180 | (setq gnus-registry-enabled t) | 1177 | (setq gnus-registry-enabled t) |
| 1181 | (add-hook 'gnus-summary-article-move-hook 'gnus-registry-action) | 1178 | (add-hook 'gnus-summary-article-move-hook #'gnus-registry-action) |
| 1182 | (add-hook 'gnus-summary-article-delete-hook 'gnus-registry-action) | 1179 | (add-hook 'gnus-summary-article-delete-hook #'gnus-registry-action) |
| 1183 | (add-hook 'gnus-summary-article-expire-hook 'gnus-registry-action) | 1180 | (add-hook 'gnus-summary-article-expire-hook #'gnus-registry-action) |
| 1184 | (add-hook 'nnmail-spool-hook 'gnus-registry-spool-action) | 1181 | (add-hook 'nnmail-spool-hook #'gnus-registry-spool-action) |
| 1185 | 1182 | ||
| 1186 | (add-hook 'gnus-save-newsrc-hook 'gnus-registry-save) | 1183 | (add-hook 'gnus-save-newsrc-hook #'gnus-registry-save) |
| 1187 | 1184 | ||
| 1188 | (add-hook 'gnus-summary-prepare-hook 'gnus-registry-register-message-ids)) | 1185 | (add-hook 'gnus-summary-prepare-hook #'gnus-registry-register-message-ids)) |
| 1189 | 1186 | ||
| 1190 | (defun gnus-registry-unload-hook () | 1187 | (defun gnus-registry-unload-hook () |
| 1191 | "Uninstall the registry hooks." | 1188 | "Uninstall the registry hooks." |
| 1192 | (remove-hook 'gnus-summary-article-move-hook 'gnus-registry-action) | 1189 | (remove-hook 'gnus-summary-article-move-hook #'gnus-registry-action) |
| 1193 | (remove-hook 'gnus-summary-article-delete-hook 'gnus-registry-action) | 1190 | (remove-hook 'gnus-summary-article-delete-hook #'gnus-registry-action) |
| 1194 | (remove-hook 'gnus-summary-article-expire-hook 'gnus-registry-action) | 1191 | (remove-hook 'gnus-summary-article-expire-hook #'gnus-registry-action) |
| 1195 | (remove-hook 'nnmail-spool-hook 'gnus-registry-spool-action) | 1192 | (remove-hook 'nnmail-spool-hook #'gnus-registry-spool-action) |
| 1196 | 1193 | ||
| 1197 | (remove-hook 'gnus-save-newsrc-hook 'gnus-registry-save) | 1194 | (remove-hook 'gnus-save-newsrc-hook #'gnus-registry-save) |
| 1198 | (remove-hook 'gnus-read-newsrc-el-hook 'gnus-registry-load) | 1195 | (remove-hook 'gnus-read-newsrc-el-hook #'gnus-registry-load) |
| 1199 | 1196 | ||
| 1200 | (remove-hook 'gnus-summary-prepare-hook 'gnus-registry-register-message-ids) | 1197 | (remove-hook 'gnus-summary-prepare-hook #'gnus-registry-register-message-ids) |
| 1201 | (setq gnus-registry-enabled nil)) | 1198 | (setq gnus-registry-enabled nil)) |
| 1202 | 1199 | ||
| 1203 | (add-hook 'gnus-registry-unload-hook 'gnus-registry-unload-hook) | 1200 | (add-hook 'gnus-registry-unload-hook #'gnus-registry-unload-hook) |
| 1204 | 1201 | ||
| 1205 | (defun gnus-registry-install-p () | 1202 | (defun gnus-registry-install-p () |
| 1206 | "Return non-nil if the registry is enabled (and maybe enable it first). | 1203 | "Return non-nil if the registry is enabled (and maybe enable it first). |
| @@ -1234,7 +1231,7 @@ data stored in the registry." | |||
| 1234 | (seen-groups (list (gnus-group-group-name)))) | 1231 | (seen-groups (list (gnus-group-group-name)))) |
| 1235 | 1232 | ||
| 1236 | (catch 'found | 1233 | (catch 'found |
| 1237 | (dolist (group (mapcar 'gnus-simplify-group-name groups)) | 1234 | (dolist (group (mapcar #'gnus-simplify-group-name groups)) |
| 1238 | 1235 | ||
| 1239 | ;; skip over any groups we really don't want to warp to. | 1236 | ;; skip over any groups we really don't want to warp to. |
| 1240 | (unless (or (member group seen-groups) | 1237 | (unless (or (member group seen-groups) |
| @@ -1270,7 +1267,7 @@ EXTRA is a list of symbols. Valid symbols are those contained in | |||
| 1270 | the docs of `gnus-registry-track-extra'. This command is useful | 1267 | the docs of `gnus-registry-track-extra'. This command is useful |
| 1271 | when you stop tracking some extra data and now want to purge it | 1268 | when you stop tracking some extra data and now want to purge it |
| 1272 | from your existing entries." | 1269 | from your existing entries." |
| 1273 | (interactive (list (mapcar 'intern | 1270 | (interactive (list (mapcar #'intern |
| 1274 | (completing-read-multiple | 1271 | (completing-read-multiple |
| 1275 | "Extra data: " | 1272 | "Extra data: " |
| 1276 | '("subject" "sender" "recipient"))))) | 1273 | '("subject" "sender" "recipient"))))) |