Browse Source

Initial import

tags/v0.1.0
Peter J. Jones 1 year ago
commit
1cee4bb7d2
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
3 changed files with 188 additions and 0 deletions
  1. 20
    0
      LICENSE
  2. 0
    0
      README.md
  3. 168
    0
      exwm-nw.el

+ 20
- 0
LICENSE View File

@@ -0,0 +1,20 @@
1
+Copyright (C) 2018 Peter Jones <pjones@devalot.com>
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining
4
+a copy of this software and associated documentation files (the
5
+"Software"), to deal in the Software without restriction, including
6
+without limitation the rights to use, copy, modify, merge, publish,
7
+distribute, sublicense, and/or sell copies of the Software, and to
8
+permit persons to whom the Software is furnished to do so, subject to
9
+the following conditions:
10
+
11
+The above copyright notice and this permission notice shall be
12
+included in all copies or substantial portions of the Software.
13
+
14
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0
- 0
README.md View File


+ 168
- 0
exwm-nw.el View File

@@ -0,0 +1,168 @@
1
+;;; exwm-nw.el --- Named workspaces for EXWM. -*- lexical-binding: t -*-
2
+
3
+;; Copyright (C) 2018 Peter Jones <pjones@devalot.com>
4
+
5
+;; Author: Peter Jones <pjones@devalot.com>
6
+;; Homepage: https://github.com/pjones/exwm-nw
7
+;; Package-Requires: ((emacs "24.4") (exwm "0.18"))
8
+;; Version: 0.1.0
9
+;;
10
+;; This file is not part of GNU Emacs.
11
+
12
+;;; Commentary:
13
+;;
14
+;; FIXME:
15
+
16
+;;; License:
17
+;;
18
+;; Permission is hereby granted, free of charge, to any person obtaining
19
+;; a copy of this software and associated documentation files (the
20
+;; "Software"), to deal in the Software without restriction, including
21
+;; without limitation the rights to use, copy, modify, merge, publish,
22
+;; distribute, sublicense, and/or sell copies of the Software, and to
23
+;; permit persons to whom the Software is furnished to do so, subject to
24
+;; the following conditions:
25
+;;
26
+;; The above copyright notice and this permission notice shall be
27
+;; included in all copies or substantial portions of the Software.
28
+;;
29
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33
+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34
+;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35
+;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
+
37
+;;; Code:
38
+(require 'ring)
39
+(require 'exwm)
40
+
41
+
42
+;; Customize interface:
43
+(defgroup exwm-nw nil
44
+  "A minor mode and functions for naming and managing EXWM
45
+workspaces."
46
+  :version "25.3"
47
+  :group 'applications)
48
+
49
+(defcustom exwm-nw-workspace-ring-size 5
50
+  "Number of workspaces to keep in the history ring."
51
+  :group 'exwm-nw
52
+  :type 'integer)
53
+
54
+
55
+;; Internal variables:
56
+(defvar exwm-nw-mode-map (make-sparse-keymap)
57
+  "Key map for the `exwm-nw' minor mode.")
58
+
59
+(defvar exwm-nw-prev-workspace-index-map exwm-workspace-index-map
60
+  "Used to restore the previous value of `exwm-workspace-index-map'.")
61
+
62
+(defvar exwm-nw-workspace-ring nil
63
+  "Ring of workspaces.")
64
+
65
+(defvar exwm-nw--previous-workspace nil
66
+  "Remember the previous workspace.")
67
+
68
+
69
+;; Internal Functions
70
+(defun exwm-nw-set-name-prompt (workspace)
71
+  "Prompt for the new name of WORKSPACE."
72
+  (read-string "Workspace Name: " (exwm-nw-get workspace)))
73
+
74
+(defun exwm-nw-get (frame-or-index)
75
+  "Return the name of the workspace identified by FRAME-OR-INDEX."
76
+  (let ((ws (exwm-workspace--workspace-from-frame-or-index frame-or-index)))
77
+    (frame-parameter ws 'exwm-nw-name)))
78
+
79
+(defun exwm-nw-format (index)
80
+  "Format the name of the workspace at INDEX."
81
+  (let ((name (exwm-nw-get index)))
82
+    (if name (format "%s:%s" index name)
83
+      (number-to-string index))))
84
+
85
+(defun exwm-nw--remember-current-workspace (&rest _args)
86
+  "Record the current workspace before it becomes the previous."
87
+  (setq exwm-nw--previous-workspace exwm-workspace--current))
88
+
89
+(defun exwm-nw--workspace-switch-hook ()
90
+  "Respond to EXWM switching workspaces."
91
+  (when (and exwm-nw--previous-workspace
92
+             (not (equal exwm-nw--previous-workspace
93
+                         exwm-workspace--current)))
94
+    (ring-remove+insert+extend
95
+     exwm-nw-workspace-ring
96
+     exwm-nw--previous-workspace)))
97
+
98
+(defun exwm-nw--goto-workspace (workspace)
99
+  "Go to WORKSPACE doing the right thing with the minibuffer."
100
+  (if (minibuffer-window-active-p (selected-window))
101
+      (let ((pos (exwm-workspace--position workspace)))
102
+        (when pos
103
+          (goto-history-element (+ 1 pos))
104
+          (exit-minibuffer)))
105
+    (exwm-workspace-switch workspace)))
106
+
107
+
108
+;; Public functions:
109
+
110
+;;;###autoload
111
+(defun exwm-nw-set (frame-or-index &optional name)
112
+  "Set workspace name for FRAME-OR-INDEX to NAME.
113
+
114
+You probably want to bind this function to a key in
115
+`exwm-nw-mode-map'."
116
+  (interactive (list exwm-workspace--current nil))
117
+  (let* ((ws (exwm-workspace--workspace-from-frame-or-index frame-or-index))
118
+         (name (or name (exwm-nw-set-name-prompt ws))))
119
+    (when (and ws name)
120
+      (set-frame-parameter ws 'exwm-nw-name name)
121
+      (setq exwm-workspace--switch-history-outdated t))))
122
+
123
+;;;###autoload
124
+(defun exwm-nw-goto-previous ()
125
+  "Switch to the previous workspace.
126
+
127
+You may want to bind this function to a key in `exwm-nw-mode-map'
128
+and in `exwm-workspace--switch-map'."
129
+  (interactive)
130
+  (let ((ws (ring-ref exwm-nw-workspace-ring 0)))
131
+    (when ws (exwm-nw--goto-workspace ws))))
132
+
133
+;;;###autoload
134
+(define-minor-mode exwm-nw-mode
135
+  "Global minor mode that helps manage workspaces in EXWM.
136
+
137
+Some of its features are:
138
+
139
+  - Assign a name to a workspace (`exwm-nw-set')
140
+  - Keep a history of workspaces in a ring
141
+  - Jump to the previous workspace (`exwm-nw-goto-previous')
142
+
143
+By default this minor mode does not have any keybindings in order
144
+to avoid clobbering any bindings you may already have.  Here are
145
+some recommendations:
146
+
147
+
148
+    (define-key exwm-nw-mode-map (kbd \"s-n\") 'exwm-nw-set)
149
+    (define-key exwm-nw-mode-map (kbd \"s-l\") 'exwm-nw-goto-previous)
150
+    (define-key exwm-workspace--switch-map (kbd \"C-l\") 'exwm-nw-goto-previous)
151
+
152
+Enjoy!"
153
+  :group  'exwm-nw
154
+  :keymap 'exwm-nw-mode-map
155
+  :global t
156
+  (if exwm-nw-mode
157
+      (progn
158
+        (setq exwm-nw-prev-workspace-index-map exwm-workspace-index-map
159
+              exwm-workspace-index-map #'exwm-nw-format
160
+              exwm-nw-workspace-ring (make-ring exwm-nw-workspace-ring-size))
161
+        (add-hook 'exwm-workspace-switch-hook #'exwm-nw--workspace-switch-hook)
162
+        (advice-add 'exwm-workspace-switch :before #'exwm-nw--remember-current-workspace))
163
+    (setq exwm-workspace-index-map exwm-nw-prev-workspace-index-map)
164
+    (remove-hook 'exwm-workspace-switch-hook #'exwm-nw--workspace-switch-hook)
165
+    (advice-remove 'exwm-workspace-switch #'exwm-nw--remember-current-workspace)))
166
+
167
+(provide 'exwm-nw)
168
+;;; exwm-nw.el ends here

Loading…
Cancel
Save