Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

w3m-util.el (w3m-flet): Rewrite it using cl-letf

  • Loading branch information...
commit d22fd47a1fcc9accf7b01936745a57b3e489a935 1 parent 9580c6d
yamaoka authored
Showing with 14 additions and 11 deletions.
  1. +4 −0 ChangeLog
  2. +10 −11 w3m-util.el
View
4 ChangeLog
@@ -1,3 +1,7 @@
+2012-12-05 Katsumi Yamaoka <yamaoka@jpl.org>
+
+ * w3m-util.el (w3m-flet): Rewrite it using cl-letf.
+
2012-12-04 Katsumi Yamaoka <yamaoka@jpl.org>
* w3m-util.el (w3m-labels): Revert; use cl-labels if available.
View
21 w3m-util.el
@@ -1520,19 +1520,18 @@ get to be the alias to `visited-file-modtime'."
;; `flet' and `labels' got obsolete since Emacs 24.3.
(defmacro w3m-flet (bindings &rest body)
"Make temporary overriding function definitions.
+This is an analogue of a dynamically scoped `let' that operates on
+the function cell of FUNCs rather than their value cell.
\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
- `(let (fn origs)
- (dolist (bind ',bindings)
- (setq fn (car bind))
- (push (cons fn (and (fboundp fn) (symbol-function fn))) origs)
- (fset fn (cons 'lambda (cdr bind))))
- (unwind-protect
- (progn ,@body)
- (dolist (orig origs)
- (if (cdr orig)
- (fset (car orig) (cdr orig))
- (fmakunbound (car orig)))))))
+ (require 'cl)
+ (if (fboundp 'cl-letf)
+ `(cl-letf ,(mapcar (lambda (binding)
+ `((symbol-function ',(car binding))
+ (lambda ,@(cdr binding))))
+ bindings)
+ ,@body)
+ `(flet ,bindings ,@body)))
(put 'w3m-flet 'lisp-indent-function 1)
(defmacro w3m-labels (bindings &rest body)
Please sign in to comment.
Something went wrong with that request. Please try again.