[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ff6f31e 37/40: Replace yas--with-temp-redefs with cl-letf
From: |
Noam Postavsky |
Subject: |
[elpa] master ff6f31e 37/40: Replace yas--with-temp-redefs with cl-letf |
Date: |
Wed, 26 Oct 2016 23:06:34 +0000 (UTC) |
branch: master
commit ff6f31ee2cd22deb6593564bb9076d505d5841ab
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Replace yas--with-temp-redefs with cl-letf
* yasnippet-tests.el (yas--call-with-temporary-redefinitions):
yas--with-temporary-redefinitions): Remove.
* yasnippet-tests.el (yas-with-overriden-buffer-list):
(basic-jit-loading-with-compiled-snippets):
(visiting-compiled-snippets): Use cl-letf.
---
yasnippet-tests.el | 63 ++++++++++------------------------------------------
1 file changed, 12 insertions(+), 51 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 1dc2374..6b7a91a 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -526,48 +526,16 @@ TODO: correct this bug!"
;;; Loading
;;;
-(defun yas--call-with-temporary-redefinitions (function
- &rest
function-names-and-overriding-functions)
- (let* ((overrides (cl-remove-if-not (lambda (fdef)
- (fboundp (car fdef)))
- function-names-and-overriding-functions))
- (definition-names (mapcar #'car overrides))
- (overriding-functions (mapcar #'cl-second overrides))
- (saved-functions (mapcar #'symbol-function definition-names)))
- ;; saving all definitions before overriding anything ensures FDEFINITION
- ;; errors don't cause accidental permanent redefinitions.
- ;;
- (cl-labels ((set-fdefinitions (names functions)
- (cl-loop for name in names
- for fn in functions
- do (fset name fn))))
- (set-fdefinitions definition-names overriding-functions)
- (unwind-protect (funcall function)
- (set-fdefinitions definition-names saved-functions)))))
-
-(defmacro yas--with-temporary-redefinitions (fdefinitions &rest body)
- ;; "Temporarily (but globally) redefine each function in FDEFINITIONS.
- ;; E.g.: (yas--with-temporary-redefinitions ((foo (x) ...)
- ;; (bar (x) ...))
- ;; ;; code that eventually calls foo, bar of (setf foo)
- ;; ...)"
- ;; FIXME: This is hideous! Better use defadvice (or at least letf).
- `(yas--call-with-temporary-redefinitions
- (lambda () ,@body)
- ,@(mapcar #'(lambda (thingy)
- `(list ',(car thingy)
- (lambda ,@(cdr thingy))))
- fdefinitions)))
(defmacro yas-with-overriden-buffer-list (&rest body)
(let ((saved-sym (make-symbol "yas--buffer-list")))
`(let ((,saved-sym (symbol-function 'buffer-list)))
- (yas--with-temporary-redefinitions
- ((buffer-list ()
- (cl-remove-if (lambda (buf)
- (with-current-buffer buf
- (eq major-mode
'lisp-interaction-mode)))
- (funcall ,saved-sym))))
+ (cl-letf (((symbol-function 'buffer-list)
+ (lambda ()
+ (cl-remove-if (lambda (buf)
+ (with-current-buffer buf
+ (eq major-mode 'lisp-interaction-mode)))
+ (funcall ,saved-sym)))))
,@body))))
@@ -610,9 +578,9 @@ TODO: correct this bug!"
(yas-with-some-interesting-snippet-dirs
(yas-reload-all)
(yas-recompile-all)
- (yas--with-temporary-redefinitions ((yas--load-directory-2
- (&rest _dummies)
- (ert-fail "yas--load-directory-2
shouldn't be called when snippets have been compiled")))
+ (cl-letf (((symbol-function 'yas--load-directory-2)
+ (lambda (&rest _dummies)
+ (ert-fail "yas--load-directory-2 shouldn't be called when
snippets have been compiled"))))
(yas-reload-all)
(yas--basic-jit-loading-1))))
@@ -672,9 +640,9 @@ TODO: correct this bug!"
(yas-with-some-interesting-snippet-dirs
(yas-recompile-all)
(yas-reload-all 'no-jit) ; must be loaded for `yas-lookup-snippet' to work.
- (yas--with-temporary-redefinitions ((find-file-noselect
- (filename &rest _)
- (throw 'yas-snippet-file filename)))
+ (cl-letf (((symbol-function 'find-file-noselect)
+ (lambda (filename &rest _)
+ (throw 'yas-snippet-file filename))))
(should (string-suffix-p
"cc-mode/def"
(catch 'yas-snippet-file
@@ -1088,13 +1056,6 @@ attention to case differences."
(put 'yas-with-overriden-buffer-list 'edebug-form-spec t)
(put 'yas-with-some-interesting-snippet-dirs 'edebug-form-spec t)
-
-(put 'yas--with-temporary-redefinitions 'lisp-indent-function 1)
-(put 'yas--with-temporary-redefinitions 'edebug-form-spec '((&rest (defun*))
cl-declarations body))
-
-
-
-
(provide 'yasnippet-tests)
;; Local Variables:
;; indent-tabs-mode: nil
- [elpa] master 85a43ad 35/40: Explain about backquote expressions in doc, (continued)
- [elpa] master 85a43ad 35/40: Explain about backquote expressions in doc, Noam Postavsky, 2016/10/26
- [elpa] master 3129040 24/40: Load snippet after saving, Noam Postavsky, 2016/10/26
- [elpa] master 1532e66 33/40: Fix saving of new snippets, Noam Postavsky, 2016/10/26
- [elpa] master 0ee86a2 23/40: Simplify `yas-new-snippet' load&save logic, Noam Postavsky, 2016/10/26
- [elpa] master 00be21c 36/40: Change cl dep to cl-lib for tests too, Noam Postavsky, 2016/10/26
- [elpa] master 9c9952c 12/40: Add test for indentation of single line mirrors, Noam Postavsky, 2016/10/26
- [elpa] master 4296a86 15/40: yasnippet.el (yas--quote-string): Remove., Noam Postavsky, 2016/10/26
- [elpa] master d4da806 17/40: Fix removal of snippets by uuid, Noam Postavsky, 2016/10/26
- [elpa] master 42b0c26 18/40: Don't warn about modifications to other buffers, Noam Postavsky, 2016/10/26
- [elpa] master eaaec30 38/40: Replace all occurances of `capitaomorte', Noam Postavsky, 2016/10/26
- [elpa] master ff6f31e 37/40: Replace yas--with-temp-redefs with cl-letf,
Noam Postavsky <=
- [elpa] master 244cdfa 26/40: Merge: Simplify `yas-new-snippet' load&save logic, Noam Postavsky, 2016/10/26
- [elpa] master 9500b00 21/40: Fix field navigation in the backwards direction, Noam Postavsky, 2016/10/26
- [elpa] master 309fe15 31/40: * Rakefile: Handle unset `warnings' parameter, Noam Postavsky, 2016/10/26
- [elpa] master 9cf9208 32/40: Fix test-rebindings, Noam Postavsky, 2016/10/26
- [elpa] master 7e0a0de 28/40: Use new name of python-in-string/comment in docs, Noam Postavsky, 2016/10/26
- [elpa] master e6b8651 39/40: * NEWS: Update for 0.11.0., Noam Postavsky, 2016/10/26
- [elpa] master 5264379 29/40: Cleanup redundant cl dependency, :group & :require, Noam Postavsky, 2016/10/26
- [elpa] master 4b12f7d 30/40: Don't warn about cl-functions with old cl-lib, Noam Postavsky, 2016/10/26
- [elpa] master a5e88b2 34/40: Add test for snippet saving, Noam Postavsky, 2016/10/26
- [elpa] master 299efcb 40/40: packages/yasnippet: Merge external (v0.11.0), Noam Postavsky, 2016/10/26