diff --git a/config-base.org b/config-base.org index 3100e9e..a197d24 100644 --- a/config-base.org +++ b/config-base.org @@ -2320,43 +2320,46 @@ #+end_src ** workgroups2 #+begin_src emacs-lisp - (use-package workgroups2) + ;; (use-package workgroups2) - (setq wg-prefix-key (kbd "C-c z")) + ;; (setq wg-prefix-key (kbd "C-c z")) - (setq wg-session-file "~/.emacs.d/.emacs_workgroups") + ;; (setq wg-session-file "~/.emacs.d/.emacs_workgroups") - (define-prefix-command '*workgroup-map*) + (require 'ivy-window-configurations) - (define-key *root-map* (kbd "b") #'wg-switch-to-workgroup) - (define-key *root-map* (kbd "u") #'wg-undo-wconfig-change) - (define-key *root-map* (kbd "R") #'wg-rename-workgroup) - (define-key *root-map* (kbd "q") #'wg-kill-workgroup) - (define-key *root-map* (kbd "Q") #'wg-delete-other-workgroups) + (define-key *root-map* (kbd "b") #'iwc-switch-to-wc) + (define-key *root-map* (kbd "R") #'iwc-rename) - (setq wg-emacs-exit-save-behavior nil - wg-workgroups-mode-exit-save-behavior nil) + (iwc-mode) + ;; (define-key *root-map* (kbd "u") #'wg-undo-wconfig-change) + ;; (define-key *root-map* (kbd "q") #'wg-kill-workgroup) + ;; (define-key *root-map* (kbd "Q") #'wg-delete-other-workgroups) + + ;; (setq wg-emacs-exit-save-behavior nil + ;; wg-workgroups-mode-exit-save-behavior nil) - ;; Advice for frames, don't switch to an active workgroup - (defun get-active-workgroups () - (loop for frame in exwm-workspace--list - unless (eq (selected-frame) frame) - collect (with-selected-frame frame - (wg-workgroup-name (wg-current-workgroup))))) + ;; ;; Advice for frames, don't switch to an active workgroup + ;; (defun get-active-workgroups () + ;; (loop for frame in exwm-workspace--list + ;; unless (eq (selected-frame) frame) + ;; collect (with-selected-frame frame + ;; (wg-workgroup-name (wg-current-workgroup))))) - (defun wg-dont-switch-to-active (orig &optional workgroup noerror) - (if workgroup - (funcall orig workgroup noerror) - (let ((active (get-active-workgroups)) - (to-switch (wg-read-workgroup-name))) - (if (member to-switch active) - (message "Workgroup \"%s\" already active" to-switch) - (funcall orig to-switch noerror))))) + ;; (defun wg-dont-switch-to-active (orig &optional workgroup noerror) + ;; (interactive) + ;; (if workgroup + ;; (funcall orig workgroup noerror) + ;; (let ((active (get-active-workgroups)) + ;; (to-switch (wg-read-workgroup-name))) + ;; (if (member to-switch active) + ;; (message "Workgroup \"%s\" already active" to-switch) + ;; (funcall orig to-switch noerror))))) - (advice-add #'wg-switch-to-workgroup - :around - #'wg-dont-switch-to-active) + ;; (advice-add #'wg-switch-to-workgroup + ;; :around + ;; #'wg-dont-switch-to-active) #+end_src ** opml to elfeed-org #+begin_src emacs-lisp diff --git a/lisp/ivy-window-configurations.el b/lisp/ivy-window-configurations.el new file mode 100644 index 0000000..92d2584 --- /dev/null +++ b/lisp/ivy-window-configurations.el @@ -0,0 +1,94 @@ +;;; ivy-window-configurations.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2020 Benson Chu + +;; Author: Benson Chu +;; Created: [2020-01-07 10:10] + +;; This file is not part of GNU Emacs + +;; 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 . + +;;; Commentary: + +;; I used workgroups2 before this, but workgroups2 had a lot of +;; functionality that I didn't need, and it appears that it is +;; because of this feature creep that workgroups2 will grind Emacs to +;; a halt for long running sessions. I haven't had time to look into +;; why this is the case. Instead I just threw this together. + +;;; Code: + +(defvar iwc/configurations nil) + +(defun iwc-set-current-wc-name (name) + (set-frame-parameter (selected-frame) 'iwc-current-wc-name + name)) + +(defun iwc-get-current-wc-name () + (frame-parameter (selected-frame) 'iwc-current-wc-name)) + +(define-minor-mode iwc-mode + "My ivy implementation of Emacs' built in window-configuration + management system." + nil nil nil + :global t + (cond (iwc-mode + (setq iwc/configurations (make-hash-table :test 'equal)) + (iwc-switch-to-wc "scratch")) + (t + (setq iwc/configurations nil) + (dolist (f (frame-list)) + (with-selected-frame f + (iwc-set-current-wc-name nil)))))) + +(defun iwc-active-on-frame? (wc-name) + (when-let (f (catch 'return + (dolist (f (frame-list)) + (with-selected-frame f + (when (string= wc-name + (iwc-get-current-wc-name)) + (throw 'return f)))))) + (if (equal f (selected-frame)) + (message "Already on wc: \"%s\"" wc-name) + (message "wc \"%s\" active on another frame" wc-name)))) + +(defun iwc-switch-to-wc (wc-name) + (interactive (list (ivy-completing-read "wc? " (hash-table-keys iwc/configurations) + nil nil ))) + (when (not iwc-mode) + (error "Not in iwc-mode")) + (unless (iwc-active-on-frame? wc-name) + (awhen (iwc-get-current-wc-name) + (puthash it + (current-window-configuration) + iwc/configurations)) + (awhen (gethash wc-name iwc/configurations) + (set-window-configuration it)) + (iwc-set-current-wc-name wc-name) + (puthash wc-name nil iwc/configurations))) + +(defun iwc-rename (name) + (interactive (list (read-from-minibuffer "Name? "))) + (when (not iwc-mode) + (error "Not in iwc-mode")) + (remhash (iwc-get-current-wc-name) iwc/configurations) + (puthash name nil iwc/configurations) + (iwc-set-current-wc-name name)) + +;; (unless (iwc-active-on-frame? "scratch") +;; (remhash "scratch" iwc/configurations)) + +(provide 'ivy-window-configurations) +;;; ivy-window-configurations.el ends here