diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-01-30 16:45:25 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2021-01-30 17:30:08 -0500 |
commit | 9be4f41b4254c029fc328b10ecef4e71cd2ca024 (patch) | |
tree | fe7acbcc2bd8041d559775b9c02d15fa72cae7a3 /lisp/gnus/nnoo.el | |
parent | acf4ec23d966b6bc92c61b557148afc88f20f99e (diff) | |
download | emacs-9be4f41b4254c029fc328b10ecef4e71cd2ca024.tar.gz emacs-9be4f41b4254c029fc328b10ecef4e71cd2ca024.tar.bz2 emacs-9be4f41b4254c029fc328b10ecef4e71cd2ca024.zip |
* lisp/gnus: Misc simplifications found during conversion to lexical
* lisp/gnus/nnoo.el (noo-import-1, nnoo-define-skeleton-1): Use `dolist`.
(noo-map-functions, nnoo-define-basics): Directly emit the code rather than
going through an intermediate function; this also avoids the use of `eval`.
(noo-map-functions-1, nnoo-define-basics-1): Delete functions,
folded into their corresponding macro.
* lisp/gnus/gmm-utils.el (gmm-tool-bar-from-list): Demote `eval` to
`symbol-value`.
* lisp/gnus/gnus-art.el (gnus-button-handle-describe-key): Avoid `eval`
since `kbd` is a function nowadays.
(gnus-treat-part-number): Rename from `part-number`.
(gnus-treat-total-parts): Rename from `total-parts`.
(gnus-treat-article, gnus-treat-predicate): Adjust accordingly.
* lisp/gnus/gnus-cache.el (gnus-agent-load-alist): Use `declare-function`.
* lisp/gnus/gnus-group.el (gnus-cache-active-hashtb): Use `defvar`.
(gnus-group-iterate): Make it a normal function since lexical scoping
avoids the risk of name capture anyway.
(gnus-group-delete-articles): Actually use the `oldp` arg.
* lisp/gnus/gnus-html.el (gnus-html-wash-images): Fix debug message so
it's emitted after the `url` var it prints is actually initialized.
And avoid `setq` while we're at it.
* lisp/gnus/gnus-msg.el (gnus-group-mail, gnus-group-news)
(gnus-summary-mail-other-window, gnus-summary-news-other-window):
Merge `let`s using `let*`.
* lisp/gnus/gnus-spec.el (gnus-update-format-specifications):
Tighten the scope of `buffer`, and tighten a regexp.
(gnus-parse-simple-format): Reduce code duplication.
* lisp/gnus/gnus-start.el (gnus-child-mode): Don't `defvar` it since we
never use that variable and accordingly don't define it as a minor mode.
* lisp/gnus/gnus-util.el (gnus-byte-compile): Simplify so it obeys
`gnus-use-byte-compile` not just on the first call.
(iswitchb-minibuffer-setup): Declare.
* lisp/gnus/mail-source.el (mail-source-bind-1)
(mail-source-bind-common-1): Use `mapcar`.
(mail-source-set-common-1): Use `dolist`.
(display-time-event-handler): Declare.
* lisp/gnus/mml-smime.el (mml-smime-epg-verify): Reduce code duplication.
* lisp/gnus/mml.el (mml-parse-1): Reduce code duplication.
* lisp/gnus/mml2015.el (mml2015-epg-verify): Reduce code duplication.
* lisp/gnus/nnmail.el (nnmail-get-split-group): Tighten regexp.
(nnmail-split-it): Reduce code duplication.
* lisp/gnus/nnweb.el (nnweb-request-article): Avoid `setq`.
* lisp/gnus/spam.el (BBDB): Use the `noerror` arg of `require`, and
define all the functions for BBDB regardless if the require succeeded.
(spam-exists-in-BBDB-p): Don't inline, not worth it.
Diffstat (limited to 'lisp/gnus/nnoo.el')
-rw-r--r-- | lisp/gnus/nnoo.el | 103 |
1 files changed, 52 insertions, 51 deletions
diff --git a/lisp/gnus/nnoo.el b/lisp/gnus/nnoo.el index cd0a5e6de99..39469d140d9 100644 --- a/lisp/gnus/nnoo.el +++ b/lisp/gnus/nnoo.el @@ -85,20 +85,14 @@ (defun nnoo-import-1 (backend imports) (let ((call-function - (if (symbolp (car imports)) (pop imports) 'nnoo-parent-function)) - imp functions function) - (while (setq imp (pop imports)) - (setq functions - (or (cdr imp) - (nnoo-functions (car imp)))) - (while functions - (unless (fboundp - (setq function - (nnoo-symbol backend - (nnoo-rest-symbol (car functions))))) - (eval `(deffoo ,function (&rest args) - (,call-function ',backend ',(car functions) args)))) - (pop functions))))) + (if (symbolp (car imports)) (pop imports) #'nnoo-parent-function))) + (dolist (imp imports) + (dolist (fun (or (cdr imp) (nnoo-functions (car imp)))) + (let ((function (nnoo-symbol backend (nnoo-rest-symbol fun)))) + (unless (fboundp function) + ;; FIXME: Use `defalias' and closures to avoid `eval'. + (eval `(deffoo ,function (&rest args) + (,call-function ',backend ',fun args))))))))) (defun nnoo-parent-function (backend function args) (let ((pbackend (nnoo-backend function)) @@ -131,22 +125,21 @@ (defmacro nnoo-map-functions (backend &rest maps) (declare (indent 1)) - `(nnoo-map-functions-1 ',backend ',maps)) - -(defun nnoo-map-functions-1 (backend maps) - (let (m margs i) - (while (setq m (pop maps)) - (setq i 0 - margs nil) - (while (< i (length (cdr m))) - (if (numberp (nth i (cdr m))) - (push `(nth ,i args) margs) - (push (nth i (cdr m)) margs)) - (cl-incf i)) - (eval `(deffoo ,(nnoo-symbol backend (nnoo-rest-symbol (car m))) + `(progn + ,@(mapcar + (lambda (m) + (let ((margs nil)) + (dotimes (i (length (cdr m))) + (push (if (numberp (nth i (cdr m))) + `(nth ,i args) + (nth i (cdr m))) + margs)) + `(deffoo ,(nnoo-symbol backend (nnoo-rest-symbol (car m))) (&rest args) + (ignore args) ;; Not always used! (nnoo-parent-function ',backend ',(car m) - ,(cons 'list (nreverse margs)))))))) + ,(cons 'list (nreverse margs)))))) + maps))) (defun nnoo-backend (symbol) (string-match "^[^-]+-" (symbol-name symbol)) @@ -273,19 +266,27 @@ (defmacro nnoo-define-basics (backend) "Define `close-server', `server-opened' and `status-message'." - `(eval-and-compile - (nnoo-define-basics-1 ',backend))) - -(defun nnoo-define-basics-1 (backend) - (dolist (function '(server-opened status-message)) - (eval `(deffoo ,(nnoo-symbol backend function) (&optional server) - (,(nnoo-symbol 'nnoo function) ',backend server)))) - (dolist (function '(close-server)) - (eval `(deffoo ,(nnoo-symbol backend function) (&optional server defs) - (,(nnoo-symbol 'nnoo function) ',backend server)))) - (eval `(deffoo ,(nnoo-symbol backend 'open-server) - (server &optional defs) - (nnoo-change-server ',backend server defs)))) + (let ((form + ;; We wrap the definitions in `when t' here so that a subsequent + ;; "real" definition of one those doesn't trigger a "defined multiple + ;; times" warning. + `(when t + ,@(mapcar (lambda (fun) + `(deffoo ,(nnoo-symbol backend fun) (&optional server) + (,(nnoo-symbol 'nnoo fun) ',backend server))) + '(server-opened status-message)) + (deffoo ,(nnoo-symbol backend 'close-server) (&optional server _defs) + (,(nnoo-symbol 'nnoo 'close-server) ',backend server)) + (deffoo ,(nnoo-symbol backend 'open-server) (server &optional defs) + (nnoo-change-server ',backend server defs))))) + ;; Wrapping with `when' has the downside that the compiler now doesn't + ;; "know" that these functions are defined, so to avoid "not known to be + ;; defined" warnings we eagerly define them during the compilation. + ;; This is fairly nasty since it will override previous "real" definitions + ;; (e.g. when compiling this in an Emacs instance that's running Gnus), but + ;; that's also what the previous code did, so it sucks but is not worse. + (eval form t) + form)) (defmacro nnoo-define-skeleton (backend) "Define all required backend functions for BACKEND. @@ -294,17 +295,17 @@ All functions will return nil and report an error." (nnoo-define-skeleton-1 ',backend))) (defun nnoo-define-skeleton-1 (backend) - (let ((functions '(retrieve-headers - request-close request-article - request-group close-group - request-list request-post request-list-newsgroups)) - function fun) - (while (setq function (pop functions)) - (when (not (fboundp (setq fun (nnoo-symbol backend function)))) + (dolist (op '(retrieve-headers + request-close request-article + request-group close-group + request-list request-post request-list-newsgroups)) + (let ((fun (nnoo-symbol backend op))) + (unless (fboundp fun) + ;; FIXME: Use `defalias' and closures to avoid `eval'. (eval `(deffoo ,fun - (&rest args) - (nnheader-report ',backend ,(format "%s-%s not implemented" - backend function)))))))) + (&rest _args) + (nnheader-report ',backend ,(format "%s-%s not implemented" + backend op)))))))) (defun nnoo-set (server &rest args) (let ((parents (nnoo-parents (car server))) |