-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsplash-screen.el
210 lines (182 loc) · 8.72 KB
/
splash-screen.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
;;; splash-screen.el --- An alternative splash screen -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Nicolas .P Rougier
;; Author: Nicolas P. Rougier <nicolas.rougier@inria.fr>
;; URL: https://github.com/rougier/emacs-splash
;; Keywords: startup
;; Version: 0.1
;; Package-Requires:
;; 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:
;;
;; An alternative splash screen:
;;
;; +–—————————––––––––––––––––––––––––––––————————————————————+
;; | |
;; | |
;; | |
;; | |
;; | |
;; | |
;; | www.gnu.org |
;; | GNU Emacs version XX.Y |
;; | a free/libre editor |
;; | |
;; | |
;; | |
;; | |
;; | |
;; | GNU Emacs comes with ABSOLUTELY NO WARRANTY |
;; | Copyright (C) 2020 Free Software Foundation, Inc. |
;; | |
;; +––––––––––––––––––––––––––––––––––––––————————————————————+
;;
;; Features:
;;
;; - No logo, no moddeline, no scrollbars
;; - "q" or <esc> kills the splash screen
;; - Any other key open the about-emacs buffer
;; - With emacs-mac (Mituharu), splash screen is faded out after 3 seconds
;;
;; Note: The screen is not shown if there are opened file buffers. For
;; example, if you start emacs with a filename on the command
;; line, the splash is not shown.
;;
;; Usage:
;;
;; (require 'splash-screen)
;;
;;; Code:
(require 'cl-lib)
(defun splash-screen ()
"Emacs splash screen"
(interactive)
(let* ((splash-buffer (get-buffer-create "*splash*"))
(recover-session (and auto-save-list-file-prefix
(file-directory-p (file-name-directory
auto-save-list-file-prefix))))
(height (- (window-body-height nil) 1))
(width (window-body-width nil))
(padding-center (- (/ height 2) 1))
(padding-bottom (- height (/ height 2) 3)))
;; If there are buffer associated with filenames,
;; we don't show splash screen.
(if (eq 0 (length (cl-loop for buf in (buffer-list)
if (buffer-file-name buf)
collect (buffer-file-name buf))))
(with-current-buffer splash-buffer
(erase-buffer)
;; Buffer local settings
(if (one-window-p)
(setq mode-line-format nil))
(setq cursor-type nil)
(setq vertical-scroll-bar nil)
(setq horizontal-scroll-bar nil)
(setq fill-column width)
(face-remap-add-relative 'link :underline nil)
;; Vertical padding to center
(insert-char ?\n padding-center)
;; Central text
(insert-text-button " www.gnu.org "
'action (lambda (_) (browse-url "https://www.gnu.org"))
'help-echo "Visit www.gnu.org website"
'follow-link t)
(center-line) (insert "\n")
(insert (concat
(propertize "GNU Emacs" 'face 'bold)
" " "version "
(format "%d.%d" emacs-major-version emacs-minor-version)))
(center-line) (insert "\n")
(insert (propertize "A free/libre editor" 'face 'shadow))
(center-line)
;; Vertical padding to bottom
(insert-char ?\n padding-bottom)
;; Recover session button
(when recover-session
(delete-char -2)
(insert-text-button " [Recover session] "
'action (lambda (_) (call-interactively 'recover-session))
'help-echo "Recover previous session"
'face 'warning
'follow-link t)
(center-line) (insert "\n") (insert "\n"))
;; Copyright text
(insert (propertize
"GNU Emacs comes with ABSOLUTELY NO WARRANTY" 'face 'shadow))
(center-line) (insert "\n")
(insert (propertize
"Copyright (C) 2020 Free Software Foundation, Inc." 'face 'shadow))
(center-line) (insert "\n")
(goto-char 0)
(read-only-mode t)
(local-set-key [t] 'splash-screen-fade-to-about)
(local-set-key (kbd "C-[") 'splash-screen-fade-to-default)
(local-set-key (kbd "<escape>") 'splash-screen-fade-to-default)
(local-set-key (kbd "q") 'splash-screen-fade-to-default)
(local-set-key (kbd "<mouse-1>") 'mouse-set-point)
(local-set-key (kbd "<mouse-2>") 'operate-this-button)
;; (local-set-key " " 'splash-screen-fade-to-default)
;; (local-set-key "x" 'splash-screen-fade-to-default)
;; (local-set-key (kbd "<RET>") 'splash-screen-fade-to-default)
;; (local-set-key (kbd "<return>") 'splash-screen-fade-to-default)
(display-buffer-same-window splash-buffer nil)
(run-with-idle-timer 10.0 nil 'splash-screen-fade-to-about)))))
;; Mac animation, only available from
;; https://bitbucket.org/mituharu/emacs-mac/src/master/
;; https://github.com/railwaycat/homebrew-emacsmacport
(defvar mac-animation-locked-p nil)
(defun mac-animation-toggle-lock ()
(setq mac-animation-locked-p (not mac-animation-locked-p)))
(defun mac-animation-fade-out (duration &rest args)
(unless mac-animation-locked-p
(mac-animation-toggle-lock)
(mac-start-animation nil :type 'fade-out :duration duration)
(run-with-timer duration nil 'mac-animation-toggle-lock)))
(defun splash-screen-fade-to (about duration)
"Fade out current frame for duration and goes to command-or-bufffer"
(interactive)
(defalias 'mac-animation-fade-out-local
(apply-partially 'mac-animation-fade-out duration))
(if (get-buffer "*splash*")
(progn (if (and (display-graphic-p) (fboundp 'mac-start-animation))
(advice-add 'set-window-buffer
:before 'mac-animation-fade-out-local))
(if about (about-emacs))
(kill-buffer "*splash*")
(if (and (display-graphic-p) (fboundp 'mac-start-animation))
(advice-remove 'set-window-buffer
'mac-animation-fade-out-local)))))
(defun splash-screen-fade-to-about ()
(interactive) (splash-screen-fade-to 1 1.0))
(defun splash-screen-fade-to-default ()
(interactive) (splash-screen-fade-to nil 0.25))
(defun splash-screen-kill ()
"Kill the splash screen buffer (immediately)."
(interactive)
(if (get-buffer "*splash*")
(kill-buffer "*splash*")))
;; Suppress any startup message in the echo area
(run-with-idle-timer 0.05 nil (lambda() (message nil)))
;; Install hook after frame parameters have been applied and only if
;; no option on the command line
(if (and (not (member "-no-splash" command-line-args))
(not (member "--file" command-line-args))
(not (member "--insert" command-line-args))
(not (member "--find-file" command-line-args))
(not inhibit-startup-screen)
)
(progn
(add-hook 'window-setup-hook 'splash-screen)
(setq inhibit-startup-screen t
inhibit-startup-message t
inhibit-startup-echo-area-message t)))
(provide 'splash-screen)
;;; splash-screen.el ends here