From 612d73167688a9a9742478373933c4af5e3f8720 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Thu, 8 Apr 2021 22:48:02 +0200 Subject: Self-TCO in `condition-case` error handlers * lisp/emacs-lisp/cl-macs.el (cl--self-tco): Recognise `condition-case` handlers as being in the tail position. * test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs--labels): Extend test. --- lisp/emacs-lisp/cl-macs.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lisp/emacs-lisp/cl-macs.el') diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 27ed07b6673..68211ec4106 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -2141,6 +2141,13 @@ Like `cl-flet' but the definitions can refer to previous ones. ;; tail-called any more. (not (memq var shadowings))))) `(,(car exp) ,bindings . ,(funcall opt-exps exps))) + ((and `(condition-case ,err-var ,bodyform . ,handlers) + (guard (not (eq err-var var)))) + `(condition-case ,err-var + (progn (setq ,retvar ,bodyform) nil) + . ,(mapcar (lambda (h) + (cons (car h) (funcall opt-exps (cdr h)))) + handlers))) ('nil nil) ;No need to set `retvar' to return nil. (_ `(progn (setq ,retvar ,exp) nil)))))) -- cgit v1.2.3