-
Notifications
You must be signed in to change notification settings - Fork 3
/
eev-multiwindow.el
187 lines (149 loc) · 6.6 KB
/
eev-multiwindow.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
;; eev-multiwindow.el - functions to create multi-window setups -*- lexical-binding: nil; -*-
;; Copyright (C) 2012-2023 Free Software Foundation, Inc.
;;
;; This file is part of GNU eev.
;;
;; GNU eev 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.
;;
;; GNU eev 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;
;; Author: Eduardo Ochs <[email protected]>
;; Maintainer: Eduardo Ochs <[email protected]>
;; Version: 20231221
;; Keywords: e-scripts
;;
;; Latest version: <http://anggtwu.net/eev-current/eev-multiwindow.el>
;; htmlized: <http://anggtwu.net/eev-current/eev-multiwindow.el.html>
;; See also: <http://anggtwu.net/eev-current/eev-beginner.el.html>
;; <http://anggtwu.net/eev-intros/find-eev-intro.html>
;; (find-eev-intro)
;;; Commentary:
;;
;; For the main ideas, see: (find-multiwindow-intro)
;;; __ _ _ _
;;; / _(_)_ __ __| | __ _____ ___| |_
;;; | |_| | '_ \ / _` |____\ \ /\ / / __|/ _ \ __|
;;; | _| | | | | (_| |_____\ V V /\__ \ __/ |_
;;; |_| |_|_| |_|\__,_| \_/\_/ |___/\___|\__|
;;;
;; These functions are explained here:
;; (find-multiwindow-intro "1. Introduction")
;; (find-multiwindow-intro "2. `find-wset'")
;; (find-multiwindow-intro "8. Adding support for new characters in `find-wset'")
(defun find-wset-1 () (delete-other-windows))
(defun find-wset-2 () (split-window-vertically))
(defun find-wset-3 () (split-window-horizontally))
(defun find-wset-s () (split-window-sensibly (selected-window)))
(defun find-wset-o () (other-window 1))
(defun find-wset-O () (other-window -1))
(defun find-wset-+ () (balance-windows))
(defun find-wset-c () (recenter))
(defun find-wset-_ () (eval (car sexps)) (setq sexps (cdr sexps)))
(defun find-wset-\ ()) ; allow whitespace
(defun find-wset (chars &rest sexps)
"Create a multi-window setting according to CHARS and SEXPS.
A detailed explanation is here: (find-multiwindow-intro)
Here is a list of the standard characters that can be used in CHARS:
1: `delete-other-windows' (C-x C-1)
2: `split-window-vertically' (C-x C-2)
3: `split-window-horizontally' (C-x C-3)
s: `split-window-sensibly'
o: `other-window' (C-x o)
+: `balance-windows' (C-x +)
c: `recenter' (C-l)
_: execute the next sexp in SEXPS.
To add support for a new character, say `C', just define
a function `find-wset-C'."
(if (not (equal chars ""))
(let ((c (substring chars 0 1))
(chars (substring chars 1)))
(funcall (ee-intern "find-wset-%s" c))
(apply 'find-wset chars sexps))))
;; High-level functions.
;; See: (find-multiwindow-intro "3. High-level words")
;;
(defun find-2a (a b) (find-wset "13_o_o" a b))
(defun find-2b (a b) (find-wset "13_o_" a b))
(defun find-3a (a b c) (find-wset "13_o2_o_o" a b c))
(defun find-3b (a b c) (find-wset "13_o2_o_oo" a b c))
(defun find-3c (a b c) (find-wset "13_o2_o_" a b c))
;;; _ _ _ _ _
;;; ___ ___ _ __ (_) |_ ___| |__ | |__ __ _ ___| | _____
;;; / _ \/ _ \ '_ \| | __/ __| '_ \ | '_ \ / _` |/ __| |/ / __|
;;; | __/ __/ |_) | | || (__| | | | | | | | (_| | (__| <\__ \
;;; \___|\___| .__/|_|\__\___|_| |_| |_| |_|\__,_|\___|_|\_\___/
;;; |_|
;; See:
;; (find-multiwindow-intro "4. Several eepitch targets")
;; (find-multiwindow-intro "5. Restarting eepitch targets")
;; (find-multiwindow-intro "7. Eepitch blocks for two targets")
(defun ee-here (code)
"Example: (ee-here '(eepitch-xxx)) opens the target of (eepitch-xxx) here.
\"Here\" means \"in the current window, without disturbing the
current window configuration\". Normal calls to `eepitch-xxx'
functions split the screen and open the target buffer in another
window; by wrapping them in an `(ee-here ...)' we can bypass
that. This is mainly for `find-wset'."
(let (result)
(find-ebuffer
(save-window-excursion
(setq result (eval code))
eepitch-buffer-name))
result))
(defun ee-here-reset (code)
"Like `ee-here', but also does an `eepitch-kill'."
(let (result)
(find-ebuffer
(save-window-excursion
(eval code)
(eepitch-kill)
(setq result (eval code))
eepitch-buffer-name))
result))
;; Mnemonic: "e" and "E" are both for preparing eepitch windows,
;; and "E" is more aggressive than "e" (it yells at you).
(defun find-wset-e () (ee-here (car sexps)) (setq sexps (cdr sexps)))
(defun find-wset-E () (ee-here-reset (car sexps)) (setq sexps (cdr sexps)))
(defun find-3ee (b c) (find-wset "13o2eoeo" b c))
(defun find-3EE (b c) (find-wset "13o2EoEo" b c))
(defun find-4eee (b c d) (find-wset "13o2eo2+eoeo" b c d))
(defun find-4EEE (b c d) (find-wset "13o2Eo2+EoEo" b c d))
;; When I invented this I used "=" and "!" instead of "e" and "E" -
;; but I think that "e" and "E" are better.
(defun find-wset-= () (ee-here (car sexps)) (setq sexps (cdr sexps)))
(defun find-wset-! () (ee-here-reset (car sexps)) (setq sexps (cdr sexps)))
;; Support for frames.
;; Inspired by this discussion:
;; https://lists.gnu.org/archive/html/eev/2021-11/index.html
;;
(defun ee-first-frame-with-title (title)
"Return the first frame with title TITLE or nil if none exists."
(let ((frameswiththattitle
(cl-loop for frame in (frame-list)
if (equal title (frame-parameter frame 'title))
collect frame)))
(car frameswiththattitle)))
(defun ee-select-frame (title)
"Like `select-frame-set-input-focus', but on a frame with title TITLE.
Use the first frame with that title if several exist. If there isn't a
frame with that title, create one."
(let ((frame (ee-first-frame-with-title title)))
(if frame
(select-frame-set-input-focus frame)
(let ((newframe (make-frame `((title . ,title)))))
(select-frame-set-input-focus newframe)))))
(defun find-wset-F () (ee-select-frame (car sexps)) (setq sexps (cdr sexps)))
(provide 'eev-multiwindow)
;; Local Variables:
;; coding: utf-8-unix
;; no-byte-compile: t
;; End: