diff options
| author | John Louis Del Rosario <john2x@gmail.com> | 2018-06-03 09:27:08 +0800 |
|---|---|---|
| committer | John Louis Del Rosario <john2x@gmail.com> | 2018-06-03 10:17:53 +0800 |
| commit | d605aedbb97d8bd9c6c4a190f1efad5710ebdaea (patch) | |
| tree | 9c5a8a84cec3b3904bb8d9bda0339b583ad83c4a /perspective.el | |
| parent | 762db0bda08386bb2a614fd8b0af8e30e07e4b17 (diff) | |
Define persp-let-frame-parameters to temporarily set frame parameters
Diffstat (limited to 'perspective.el')
| -rw-r--r-- | perspective.el | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/perspective.el b/perspective.el index bbfca41..991c1c6 100644 --- a/perspective.el +++ b/perspective.el @@ -103,6 +103,18 @@ See also `with-temp-buffer'." (if (buffer-live-p ,old-buffer) (set-buffer ,old-buffer))))))) +(defmacro persp-let-frame-parameters (bindings &rest body) + "Like `let', but for frame parameters. +Temporariliy set frame parameters according to BINDINGS then eval BODY. +After BODY is evaluated, frame parameters are reset to their original values." + (declare (indent 1)) + (let ((current-frame-parameters (mapcar (lambda (binding) (cons (car binding) (frame-parameter nil (car binding)))) bindings))) + `(unwind-protect + (progn ,@(mapcar (lambda (binding) `(set-frame-parameter nil (quote ,(car binding)) ,(cadr binding))) bindings) + ,@body) + ;; Revert the frame-parameters + (modify-frame-parameters nil (quote ,current-frame-parameters))))) + (cl-defstruct (perspective (:conc-name persp-) (:constructor make-persp-internal)) @@ -161,7 +173,6 @@ Run with the activated perspective active.") (define-key perspective-map (kbd "<left>") 'persp-prev) (define-key perspective-map persp-mode-prefix-key 'persp-switch-last) - (defun persp--current-persp () "Get the current perspective in the active frame." (frame-parameter nil 'persp-curr)) @@ -720,17 +731,17 @@ See also `persp-add-buffer'." "Preserve the current perspective when entering a recursive edit." (persp-protect (persp-save) - (set-frame-parameter nil 'persp-recursive (persp--current-persp)) - (let ((old-hash (copy-hash-table (persp--perspectives-hash)))) - ad-do-it - ;; We want the buffer lists that were created in the recursive edit, - ;; but not the window configurations - (maphash (lambda (key new-persp) - (let ((persp (gethash key old-hash))) - (when persp - (setf (persp-buffers persp) (persp-buffers new-persp))))) - (persp--perspectives-hash)) - (set-frame-parameter nil 'perspectives-hash old-hash)))) + (persp-let-frame-parameters ((persp-recursive (persp--current-persp))) + (let ((old-hash (copy-hash-table (persp--perspectives-hash)))) + ad-do-it + ;; We want the buffer lists that were created in the recursive edit, + ;; but not the window configurations + (maphash (lambda (key new-persp) + (let ((persp (gethash key old-hash))) + (when persp + (setf (persp-buffers persp) (persp-buffers new-persp))))) + (persp--perspectives-hash)) + (set-frame-parameter nil 'perspectives-hash old-hash))))) (defadvice exit-recursive-edit (before persp-restore-after-recursive-edit) "Restore the old perspective when exiting a recursive edit." |
