2015-01-27 03:51:47 +00:00
|
|
|
;;; core-spacemacs-buffer.el --- Spacemacs Core File
|
2015-01-26 03:36:07 +00:00
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
2015-02-04 04:56:52 +00:00
|
|
|
(defconst spacemacs-buffer-name "*spacemacs*"
|
|
|
|
"The name of the spacemacs buffer.")
|
|
|
|
|
2015-03-13 03:55:38 +00:00
|
|
|
(defconst spacemacs--banner-length 75
|
|
|
|
"Width of a banner.")
|
2015-01-26 03:36:07 +00:00
|
|
|
|
2015-03-13 03:55:38 +00:00
|
|
|
(defun spacemacs//insert-banner-and-buttons ()
|
|
|
|
"Choose a banner accordingly to `dotspacemacs-startup-banner'and insert it
|
|
|
|
in spacemacs buffer along whith quick buttons underneath.
|
|
|
|
|
|
|
|
Easter egg:
|
|
|
|
Doge special text banner can be reachable via `999', `doge' or `random*'.
|
2015-01-26 03:36:07 +00:00
|
|
|
`random' ignore special banners whereas `random*' does not."
|
2015-03-09 02:09:09 +00:00
|
|
|
(let ((banner (spacemacs//choose-banner))
|
2015-01-26 03:36:07 +00:00
|
|
|
(buffer-read-only nil))
|
|
|
|
(when banner
|
|
|
|
(spacemacs/message (format "Banner: %s" banner))
|
2015-03-08 15:57:32 +00:00
|
|
|
(if (string-match "\\.png\\'" banner)
|
2015-03-13 03:55:38 +00:00
|
|
|
(spacemacs//insert-image-banner banner)
|
|
|
|
(insert-file-contents banner))
|
|
|
|
(spacemacs//inject-version)
|
|
|
|
(spacemacs/insert-buttons)
|
|
|
|
(spacemacs//redisplay))))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
2015-03-09 02:09:09 +00:00
|
|
|
(defun spacemacs//choose-banner ()
|
|
|
|
"Return the full path of a banner based on the dotfile value."
|
|
|
|
(cond
|
2015-03-13 03:55:38 +00:00
|
|
|
((eq 'official dotspacemacs-startup-banner)
|
|
|
|
(if (and (display-graphic-p) (image-type-available-p 'png))
|
|
|
|
spacemacs-banner-official-png
|
|
|
|
(spacemacs//get-banner-path 1)))
|
2015-03-09 02:09:09 +00:00
|
|
|
((eq 'random dotspacemacs-startup-banner)
|
|
|
|
(spacemacs//choose-random-text-banner))
|
|
|
|
((eq 'random* dotspacemacs-startup-banner)
|
|
|
|
(spacemacs//choose-random-text-banner t))
|
|
|
|
((eq 'doge dotspacemacs-startup-banner)
|
|
|
|
(spacemacs//get-banner-path 999))
|
|
|
|
((integerp dotspacemacs-startup-banner)
|
|
|
|
(spacemacs//get-banner-path dotspacemacs-startup-banner))
|
2015-03-13 03:55:38 +00:00
|
|
|
((and dotspacemacs-startup-banner
|
|
|
|
(string-match "\\.png\\'" dotspacemacs-startup-banner))
|
|
|
|
(if (and (display-graphic-p) (image-type-available-p 'png))
|
2015-03-09 02:09:09 +00:00
|
|
|
(if (file-exists-p dotspacemacs-startup-banner)
|
|
|
|
dotspacemacs-startup-banner
|
|
|
|
(spacemacs/message (format "Warning: could not find banner %s"
|
|
|
|
dotspacemacs-startup-banner))
|
|
|
|
(spacemacs//get-banner-path 1))
|
|
|
|
(spacemacs//get-banner-path 1)))))
|
|
|
|
|
|
|
|
(defun spacemacs//choose-random-text-banner (&optional all)
|
2015-01-26 03:36:07 +00:00
|
|
|
"Return the full path of a banner chosen randomly.
|
|
|
|
|
|
|
|
If ALL is non-nil then truly all banners can be selected."
|
|
|
|
(let* ((files (directory-files spacemacs-banner-directory t))
|
|
|
|
(count (length files))
|
|
|
|
;; -2 then +2 to remove `.' and `..'
|
|
|
|
(choice (+ 2 (random (- count (if all 2 3))))))
|
|
|
|
(nth choice files)))
|
|
|
|
|
|
|
|
(defun spacemacs//get-banner-path (index)
|
|
|
|
"Return the full path to banner with index INDEX."
|
|
|
|
(concat spacemacs-banner-directory (format "%03d-banner.txt" index)))
|
|
|
|
|
2015-03-13 03:55:38 +00:00
|
|
|
(defun spacemacs//insert-image-banner (banner)
|
|
|
|
"Display an image banner."
|
|
|
|
(when (file-exists-p banner)
|
|
|
|
(let* ((spec (create-image banner))
|
|
|
|
(size (image-size spec))
|
|
|
|
(width (car size))
|
|
|
|
(left-margin (floor (- spacemacs--banner-length width) 2)))
|
|
|
|
(beginning-of-buffer)
|
|
|
|
(insert "\n")
|
|
|
|
(insert (make-string (- left-margin 1) ?\ ))
|
|
|
|
(insert-image spec)
|
|
|
|
(insert "\n\n")
|
|
|
|
(insert " [S P A C E M A C S]\n\n"))))
|
|
|
|
|
|
|
|
(defun spacemacs//inject-version ()
|
2015-01-26 03:36:07 +00:00
|
|
|
"Inject the current version of spacemacs in the first line of the
|
|
|
|
buffer, right justified."
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-buffer)
|
2015-03-13 03:55:38 +00:00
|
|
|
(let* ((maxcol spacemacs--banner-length)
|
2015-01-26 03:36:07 +00:00
|
|
|
(injected (format "(%s)" spacemacs-version))
|
|
|
|
(pos (- maxcol (length injected)))
|
|
|
|
(buffer-read-only nil))
|
|
|
|
;; fill the first line with spaces if required
|
|
|
|
(when (< (line-end-position) maxcol)
|
|
|
|
(end-of-line)
|
|
|
|
(insert-char ?\s (- maxcol (line-end-position))))
|
|
|
|
(goto-char pos)
|
|
|
|
(delete-char (length injected))
|
|
|
|
(insert injected))))
|
|
|
|
|
2015-03-16 05:28:21 +00:00
|
|
|
(defun spacemacs/set-mode-line (format)
|
|
|
|
"Set mode-line format for spacemacs buffer."
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
(setq mode-line-format format)))
|
|
|
|
|
2015-01-26 03:36:07 +00:00
|
|
|
(defun spacemacs/message (msg &rest args)
|
|
|
|
"Display MSG in message prepended with '(Spacemacs)'."
|
|
|
|
(message "(Spacemacs) %s" (apply 'format msg args)))
|
|
|
|
|
|
|
|
(defun spacemacs/append-to-buffer (msg &optional messagebuf)
|
|
|
|
"Append MSG to spacemacs buffer. If MESSAGEBUF is not nil then MSG is
|
|
|
|
also written in message buffer."
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(insert msg)
|
2015-03-12 04:25:52 +00:00
|
|
|
(if messagebuf (message "(Spacemacs) %s" msg)))
|
2015-03-16 05:28:21 +00:00
|
|
|
(spacemacs/set-mode-line "")))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
|
|
(defun spacemacs/replace-last-line-of-buffer (msg &optional messagebuf)
|
|
|
|
"Replace the last line of the spacemacs buffer with MSG. If MESSAGEBUF is
|
|
|
|
not nil then MSG is also written in message buffer."
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(let ((buffer-read-only nil))
|
|
|
|
(delete-region (line-beginning-position) (point-max))
|
|
|
|
(insert msg)
|
2015-03-12 04:25:52 +00:00
|
|
|
(if messagebuf (message "(Spacemacs) %s" msg)))
|
2015-03-16 05:28:21 +00:00
|
|
|
(spacemacs/set-mode-line "")))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
|
|
(defun spacemacs/loading-animation ()
|
2015-03-13 03:55:38 +00:00
|
|
|
"Display the progress bar by chunk of size `spacemacs--loading-dots-chunk-threshold'."
|
2015-02-16 02:25:12 +00:00
|
|
|
(when dotspacemacs-loading-progress-bar
|
|
|
|
(setq spacemacs-loading-counter (1+ spacemacs-loading-counter))
|
|
|
|
(when (>= spacemacs-loading-counter spacemacs-loading-dots-chunk-threshold)
|
|
|
|
(setq spacemacs-loading-counter 0)
|
2015-03-12 03:46:37 +00:00
|
|
|
(setq spacemacs-loading-string
|
|
|
|
(concat spacemacs-loading-string
|
|
|
|
(make-string spacemacs-loading-dots-chunk-size
|
|
|
|
spacemacs-loading-char)))
|
|
|
|
(setq mode-line-format spacemacs-loading-string)
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay))))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
|
|
(defun spacemacs/insert-buttons ()
|
|
|
|
(goto-char (point-max))
|
2015-02-04 04:56:52 +00:00
|
|
|
(insert " ")
|
|
|
|
(insert-button "[Homepage]" 'action
|
2015-01-26 03:36:07 +00:00
|
|
|
(lambda (b) (browse-url "https://github.com/syl20bnr/spacemacs"))
|
2015-03-02 00:53:45 +00:00
|
|
|
'follow-link t 'help-echo "Open the Spacemacs Github page in your browser.")
|
2015-01-26 03:36:07 +00:00
|
|
|
(insert " ")
|
2015-02-04 04:56:52 +00:00
|
|
|
(insert-button "[Documentation]" 'action
|
2015-01-26 03:36:07 +00:00
|
|
|
(lambda (b) (browse-url "https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.md"))
|
2015-03-02 00:53:45 +00:00
|
|
|
'follow-link t 'help-echo "Open the Spacemacs documentation in your browser.")
|
2015-01-26 03:36:07 +00:00
|
|
|
(insert " ")
|
2015-02-04 04:56:52 +00:00
|
|
|
(insert-button "[Gitter Chat]" 'action
|
2015-01-26 03:36:07 +00:00
|
|
|
(lambda (b) (browse-url "https://gitter.im/syl20bnr/spacemacs"))
|
2015-03-02 00:53:45 +00:00
|
|
|
'follow-link t 'help-echo "Ask questions and chat with fellow users in our chat room.")
|
2015-01-26 03:36:07 +00:00
|
|
|
(insert " ")
|
2015-02-04 04:56:52 +00:00
|
|
|
(insert-button "[Update]" 'action
|
2015-03-02 00:53:45 +00:00
|
|
|
(lambda (b) (configuration-layer/update-packages))
|
|
|
|
'follow-link t 'help-echo "Update all ELPA packages to the latest versions.")
|
2015-01-26 03:36:07 +00:00
|
|
|
(insert " ")
|
2015-02-04 04:56:52 +00:00
|
|
|
(insert-button "[Rollback]" 'action
|
2015-03-02 00:53:45 +00:00
|
|
|
(lambda (b) (call-interactively 'configuration-layer/rollback))
|
|
|
|
'follow-link t 'help-echo "Rollback ELPA package upgrades if something got borked.")
|
|
|
|
(insert "\n")
|
2015-03-13 03:55:38 +00:00
|
|
|
(let ((button-title "[Search in Spacemacs]"))
|
2015-03-02 00:53:45 +00:00
|
|
|
; Compute the correct number of spaces to center the button.
|
2015-03-13 03:55:38 +00:00
|
|
|
(dotimes (i (/ (- spacemacs--banner-length (string-width button-title) 1) 2)) (insert " "))
|
2015-03-02 00:53:45 +00:00
|
|
|
(insert-button button-title 'action
|
|
|
|
(lambda (b) (call-interactively 'helm-spacemacs)) 'follow-link t
|
|
|
|
'help-echo "Find Spacemacs package and layer configs using helm-spacemacs."))
|
2015-01-26 03:36:07 +00:00
|
|
|
(insert "\n\n")
|
|
|
|
)
|
|
|
|
|
2015-02-04 04:56:52 +00:00
|
|
|
(defun spacemacs/goto-link-line ()
|
|
|
|
"Move the point to the beginning of the link line."
|
|
|
|
(interactive)
|
2015-03-16 05:28:21 +00:00
|
|
|
(when (and dotspacemacs-startup-banner
|
|
|
|
(not configuration-layer-error-count))
|
2015-03-13 03:55:38 +00:00
|
|
|
(with-current-buffer spacemacs-buffer-name
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "Homepage")
|
|
|
|
(beginning-of-line))))
|
2015-02-04 04:56:52 +00:00
|
|
|
|
2015-01-27 03:51:47 +00:00
|
|
|
(provide 'core-spacemacs-buffer)
|