From 686ff8fa2fb5b6cd655834f3af5cd234feef8918 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 28 Aug 2022 20:55:21 +0100 Subject: afio: option to use frames (for terminals) and cleanups galore --- custom/jao-custom-completion.el | 3 +- custom/jao-custom-notmuch.el | 2 +- init.el | 19 ++--- lib/eos/jao-afio.el | 154 ++++++++++++++----------------------- lib/themes/jao-light-term-theme.el | 3 +- 5 files changed, 67 insertions(+), 114 deletions(-) diff --git a/custom/jao-custom-completion.el b/custom/jao-custom-completion.el index 0c67fbb..0682b44 100644 --- a/custom/jao-custom-completion.el +++ b/custom/jao-custom-completion.el @@ -273,8 +273,7 @@ (defun jao-consult-initial-narrow () (when-let (c (cond ((eq this-command #'consult-buffer) - (cdr (assoc (jao-afio-current-frame) - jao-consult-narrow))) + (cdr (assoc (jao-afio-frame-name) jao-consult-narrow))) ((eq this-command #'consult-mode-command) ?m))) (setq unread-command-events (append unread-command-events `(,c 32))))) diff --git a/custom/jao-custom-notmuch.el b/custom/jao-custom-notmuch.el index 86555d1..a374ebd 100644 --- a/custom/jao-custom-notmuch.el +++ b/custom/jao-custom-notmuch.el @@ -271,7 +271,7 @@ (defun jao-notmuch-refresh-hello (&optional agenda) (interactive "P") (ignore-errors - (when (and (string= "Mail" (jao-afio-current-frame)) + (when (and (string= "Mail" (jao-afio-frame-name)) (derived-mode-p 'notmuch-hello-mode)) (when (not (string-blank-p jao-notmuch-minibuffer-string)) (let ((notmuch-hello-auto-refresh nil)) (notmuch-hello))) diff --git a/init.el b/init.el index 9952379..213ad94 100644 --- a/init.el +++ b/init.el @@ -1284,7 +1284,7 @@ (menu-bar-mode -1) ;; (setting it to nil avoids mouse wrapping after other-frame) -(setq focus-follows-mouse t) +(setq focus-follows-mouse (and window-system t)) (use-package scroll-bar) (set-scroll-bar-mode nil) @@ -1312,22 +1312,15 @@ (delete-window)) ;;;; afio -(use-package jao-afio) - -(defun jao-xmonad-goto-1 () - (shell-command "sendCommand 1")) - -(defun jao-afio--goto-scratch-1 () - (interactive) - (jao-afio-goto-scratch t)) - -(jao-afio-setup 'jao-afio--goto-scratch-1 t) +(use-package jao-afio + :demand t + :config (jao-afio-setup (not window-system))) (defun jao-current--frame-id () (propertize (if (and (jao-exwm-enabled-p) (not (bound-and-true-p jao-exwm--use-afio))) (format "F%s" exwm-workspace-current-index) - (format "%s" (jao-afio-current-no))) + (format "%s" (jao-afio-frame-no))) 'face 'font-lock-warning-face)) (add-hook 'jao-afio-switch-hook #'tracking-remove-visible-buffers) @@ -1335,7 +1328,7 @@ (defun jao-afio--set-mode-line () (when (and window-system (fboundp 'jao-mode-line-hide-inactive)) - (if (string= "Docs" (jao-afio-current-frame)) + (if (string= "Docs" (jao-afio-frame-name)) (jao-mode-line-show-inactive nil) (jao-mode-line-hide-inactive nil)))) diff --git a/lib/eos/jao-afio.el b/lib/eos/jao-afio.el index 98a8760..092a902 100644 --- a/lib/eos/jao-afio.el +++ b/lib/eos/jao-afio.el @@ -18,60 +18,38 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -;;; Code: - +;;; initialisation (require 'cl-lib) (require 'jao-doc-session) +(defvar jao-afio-use-frames (not window-system)) + (defvar jao-open-doc-fun 'find-file) (defvar jao-afio-mail-function 'gnus) (defvar jao-afio-use-w3m nil) -(defvar jao-afio-notmuch-in-web nil) (defvar jao-afio-switch-hook nil) (defvar jao-afio--configs '(?c ?w ?g ?p ?s)) -(defvar jao-afio--current-config (car jao-afio--configs)) -(defvar jao-afio--locker nil) -(defvar jao-afio-fallback-fun nil) + +(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) - (when (and (frame-live-p jao-afio--locker) - (not (eql f jao-afio--locker))) - (if jao-afio-fallback-fun - (funcall jao-afio-fallback-fun) - (error "Another frame is using afio"))) - (setq jao-afio--locker f) - (modify-frame-parameters f '((afio . t))) - (setq jao-afio--current-config ?c) - (mapc (lambda (r) (set-register r nil)) jao-afio--configs) - (window-configuration-to-register ?c)) - -(defun jao-afio--steal () - (interactive) - (setq jao-afio--locker nil) - (jao-afio--init (window-frame (get-buffer-window (current-buffer))))) + (jao-afio--current-config ?c) + (if jao-afio-use-frames + (set-frame-name "W1") + (window-configuration-to-register ?c))) (defun jao-afio--check-frame () - (unless (jao-afio--check-frame-p) - (or ;; (when jao-afio-fallback-fun - ;; (funcall jao-afio-fallback-fun) - ;; t) - (when (y-or-n-p "Another frame is using afio. Steal? ") - (jao-afio--steal) - t) - (error "Aborted")))) - -(defun jao-afio--next-frame () - (interactive) - (jao-afio--check-frame) - (let* ((cur (member jao-afio--current-config jao-afio--configs)) - (next (or (cadr cur) (car jao-afio--configs)))) - (jao-afio--goto-frame next))) + (unless (jao-afio--current-config) + (jao-afio--init (window-frame (get-buffer-window (current-buffer)))))) +;;; session openers ;;;###autoload (defun jao-afio-open-pdf-session () (interactive) @@ -111,9 +89,7 @@ (jao-eww-session-load) (let ((b (current-buffer))) (other-window 1) - (if jao-afio-notmuch-in-web - (notmuch) - (switch-to-buffer (car (jao-eww-session--list-buffers b)))) + (switch-to-buffer (car (jao-eww-session--list-buffers b))) (other-window 1))))) ;;;###autoload @@ -163,84 +139,68 @@ ((eq 'notmuch jao-afio-mail-function) (jao-afio-open-notmuch)) (jao-afio-open-mail-function (jao-afio-open-mail-function)))) +;;;###autoload +(defun jao-afio-reset () + (interactive) + (delete-other-windows) + (cl-case (jao-afio--current-config) + (?w (jao-afio-open-www)) + (?g (jao-afio-open-mail)) + (?p (jao-afio-open-doc)) + (?s (delete-other-windows)))) + +;;; go to frame +(defsubst jao-afio--find-frame (c) + (seq-find (lambda (f) (eq (jao-afio--current-config nil f) c)) (frame-list))) + +(defun jao-afio-frame-name (&optional c) + (alist-get (or c (jao-afio--current-config)) + '((?c . "Main") (?s . "Scratch") (?g . "Mail") + (?p . "Docs") (?w . "Web")))) + +(defun jao-afio-frame-no (&optional c) + (alist-get (or c (jao-afio--current-config)) + '((?s . 0) (?c . 1) (?g . 2) (?w . 3) (?p . 4)))) + (defun jao-afio--goto-frame (next &optional reset) - (when (or reset (not (eq next jao-afio--current-config))) - (let ((next-cfg (when (not reset) (get-register next)))) - (window-configuration-to-register jao-afio--current-config) - (setq jao-afio--current-config next) - (if next-cfg - (jump-to-register next) - (delete-other-windows) - (cl-case next - (?w (jao-afio-open-www)) - (?g (jao-afio-open-mail)) - (?p (jao-afio-open-doc)) - (?s (delete-other-windows)))) - (run-hooks 'jao-afio-switch-hook)))) + (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) (interactive "P") - (jao-afio--check-frame) (jao-afio--goto-frame ?c reset)) (defun jao-afio--goto-scratch (&optional reset) (interactive "P") - (jao-afio--check-frame) (jao-afio--goto-frame ?s reset)) (defun jao-afio--goto-mail (&optional reset) (interactive "P") - (jao-afio--check-frame) (jao-afio--goto-frame ?g reset)) (defun jao-afio--goto-docs (&optional reset) (interactive "P") - (jao-afio--check-frame) (jao-afio--goto-frame ?p reset)) (defun jao-afio--goto-www (&optional reset) (interactive "P") - (if (jao-afio--check-frame-p) - (jao-afio--goto-frame ?w reset) - (when (and jao-afio-use-w3m (w3m-alive-p)) - (pop-to-buffer (w3m-alive-p))))) - -(defun jao-afio--try-init (&optional f) - (ignore-errors (jao-afio--init f)) - t) - -(defun jao-afio--goto-www-buffer (buf &rest _) - (jao-afio--goto-www) - (jao-first-window) - (switch-to-buffer buf nil t)) - -(defun jao-afio--goto-pdf-buffer (buf &rest _) - (if (jao-afio--check-frame-p) - (progn (jao-afio--goto-docs) - (jao-first-window) - (switch-to-buffer buf nil t)) - (pop-to-buffer buf))) + (jao-afio--goto-frame ?w reset)) (defun jao-afio-goto-scratch (&optional one-win) + (interactive "P") (jao-afio--goto-scratch) (when one-win (delete-other-windows))) -(defun jao-afio-current-frame () - (cl-case jao-afio--current-config - (?c "Main") - (?s "Scratch") - (?g "Mail") - (?p "Docs") - (?w "Web"))) - -(defun jao-afio-current-no () - (cl-case jao-afio--current-config - (?c "1") - (?s "0") - (?g "2") - (?p "4") - (?w "3"))) - ;;;###autoload (defun jao-afio-goto-nth (n) (cl-case n @@ -248,18 +208,18 @@ ((2) (jao-afio--goto-mail)) ((3) (jao-afio--goto-www)) ((4) (jao-afio--goto-docs)) - ((5) (jao-afio--goto-scratch-1)) + ((5) (jao-afio--goto-scratch t)) ((0) (jao-afio--goto-scratch)))) +;;; setup ;;;###autoload -(defun jao-afio-setup (&optional fallback-fun init-p) +(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) - (setq jao-afio-fallback-fun fallback-fun) - (add-hook (if init-p 'after-init-hook 'after-make-frame-functions) - 'jao-afio--try-init)) + (setq jao-afio-use-frames use-frames) + (jao-afio--init)) (provide 'jao-afio) ;;; jao-afio.el ends here diff --git a/lib/themes/jao-light-term-theme.el b/lib/themes/jao-light-term-theme.el index 61a81a7..f7b2eb8 100644 --- a/lib/themes/jao-light-term-theme.el +++ b/lib/themes/jao-light-term-theme.el @@ -112,7 +112,8 @@ (vertical-border (c "grey70" nil)) (vertico-current (c nil yellow) nul ext) (widget-button (c blue nil) nit nul) - (widget-field (c nil bg-light) nit nul))) + (widget-field (c nil bg-light) nit nul) + (whitespace-tag (p hilite)))) ;; (enable-theme 'jao-light-term) ;; (jao-mode-line-adjust-faces) -- cgit v1.2.3