summaryrefslogtreecommitdiff
path: root/scratch-splash.el
blob: ffa4323e7a07786d0cdca798295a73d74cc7f4d5 (plain)
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
;; ---------------------------------------------------------------------
;; Copyright (C) 2020 - Nicolas .P Rougier 
;; Copyright (C) 2020 - N Λ N O developers 
;;
;; 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/>.
;; ---------------------------------------------------------------------
;;
;; 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 screen is not shown.
;;
;; This is based on some combination of:
;; - https://github.com/rougier/nano-emacs
;; - https://github.com/rougier/emacs-splash
(require 'cl-lib)

(defun scratch-splash ()
  "Emacs splash screen"
  
  (interactive)
  
  (let* ((splash-buffer  (get-buffer-create "*splash*"))
         (height         (round (- (window-body-height nil) 1) ))
         (width          (round (window-body-width nil)        ))
         (padding-center (- (/ height 2) 1)))
    
    ;; If there are buffer associated with filenames,
    ;; we don't show the 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)
          
          (setq-local line-spacing 0)
          (setq-local vertical-scroll-bar nil)
          (setq-local horizontal-scroll-bar nil)
          (setq-local fill-column width)
          (face-remap-add-relative 'link :underline nil)

          (insert-char ?\n padding-center)

          (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)

          (read-only-mode t)
          (display-buffer-same-window splash-buffer nil)
	  )
      )))

(provide 'scratch-splash)