From 03f23bc8da4462c93bf259a960a53d4334ca3482 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Fri, 8 Mar 2019 08:26:34 -0500 Subject: Initial commit. --- exwm-buffer-groups.el | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 exwm-buffer-groups.el (limited to 'exwm-buffer-groups.el') diff --git a/exwm-buffer-groups.el b/exwm-buffer-groups.el new file mode 100644 index 0000000..b937261 --- /dev/null +++ b/exwm-buffer-groups.el @@ -0,0 +1,77 @@ +;;; exwm-buffer-groups.el --- Buffer grouping for EXWM workspaces. -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Jakob L. Kreuze + +;; Author: Jakob L. Kreuze +;; Version: 1.0 +;; Package-Requires (exwm) +;; Keywords: frames +;; URL: https://git.sr.ht/~jakob/exwm-buffer-groups + +;; 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: + +;; The default behavior of EXWM is to make buffers containing X windows +;; accessible only from the workspace they were created in. This is a useful +;; feature, but introduces some level of inconsistency as this does not apply to +;; normal buffers. exwm-buffer-groups aims to change this by associating all +;; buffers with a workspace. + +;;; Code: + +(require 'exwm) + +(defun exwm-buffer-groups-default-buffers () + "Initial list of buffers for a workspace." + (if (get-buffer "*scratch*") + (list (get-buffer "*scratch*")) + nil)) + +(defvar exwm-buffer-groups-buffers + (make-vector exwm-workspace-number (exwm-buffer-groups-default-buffers)) + "Vector containing lists of associated buffers for each workspace.") + +(defun exwm-buffer-groups--buffer-seen-p (buffer) + "Whether or not BUFFER is contained in `exwm-buffer-groups-buffers'." + (reduce #'(lambda (x y) (or x y)) + (map 'list + #'(lambda (workspace) + (memq buffer workspace)) + exwm-buffer-groups-buffers))) + +(defun exwm-buffer-groups--remove-buffers () + "Removes dead buffers from `exwm-buffer-groups-buffers'." + (setq exwm-buffer-groups-buffers + (map 'vector + #'(lambda (buffers) (remove-if-not #'buffer-live-p buffers)) + exwm-buffer-groups-buffers))) + +(defun exwm-buffer-groups--add-buffers () + "Adds unseen buffers to `exwm-buffer-groups-buffers'. +Any unseen buffers are added to the entry corresponding to the +current workspace." + (dolist (buffer (buffer-list)) + (unless (exwm-buffer-groups--buffer-seen-p buffer) + (push buffer (elt exwm-buffer-groups-buffers exwm-workspace-current-index))))) + +(defun exwm-buffer-groups-update () + "Updates `exwm-buffer-groups-buffers' to reflect the buffer list." + (exwm-buffer-groups--remove-buffers) + (exwm-buffer-groups--add-buffers)) + +(add-hook 'after-change-major-mode-hook #'exwm-buffer-groups-update) + +(provide 'exwm-buffer-groups) +;;; exwm-buffer-groups.el ends here -- cgit v1.3