branch: elpa/auto-dim-other-buffers commit 02ae62c5aba83cf19b5df980498beb3e32fab48c Author: Michal Nazarewicz <min...@mina86.com> Commit: Michal Nazarewicz <min...@mina86.com>
Remove pre command hook The only purpose of `adob--pre-command-hook' was to record the `current-buffer' before the command was executed. This allowed `adob--post-command-hook' to check whether the buffer changed. A much simpler approach is to record buffer whenever it is undimmed. This gets rid of the pre command hook and the whole logic is now in `adob--post-command-hook'. --- auto-dim-other-buffers.el | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/auto-dim-other-buffers.el b/auto-dim-other-buffers.el index 120e7d20fe..e6f18f0e21 100644 --- a/auto-dim-other-buffers.el +++ b/auto-dim-other-buffers.el @@ -81,15 +81,10 @@ Currently only mini buffer and echo areas are ignored." (setq adob--face-mode-remapping))) (force-window-update (current-buffer))) -(defun adob--pre-command-hook () - "Record current buffer before the command is run." - (setq adob--last-buffer (current-buffer))) - (defun adob--post-command-hook () "If buffer has changed, dim the last one and undim the new one." ;; if we haven't switched buffers, do nothing (unless (eq (current-buffer) 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. @@ -98,7 +93,8 @@ Currently only mini buffer and echo areas are ignored." (with-current-buffer adob--last-buffer (adob--dim-buffer t))) ;; now, restore the current buffer, and undim it. - (adob--dim-buffer nil))) + (adob--dim-buffer nil) + (setq adob--last-buffer (current-buffer)))) (defun adob--after-change-major-mode-hook () "Dim or undim a new buffer if a new window, like help window, has popped up." @@ -117,8 +113,7 @@ function." (defun adob--hooks (callback) "Add (if CALLBACK is `add-hook') or remove (if `remove-hook') adob hooks." (dolist (args - '((pre-command-hook adob--pre-command-hook) - (post-command-hook adob--post-command-hook) + '((post-command-hook adob--post-command-hook) (focus-out-hook adob--dim-all-buffers) (focus-in-hook adob--after-change-major-mode-hook) (after-change-major-mode-hook adob--after-change-major-mode-hook)