Skip to content

Commit

Permalink
prot-simple: make focusable buffers a minor-mode
Browse files Browse the repository at this point in the history
I still need to make this work for vc-{pull,push} and related.
  • Loading branch information
protesilaos committed Sep 6, 2021
1 parent 50a3e16 commit 2201b9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions emacs/.emacs.d/prot-emacs.org
Expand Up @@ -261,9 +261,9 @@ appropriate place to re-bind or free up some common key combinations.
describe-char
what-cursor-position
describe-package
view-lossage
vc-git-push
vc-git-pull))
view-lossage))

(prot-simple-focus-help-buffers 1)

;; General commands
(let ((map global-map))
Expand Down
26 changes: 20 additions & 6 deletions emacs/.emacs.d/prot-lisp/prot-simple.el
Expand Up @@ -76,11 +76,17 @@ Used by `prot-simple-inset-date'."
'( describe-symbol describe-function
describe-variable describe-key
view-lossage)
"Commands whose buffers should steal focus.
This makes it easier to dismiss them at once."
"Commands whose buffers should be focused when displayed.
This makes it easier to dismiss them at once.
Also see `prot-simple-focus-help-buffers'."
:type '(repeat symbol)
:group 'prot-simple)

;;; Generic setup

;;;; Focus auxiliary buffers

;; TODO 2021-08-27: Is there a more general way to do this without
;; specifying the BUF? That way we would only need one function.
(defmacro prot-simple--auto-focus-buffer (fn doc buf)
Expand All @@ -102,10 +108,18 @@ Intended as :after advice for `describe-symbol' and friends."
Intended as :after advice for `view-echo-area-messages'."
(messages-buffer))

(dolist (fn prot-simple-focusable-help-commands)
(advice-add fn :after 'prot-simple--help-focus))

(advice-add 'view-echo-area-messages :after 'prot-simple--messages-focus)
;;;###autoload
(define-minor-mode prot-simple-focus-help-buffers
"Add advice to focus `prot-simple-focusable-help-commands'."
:lighter nil
(if prot-simple-focus-help-buffers
(progn
(dolist (fn prot-simple-focusable-help-commands)
(advice-add fn :after 'prot-simple--help-focus))
(advice-add 'view-echo-area-messages :after 'prot-simple--messages-focus))
(dolist (fn prot-simple-focusable-help-commands)
(advice-remove fn 'prot-simple--help-focus))
(advice-remove 'view-echo-area-messages 'prot-simple--messages-focus)))

;;; Commands

Expand Down

0 comments on commit 2201b9c

Please sign in to comment.