-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpel-frame-control.el
117 lines (101 loc) · 4.44 KB
/
pel-frame-control.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
;;; pel-frame-control.el --- PEL process frame support -*-lexical-binding: t-*-
;; Copyright (C) 2020, 2021, 2023 Pierre Rouleau
;; Author: Pierre Rouleau <[email protected]>
;; This file is part of the PEL package
;; 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 <http://www.gnu.org/licenses/>.
;; -----------------------------------------------------------------------------
;;; Commentary:
;;
;; Some functions only work in graphic mode, but the macOS Terminal.app based
;; operation is available via the macOS specific keystrokes. The following
;; functions detect the mode, and perform the operation in graphic mode, but
;; display a message in Terminal mode to remind how it can be performed with
;; macOS keystrokes.
;; TODO: Add support for other environments to pel-toggle-frame-fullscreen.
;; Currently it only supports macOS and two of the terminal applications
;; available on it.
;;; Code:
(require 'pel--base) ; use: pel-count-string
;; ; pel-system-is-macos-p
;; ; pel-emacs-is-graphic-p
;;-pel-autoload
(defun pel-toggle-frame-fullscreen ()
"Toggle frame fullscreen mode on/off in graphics mode.
In Terminal mode, issue error to show how to use the OS keystrokes
to toggle the fullscreen mode."
(interactive)
(if pel-emacs-is-graphic-p
(toggle-frame-fullscreen)
(if pel-system-is-macos-p
(let* ((terminal_name (pel-val-or-default
(getenv "TERM_PROGRAM") "this unknown terminal"))
(keys (cond ((string= terminal_name "Apple_Terminal")
"use 'Control-Command f'")
((string= terminal_name "iTerm.app")
"use 'Command RET'")
(t "consult the manual"))))
(error
"When using Emacs inside %s, %s to toggle fullscreen mode"
terminal_name keys))
(error "When using Emacs in Terminal mode, \
use your OS supported command to toggle fullscreen mode"))))
;;-pel-autoload
(defun pel-show-frame-count ()
"Display number of active Emacs frames in the mini-buffer."
(interactive)
(message "Emacs has %s, of which %s visible."
(pel-count-string
(length (frame-list))
"frame")
(pel-count-string
(if pel-emacs-is-graphic-p
(length (visible-frame-list))
1)
"is" "are")))
;;-pel-autoload
(defun pel-next-frame (arg)
"Make next frame visible.
The next frame is the one with the next larger frame number.
In text terminal mode: iterate through all frames.
In graphics mode:
- with no/nil argument (the default): iterate through visible frames,
- with ARG non nil: iterate through all frames (included iconified frames)."
(interactive "p")
;; use previous-frame as it's the command that opens the frame with the next
;; larger frame number...
(raise-frame (previous-frame
nil
(if (and pel-emacs-is-graphic-p arg)
0
'visible))))
;;-pel-autoload
(defun pel-previous-frame (arg)
"Make previous frame visible.
The previous frame is the one with the next smaller frame number.
In text terminal mode: iterate through all frames.
In graphics mode:
- with no/nil argument (the default): iterate through visible frames,
- with ARG non nil: iterate through all frames (included iconified frames)."
(interactive "p")
;; use next-frame as it's the command that opens the frame with the next
;; smaller frame number...
(raise-frame (next-frame
nil
(if (and pel-emacs-is-graphic-p arg)
0
'visible))))
;; -----------------------------------------------------------------------------
(provide 'pel-frame-control)
;;; pel-frame-control.el ends here