;;; jao-afio.el --- workspaces in just one frame -*- lexical-binding: t; -*- ;; Copyright (C) 2020, 2021, 2022 jao ;; Author: jao ;; Keywords: frames ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; 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-switch-hook nil) (defvar jao-afio--configs '(?c ?w ?g ?p ?s)) (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) (if jao-afio-use-frames (set-frame-name "W1") (window-configuration-to-register ?c))) (defun jao-afio--check-frame () (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) (let ((jao-doc-session-inhibit-save t)) (dolist (doc (jao-doc-session)) (when (and (file-exists-p doc) (y-or-n-p (format "Open %s? " doc))) (jao-open-doc doc) (other-window 1))) (other-window 1))) (defun jao-afio-open-doc () (interactive) (delete-other-windows) (split-window-right) (let ((docs (cl-remove-if-not 'jao-doc-session-is-doc (buffer-list)))) (if (car docs) (progn (switch-to-buffer (car docs)) (switch-to-buffer-other-window (or (cadr docs) (car docs)))) (when (and (jao-doc-session) (y-or-n-p "Load saved session? ")) (jao-afio-open-pdf-session))))) (declare w3m "w3m") (declare w3m-alive-p "w3m") (declare w3m-previous-buffer "w3m") (declare notmuch "notmuch") ;;;###autoload (defun jao-afio-open-www () (interactive) (require 'jao-eww-session) (if (< (frame-width) 160) (if jao-afio-use-w3m (w3m) (jao-eww-session-load)) (delete-other-windows) (split-window-right) (if jao-afio-use-w3m (w3m) (jao-eww-session-load) (let ((b (current-buffer))) (other-window 1) (switch-to-buffer (car (jao-eww-session--list-buffers b))) (other-window 1))))) ;;;###autoload (defun jao-afio-open-gnus () (interactive) (delete-other-windows) (org-agenda-list) (calendar) (find-file (expand-file-name "inbox.org" org-directory)) (gnus) (jao-gnus--set-summary-line)) (defun jao-afio--mail-sidebar () (other-window 1) (delete-other-windows-vertically) (find-file (expand-file-name "inbox.org" org-directory)) (split-window-below (/ (window-height) 3)) (other-window 1) (org-agenda-list) (split-window-below -9) (other-window 1) (switch-to-buffer "*Calendar*") (other-window 1)) ;;;###autoload (defun jao-afio-open-notmuch () (interactive) (delete-other-windows) (split-window-horizontally -80) (notmuch) (jao-afio--mail-sidebar)) (defun jao-afio-open-mail-function () (interactive) (jao-trisect) (other-window 2) (delete-window) (other-window 1) (funcall jao-afio-mail-function) (jao-afio--mail-sidebar)) ;;;###autoload (defun jao-afio-open-mail () (interactive) (unless (get-buffer "*Calendar*") (calendar)) (cond ((eq 'gnus jao-afio-mail-function) (jao-afio-open-gnus)) ((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) (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--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) (interactive "P") (jao-afio--goto-frame ?g reset)) (defun jao-afio--goto-docs (&optional reset) (interactive "P") (jao-afio--goto-frame ?p reset)) (defun jao-afio--goto-www (&optional reset) (interactive "P") (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))) ;;;###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)))) ;;; 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) (setq jao-afio-use-frames use-frames) (jao-afio--init)) (provide 'jao-afio) ;;; jao-afio.el ends here