From 2c6afef1f6bb75097bd192ccb8a88489da4eb063 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 2 Sep 2022 02:37:20 +0100 Subject: afio frame toggling and clean-ups --- lib/eos/jao-afio.el | 72 ++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'lib/eos') diff --git a/lib/eos/jao-afio.el b/lib/eos/jao-afio.el index 4000eca..7bb85a0 100644 --- a/lib/eos/jao-afio.el +++ b/lib/eos/jao-afio.el @@ -30,14 +30,12 @@ (defvar jao-afio-switch-hook nil) (defvar jao-afio--configs '(?c ?w ?g ?p ?s)) +(defvar jao-afio--previous-config (car jao-afio--configs)) (defun jao-afio--current-config (&optional c f) (when c (modify-frame-parameters f `((afio . ,c)))) (frame-parameter f 'afio)) -(defun jao-afio--check-frame-p () - (assoc 'afio (frame-parameters))) - (defun jao-afio--init (&optional f) (interactive) (jao-afio--current-config ?c) @@ -170,60 +168,66 @@ (defun jao-afio--goto-frame (next &optional reset) (jao-afio--check-frame) - (when (or reset (not (eq next (jao-afio--current-config)))) - (if jao-afio-use-frames - (let ((f (jao-afio--find-frame next))) - (select-frame-set-input-focus (or f (make-frame))) - (when (setq reset (or reset (not f))) - (set-frame-name (format "W%s" (or (jao-afio-frame-no next) next))))) - (window-configuration-to-register (jao-afio--current-config)) - (when (and (not reset) (get-register next)) (jump-to-register next))) - (jao-afio--current-config next) - (when reset (jao-afio-reset)) - (run-hooks 'jao-afio-switch-hook))) - -(defun jao-afio--goto-main (&optional reset) + (let ((current (jao-afio--current-config))) + (if (and (eq next current) + (not reset) + (not (eq current jao-afio--previous-config))) + (jao-afio--goto-frame jao-afio--previous-config) + (when (or reset (not (eq next current))) + (if jao-afio-use-frames + (let ((f (jao-afio--find-frame next))) + (select-frame-set-input-focus (or f (make-frame))) + (when (setq reset (or reset (not f))) + (set-frame-name (format "W%s" (or (jao-afio-frame-no next) next))))) + (window-configuration-to-register (jao-afio--current-config)) + (when (and (not reset) (get-register next)) (jump-to-register next))) + (jao-afio--current-config next) + (unless (eq current next) (setq jao-afio--previous-config current)) + (when reset (jao-afio-reset)) + (run-hooks 'jao-afio-switch-hook))))) + +(defun jao-afio-goto-main (&optional reset) (interactive "P") (jao-afio--goto-frame ?c reset)) -(defun jao-afio--goto-scratch (&optional reset) - (interactive "P") - (jao-afio--goto-frame ?s reset)) - -(defun jao-afio--goto-mail (&optional reset) +(defun jao-afio-goto-mail (&optional reset) (interactive "P") (jao-afio--goto-frame ?g reset)) -(defun jao-afio--goto-docs (&optional reset) +(defun jao-afio-goto-docs (&optional reset) (interactive "P") (jao-afio--goto-frame ?p reset)) -(defun jao-afio--goto-www (&optional reset) +(defun jao-afio-goto-www (&optional reset) (interactive "P") (jao-afio--goto-frame ?w reset)) +(defun jao-afio-toggle () + (interactive) + (jao-afio--goto-frame jao-afio--previous-config)) + (defun jao-afio-goto-scratch (&optional one-win) (interactive "P") - (jao-afio--goto-scratch) + (jao-afio--goto-frame ?s nil) (when one-win (delete-other-windows))) ;;;###autoload (defun jao-afio-goto-nth (n) (cl-case n - ((1) (jao-afio--goto-main)) - ((2) (jao-afio--goto-mail)) - ((3) (jao-afio--goto-www)) - ((4) (jao-afio--goto-docs)) - ((5) (jao-afio--goto-scratch t)) - ((0) (jao-afio--goto-scratch)))) + ((1) (jao-afio-goto-main)) + ((2) (jao-afio-goto-mail)) + ((3) (jao-afio-goto-www)) + ((4) (jao-afio-goto-docs)) + ((5) (jao-afio-goto-scratch t)) + ((0) (jao-afio-goto-scratch)))) ;;; setup ;;;###autoload (defun jao-afio-setup (&optional use-frames) - (global-set-key "\C-cf" 'jao-afio--goto-main) - (global-set-key "\C-cg" 'jao-afio--goto-mail) - (global-set-key "\C-cw" 'jao-afio--goto-www) - (global-set-key "\C-cz" 'jao-afio--goto-docs) + (global-set-key "\C-cf" 'jao-afio-goto-main) + (global-set-key "\C-cg" 'jao-afio-goto-mail) + (global-set-key "\C-cw" 'jao-afio-goto-www) + (global-set-key "\C-cz" 'jao-afio-goto-docs) (setq jao-afio-use-frames use-frames) (jao-afio--init)) -- cgit v1.2.3