branch: elpa/auto-dim-other-buffers commit bea02696f00ec7b68922e675df6122d82a474453 Author: Michal Nazarewicz <min...@mina86.com> Commit: Michal Nazarewicz <min...@mina86.com>
Use save-current-buffer and with-current-buffer --- auto-dim-other-buffers.el | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/auto-dim-other-buffers.el b/auto-dim-other-buffers.el index 0a60110071..29cc140ca7 100644 --- a/auto-dim-other-buffers.el +++ b/auto-dim-other-buffers.el @@ -2,7 +2,7 @@ ;; Author: Steven Degutis ;; URL: https://github.com/sdegutis/auto-dim-other-buffers.el -;; Version: 1.3 +;; Version: 1.4 (defface auto-dim-other-buffers-face '((t :background "black")) "Face (presumably dimmed somehow) for non-current buffers." @@ -12,25 +12,19 @@ (setq adob/last-buffer (current-buffer))) (defun adob/post-command-hook () - (let ((original (current-buffer))) + ;; if we haven't switched buffers, do nothing + (unless (eq (current-buffer) adob/last-buffer) - ;; if we haven't switched buffers, do nothing - (unless (eq original adob/last-buffer) + ;; first, try to dim the last buffer. if it's nil, then the + ;; feature was just turned on and all buffers are already + ;; dimmed. if it's just killed, don't try to set its face. + (and (buffer-live-p adob/last-buffer) + (not (minibufferp adob/last-buffer)) + (with-current-buffer adob/last-buffer + (buffer-face-set 'auto-dim-other-buffers-face))) - ;; first, try to dim the last buffer. if it's nil, then the - ;; feature was just turned on and all buffers are already - ;; dimmed. if it's just killed, don't try to set its face. - (when (and adob/last-buffer - (buffer-live-p adob/last-buffer) - ;; (not (minibufferp adob/last-buffer)) ;; this doesn't do what i want - ) - - (set-buffer adob/last-buffer) - (buffer-face-set 'auto-dim-other-buffers-face)) - - ;; now, restore the current buffer, and undim it. - (set-buffer original) - (buffer-face-set nil)))) + ;; now, restore the current buffer, and undim it. + (buffer-face-set nil))) ;; if a new window pops up, like a help window or something, we ;; should dim or undim it, depending on if its selected. @@ -39,11 +33,10 @@ 'auto-dim-other-buffers-face))) (defun adob/set-face-on-all-buffers (face) - (let ((original (current-buffer))) + (save-current-buffer (dolist (buffer (buffer-list)) (set-buffer buffer) - (buffer-face-set face)) - (set-buffer original))) + (buffer-face-set face)))) (defun adob/undim-all-windows () (adob/set-face-on-all-buffers nil))