diff options
author | JSDurand <mmemmew@gmail.com> | 2023-07-29 23:44:42 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-07-29 23:44:42 +0800 |
commit | e2f96a80b823fd4565939e104e6f014fea87f583 (patch) | |
tree | 96cae0b10c491a57ff58773c6615e0b81565786d | |
parent | 5eb614d9e7a4599848e5e6e79a1f70e4294ea8c5 (diff) |
modeline: `mode-line-window-selected-p`
* modeline.el: (modeline-get-active-window, modeline-active-window,
modeline-active-window-p, modeline-set-active-window,
modeline-unset-active-window, modeline-refresh-modeline,
window-configuration-change-hook, buffer-list-update-hook,
after-make-frame-functions, delete-frame-functions,
handle-switch-frame): Emacs 29 adds a convenient function
`mode-line-window-selected-p` that makes my old manual implementation
here obsolete now.
-rw-r--r-- | modeline.el | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/modeline.el b/modeline.el index a505733..52ae9af 100644 --- a/modeline.el +++ b/modeline.el @@ -169,53 +169,58 @@ MAP is the local keymap of the text." ;; NOTE: I tried to avoid this, but it turns out that this is the most ;; reliable way to do so. -;;;###autoload -(defun modeline-get-active-window (&optional frame) - "The active window excluding the child windows." - (cond - ((and (fboundp #'frame-parent) (frame-parent frame)) - (frame-selected-window (frame-parent frame))) - ((frame-selected-window frame)))) - -;;;###autoload -(defvar modeline-active-window (modeline-get-active-window) - "The active window excluding the child windows.") - -;;;###autoload -(defun modeline-active-window-p () - "Whether we are in the active window." - (and modeline-active-window - (eq modeline-active-window (selected-window)))) - -;;;###autoload -(defun modeline-set-active-window (&rest _) - "Update `modeline-active-window'." - (let ((active-wn (modeline-get-active-window))) - (cond - ((minibuffer-window-active-p active-wn)) - (t (setq modeline-active-window active-wn)))) - (force-mode-line-update t)) - -;;;###autoload -(defsubst modeline-unset-active-window (&rest _) - "Set `modeline-active-window' to `nil'." - (setq modeline-active-window nil)) - -;;;###autoload -(defun modeline-refresh-modeline () - "Refresh the focus state of the mode line." - (setq modeline-active-window nil) - (mapc (lambda (frame) - (cond ((eq (frame-focus-state frame) t) - (setq modeline-active-window (modeline-get-active-window frame))))) - (frame-list))) - -(add-hook 'window-configuration-change-hook #'modeline-set-active-window) -(add-hook 'buffer-list-update-hook #'modeline-set-active-window) -(add-hook 'after-make-frame-functions #'modeline-set-active-window) -(add-hook 'delete-frame-functions #'modeline-set-active-window) -(advice-add #'handle-switch-frame :after #'modeline-set-active-window) -(add-function :after after-focus-change-function #'modeline-refresh-modeline) +;; NOTE: Emacs-29 adds the function `mode-line-window-selected-p' +;; which does what I manually implemented here. + +;; ;;;###autoload +;; (defun modeline-get-active-window (&optional frame) +;; "The active window excluding the child windows." +;; (cond +;; ((and (fboundp #'frame-parent) (frame-parent frame)) +;; (frame-selected-window (frame-parent frame))) +;; ((frame-selected-window frame)))) + +;; ;;;###autoload +;; (defvar modeline-active-window (modeline-get-active-window) +;; "The active window excluding the child windows.") + +(defalias #'modeline-active-window-p #'mode-line-window-selected-p) + +;; ;;;###autoload +;; (defun modeline-active-window-p () +;; "Whether we are in the active window." +;; (and modeline-active-window +;; (eq modeline-active-window (selected-window)))) + +;; ;;;###autoload +;; (defun modeline-set-active-window (&rest _) +;; "Update `modeline-active-window'." +;; (let ((active-wn (modeline-get-active-window))) +;; (cond +;; ((minibuffer-window-active-p active-wn)) +;; (t (setq modeline-active-window active-wn)))) +;; (force-mode-line-update t)) + +;; ;;;###autoload +;; (defsubst modeline-unset-active-window (&rest _) +;; "Set `modeline-active-window' to `nil'." +;; (setq modeline-active-window nil)) + +;; ;;;###autoload +;; (defun modeline-refresh-modeline () +;; "Refresh the focus state of the mode line." +;; (setq modeline-active-window nil) +;; (mapc (lambda (frame) +;; (cond ((eq (frame-focus-state frame) t) +;; (setq modeline-active-window (modeline-get-active-window frame))))) +;; (frame-list))) + +;; (add-hook 'window-configuration-change-hook #'modeline-set-active-window) +;; (add-hook 'buffer-list-update-hook #'modeline-set-active-window) +;; (add-hook 'after-make-frame-functions #'modeline-set-active-window) +;; (add-hook 'delete-frame-functions #'modeline-set-active-window) +;; (advice-add #'handle-switch-frame :after #'modeline-set-active-window) +;; (add-function :after after-focus-change-function #'modeline-refresh-modeline) ;;; Faces |