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-04-12 04:24:03 +00:00
|
|
|
|
(defconst spacemacs-buffer--banner-length 75
|
2015-03-13 03:55:38 +00:00
|
|
|
|
"Width of a banner.")
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-13 06:17:48 +00:00
|
|
|
|
(defconst spacemacs-buffer--cache-file
|
|
|
|
|
(expand-file-name (concat spacemacs-cache-directory "spacemacs-buffer.el"))
|
|
|
|
|
"Cache file for various persistent data for the spacemacs startup buffer")
|
|
|
|
|
|
|
|
|
|
(defvar spacemacs-buffer--release-note-version nil
|
|
|
|
|
"If nil the release note is displayed. If non nil it contains
|
|
|
|
|
a version number, if the version number is lesser than the current
|
|
|
|
|
version the release note it displayed")
|
|
|
|
|
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(defvar spacemacs-buffer--note-widgets nil
|
2015-04-13 06:17:48 +00:00
|
|
|
|
"List of widgets used to display the release note.")
|
2015-04-04 14:33:04 +00:00
|
|
|
|
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(defvar spacemacs-buffer--previous-insert-type nil
|
|
|
|
|
"Previous type of note inserted.")
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/insert-banner-and-buttons ()
|
2015-03-13 03:55:38 +00:00
|
|
|
|
"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-04-12 04:24:03 +00:00
|
|
|
|
(let ((banner (spacemacs-buffer//choose-banner))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(buffer-read-only nil))
|
|
|
|
|
(when banner
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/message (format "Banner: %s" banner))
|
2015-05-23 02:32:15 +00:00
|
|
|
|
(if (image-type-available-p (intern (file-name-extension banner)))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//insert-image-banner banner)
|
2015-03-13 03:55:38 +00:00
|
|
|
|
(insert-file-contents banner))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//inject-version)
|
|
|
|
|
(spacemacs-buffer//insert-buttons)
|
2015-04-13 07:35:05 +00:00
|
|
|
|
(if (file-exists-p spacemacs-buffer--cache-file)
|
|
|
|
|
(load spacemacs-buffer--cache-file)
|
|
|
|
|
(unless (file-exists-p dotspacemacs-filepath)
|
|
|
|
|
;; fresh install of spacemacs, the release notes are not displayed
|
|
|
|
|
(setq spacemacs-buffer--release-note-version spacemacs-version)
|
|
|
|
|
(spacemacs/dump-vars-to-file
|
|
|
|
|
'(spacemacs-buffer--release-note-version) spacemacs-buffer--cache-file)))
|
2015-04-13 06:42:11 +00:00
|
|
|
|
;; if there is an installed dotfile we check the variable
|
|
|
|
|
;; spacemacs-buffer--release-note-version to decide whether
|
|
|
|
|
;; we show the release note
|
|
|
|
|
(when (and (file-exists-p dotspacemacs-filepath)
|
|
|
|
|
(or (not spacemacs-buffer--release-note-version)
|
|
|
|
|
(version< spacemacs-buffer--release-note-version
|
|
|
|
|
spacemacs-version)))
|
2015-06-03 01:36:45 +00:00
|
|
|
|
(spacemacs-buffer/toggle-note (concat spacemacs-release-notes-directory "0.103.txt")
|
2015-04-15 14:30:25 +00:00
|
|
|
|
'release-note))
|
2015-03-13 03:55:38 +00:00
|
|
|
|
(spacemacs//redisplay))))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//choose-banner ()
|
2015-03-09 02:09:09 +00:00
|
|
|
|
"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
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//get-banner-path 1)))
|
2015-03-09 02:09:09 +00:00
|
|
|
|
((eq 'random dotspacemacs-startup-banner)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//choose-random-text-banner))
|
2015-03-09 02:09:09 +00:00
|
|
|
|
((eq 'random* dotspacemacs-startup-banner)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//choose-random-text-banner t))
|
2015-03-09 02:09:09 +00:00
|
|
|
|
((eq 'doge dotspacemacs-startup-banner)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//get-banner-path 999))
|
2015-03-09 02:09:09 +00:00
|
|
|
|
((integerp dotspacemacs-startup-banner)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer//get-banner-path dotspacemacs-startup-banner))
|
2015-03-13 03:55:38 +00:00
|
|
|
|
((and dotspacemacs-startup-banner
|
2015-05-23 02:32:15 +00:00
|
|
|
|
(image-type-available-p (intern (file-name-extension
|
|
|
|
|
dotspacemacs-startup-banner))))
|
|
|
|
|
(if (file-exists-p dotspacemacs-startup-banner)
|
|
|
|
|
dotspacemacs-startup-banner
|
|
|
|
|
(spacemacs-buffer/warning (format "could not find banner %s"
|
|
|
|
|
dotspacemacs-startup-banner))
|
2015-06-01 16:12:05 +00:00
|
|
|
|
(spacemacs-buffer//get-banner-path 1))
|
|
|
|
|
(spacemacs-buffer//get-banner-path 1))))
|
2015-03-09 02:09:09 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//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)))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//get-banner-path (index)
|
2015-01-26 03:36:07 +00:00
|
|
|
|
"Return the full path to banner with index INDEX."
|
|
|
|
|
(concat spacemacs-banner-directory (format "%03d-banner.txt" index)))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//insert-image-banner (banner)
|
2015-03-13 03:55:38 +00:00
|
|
|
|
"Display an image banner."
|
|
|
|
|
(when (file-exists-p banner)
|
|
|
|
|
(let* ((spec (create-image banner))
|
|
|
|
|
(size (image-size spec))
|
|
|
|
|
(width (car size))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(left-margin (floor (- spacemacs-buffer--banner-length width) 2)))
|
2015-03-13 03:55:38 +00:00
|
|
|
|
(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"))))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//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-04-12 04:24:03 +00:00
|
|
|
|
(let* ((maxcol spacemacs-buffer--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-04-15 14:30:25 +00:00
|
|
|
|
(defun spacemacs-buffer//insert-note (file caption &optional additional-widgets)
|
|
|
|
|
"Insert the release note just under the banner.
|
|
|
|
|
|
|
|
|
|
FILE is the file that contains the content to show.
|
|
|
|
|
CAPTION is the title of the note.
|
|
|
|
|
TAG-STRING is the label of the button for additional action.
|
|
|
|
|
HELP-STRING is the help message of the button for additional action."
|
2015-04-04 14:33:04 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-buffer)
|
|
|
|
|
(search-forward "Spacemacs\]")
|
|
|
|
|
(next-line)
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(let* ((note (concat "\n" (spacemacs//render-framed-text file
|
|
|
|
|
spacemacs-buffer--banner-length
|
|
|
|
|
caption))))
|
|
|
|
|
(add-to-list 'spacemacs-buffer--note-widgets (widget-create 'text note))
|
|
|
|
|
(funcall additional-widgets))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer//insert-note-p (type)
|
|
|
|
|
"Decicde if whether to insert note widget or not based on current note TYPE.
|
|
|
|
|
|
|
|
|
|
If note TYPE is `quickhelp' or `release-note' and is equal to
|
|
|
|
|
previous insert type in `spacemacs-buffer--previous-insert-type',
|
|
|
|
|
which means previous note widget of the same type already
|
|
|
|
|
inserted. In this case, we simply delete the widgets but don't insert.
|
|
|
|
|
|
|
|
|
|
Otherwise, delete and allow insert note of TYPE."
|
|
|
|
|
(if (not (eq spacemacs-buffer--previous-insert-type type))
|
|
|
|
|
type
|
|
|
|
|
(setq spacemacs-buffer--previous-insert-type nil)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer/toggle-note (file type)
|
|
|
|
|
"Toggle the note in FILE for the buffer based on TYPE.
|
|
|
|
|
|
|
|
|
|
If TYPE is nil, just remove widgets."
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(interactive)
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(spacemacs-buffer//remove-existing-widget-if-exist)
|
|
|
|
|
(cond
|
|
|
|
|
((eq type 'quickhelp)
|
|
|
|
|
(spacemacs-buffer//insert-quickhelp-widget file))
|
|
|
|
|
((eq type 'release-note)
|
|
|
|
|
(spacemacs-buffer//insert-release-note-widget file))
|
2015-04-19 06:11:04 +00:00
|
|
|
|
(t)))
|
2015-04-15 14:30:25 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer//remove-existing-widget-if-exist ()
|
|
|
|
|
"Remove existing note widgets if exists."
|
|
|
|
|
(when spacemacs-buffer--note-widgets
|
|
|
|
|
(spacemacs-buffer//remove-note-widgets)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer//insert-quickhelp-widget (file)
|
|
|
|
|
"Insert quickhelp with content from FILE."
|
|
|
|
|
(spacemacs-buffer//remove-existing-widget-if-exist)
|
|
|
|
|
(let ((widget-func (lambda ()
|
|
|
|
|
(add-to-list 'spacemacs-buffer--note-widgets
|
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:tag (propertize "Evil Tutorial" 'face 'font-lock-keyword-face)
|
|
|
|
|
:help-echo "Teach you how to use Vim basics."
|
|
|
|
|
:action (lambda (&rest ignore) (call-interactively #'evil-tutor-start))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"))
|
2015-04-21 09:47:41 +00:00
|
|
|
|
(widget-insert " ")
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(add-to-list 'spacemacs-buffer--note-widgets
|
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:tag (propertize "Emacs Tutorial" 'face 'font-lock-keyword-face)
|
|
|
|
|
:help-echo "Teach you how to use Emacs basics."
|
|
|
|
|
:action (lambda (&rest ignore) (call-interactively #'help-with-tutorial))
|
|
|
|
|
:mouse-face 'highlight
|
2015-06-06 17:24:26 +00:00
|
|
|
|
:follow-link "\C-m"))
|
|
|
|
|
(widget-insert " ")
|
|
|
|
|
(add-to-list 'spacemacs-buffer--note-widgets
|
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:tag (propertize "Vim Migration Guide" 'face 'font-lock-keyword-face)
|
|
|
|
|
:help-echo "Documentation for former vim users."
|
|
|
|
|
:action (lambda (&rest ignore) (find-file (concat spacemacs-docs-directory "VIMUSERS.org")))
|
|
|
|
|
:mouse-face 'highlight
|
2015-04-15 14:30:25 +00:00
|
|
|
|
:follow-link "\C-m")))))
|
|
|
|
|
(spacemacs-buffer//insert-note file "Quick Help" widget-func))
|
|
|
|
|
(setq spacemacs-buffer--previous-insert-type 'quickhelp))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer//insert-release-note-widget (file)
|
|
|
|
|
"Insert release note with content from FILE."
|
|
|
|
|
(spacemacs-buffer//remove-existing-widget-if-exist)
|
|
|
|
|
(let ((widget-func (lambda ()
|
|
|
|
|
(add-to-list 'spacemacs-buffer--note-widgets
|
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:tag (propertize "Click here for full change log" 'face 'font-lock-warning-face)
|
|
|
|
|
:help-echo "Open the full change log."
|
|
|
|
|
:action (lambda (&rest ignore)
|
|
|
|
|
(funcall 'spacemacs/open-file
|
|
|
|
|
(concat user-emacs-directory "CHANGELOG.org")
|
2015-06-03 01:36:45 +00:00
|
|
|
|
"Release 0.103.x"))
|
2015-04-15 14:30:25 +00:00
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m")))))
|
|
|
|
|
(spacemacs-buffer//insert-note file
|
2015-06-03 01:36:45 +00:00
|
|
|
|
" Important Notes (Release 0.103.x) "
|
2015-04-15 14:30:25 +00:00
|
|
|
|
widget-func))
|
|
|
|
|
|
|
|
|
|
(setq spacemacs-buffer--release-note-version nil)
|
|
|
|
|
(spacemacs/dump-vars-to-file
|
|
|
|
|
'(spacemacs-buffer--release-note-version) spacemacs-buffer--cache-file)
|
|
|
|
|
(setq spacemacs-buffer--previous-insert-type 'release-note))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs-buffer//remove-note-widgets ()
|
|
|
|
|
(mapc 'widget-delete spacemacs-buffer--note-widgets)
|
|
|
|
|
(setq spacemacs-buffer--note-widgets nil)
|
|
|
|
|
(setq spacemacs-buffer--release-note-version spacemacs-version)
|
|
|
|
|
(spacemacs/dump-vars-to-file
|
|
|
|
|
'(spacemacs-buffer--release-note-version) spacemacs-buffer--cache-file))
|
2015-04-04 14:33:04 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/set-mode-line (format)
|
2015-03-16 05:28:21 +00:00
|
|
|
|
"Set mode-line format for spacemacs buffer."
|
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
|
(setq mode-line-format format)))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/message (msg &rest args)
|
2015-04-12 16:25:53 +00:00
|
|
|
|
"Display MSG in message prepended with '(Spacemacs)'.
|
|
|
|
|
The message is displayed only if `dotspacemacs-verbose-loading' is non nil."
|
2015-04-06 03:45:02 +00:00
|
|
|
|
(when dotspacemacs-verbose-loading
|
|
|
|
|
(message "(Spacemacs) %s" (apply 'format msg args))))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-12 16:25:53 +00:00
|
|
|
|
(defun spacemacs-buffer/warning (msg &rest args)
|
|
|
|
|
"Display MSG as a warning message but in buffer `*Messages*'.
|
|
|
|
|
The message is always displayed. "
|
|
|
|
|
(message "(Spacemacs) Warning: %s" (apply 'format msg args)))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/insert-page-break ()
|
2015-04-03 02:23:16 +00:00
|
|
|
|
"Insert a page break line in spacemacs buffer."
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/append "\n\n\n"))
|
2015-04-03 02:23:16 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/append (msg &optional messagebuf)
|
2015-01-26 03:36:07 +00:00
|
|
|
|
"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-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/set-mode-line "")))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/replace-last-line (msg &optional messagebuf)
|
2015-01-26 03:36:07 +00:00
|
|
|
|
"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-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/set-mode-line "")))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/insert-framed-text
|
2015-04-06 00:59:55 +00:00
|
|
|
|
(msg &optional caption hpadding)
|
|
|
|
|
"Insert MSG in spacemacs buffer within a frame of width FILL-COLUMN.
|
|
|
|
|
|
|
|
|
|
See `spacemacs//render-framed-text' for documentation of the other
|
|
|
|
|
parameters."
|
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
|
(let ((buffer-read-only nil))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(insert (spacemacs//render-framed-text msg spacemacs-buffer--banner-length
|
2015-04-06 00:59:55 +00:00
|
|
|
|
caption hpadding)))))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/insert-framed-text-from-file
|
2015-04-06 00:59:55 +00:00
|
|
|
|
(filepath &optional caption hpadding)
|
|
|
|
|
"Insert at point the content of FILENAME file in spacemacs buffer in a
|
|
|
|
|
frame.
|
|
|
|
|
|
|
|
|
|
If FILEPATH does not exists the function returns nil.
|
|
|
|
|
|
|
|
|
|
See `spacemacs//render-framed-text' for documentation of the other
|
|
|
|
|
parameters."
|
|
|
|
|
(when (file-exists-p filepath)
|
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
|
(let ((buffer-read-only nil))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(insert (spacemacs//render-framed-text filepath spacemacs-buffer--banner-length
|
2015-04-06 00:59:55 +00:00
|
|
|
|
caption hpadding))))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//render-framed-text (content &optional width caption hpadding)
|
|
|
|
|
"Return a formated string framed with plained lines of width FILL-COLUMN.
|
|
|
|
|
|
|
|
|
|
CONTENT can be a text or a filepath.
|
|
|
|
|
|
|
|
|
|
WIDTH set the `fill-column' variable.
|
|
|
|
|
|
|
|
|
|
If CAPTION is non nil string then it is included in at the top of the frame.
|
|
|
|
|
If CAPTION length is greater than FILL-COLUMN minus 5 the function returns
|
|
|
|
|
nil.
|
|
|
|
|
|
|
|
|
|
HPADDING is the horizontal spacing between the text and the frame.
|
|
|
|
|
The vertical spacing is always one line."
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(if (not (file-exists-p content))
|
|
|
|
|
(insert content)
|
|
|
|
|
(insert-file-contents content)
|
|
|
|
|
;; remove additional newline at eof
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(delete-char -1))
|
|
|
|
|
(let* ((hpadding (or hpadding 1))
|
|
|
|
|
(fill-column (if width
|
|
|
|
|
(- width hpadding)
|
|
|
|
|
fill-column))
|
|
|
|
|
(sentence-end-double-space nil)
|
|
|
|
|
(caption-len (length caption)))
|
2015-04-19 04:26:24 +00:00
|
|
|
|
(fill-region (point-min) (point-max) 'justify 'nosqueeze)
|
2015-04-06 00:59:55 +00:00
|
|
|
|
(concat
|
|
|
|
|
;; top
|
|
|
|
|
"╭─"
|
|
|
|
|
(if caption
|
|
|
|
|
(concat caption
|
|
|
|
|
(make-string (+ (- fill-column caption-len 1)
|
|
|
|
|
hpadding) ?─))
|
|
|
|
|
(make-string fill-column ?─))
|
|
|
|
|
(make-string hpadding ?─) "╮\n"
|
|
|
|
|
;; content
|
|
|
|
|
(spacemacs//render-framed-line "" hpadding)
|
|
|
|
|
(mapconcat (lambda (x)
|
|
|
|
|
(spacemacs//render-framed-line x hpadding))
|
|
|
|
|
(split-string (buffer-string) "\n" nil) "")
|
|
|
|
|
(spacemacs//render-framed-line "" hpadding)
|
|
|
|
|
;; bottom
|
|
|
|
|
"╰" (make-string hpadding ?─)
|
|
|
|
|
(make-string fill-column ?─)
|
2015-04-13 06:17:48 +00:00
|
|
|
|
(make-string hpadding ?─) "╯"))))
|
2015-04-06 00:59:55 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//render-framed-line (line hpadding)
|
|
|
|
|
"Return a formated LINE with borders of a frame on each side and
|
|
|
|
|
with width FILL-COLUMN.
|
|
|
|
|
|
|
|
|
|
If length of LINE is bigger than FILL-COLUMN it returns nil.
|
|
|
|
|
|
|
|
|
|
HPADDING is the horizontal spacing betwee the content line and the frame border."
|
|
|
|
|
(let* ((len (length line))
|
|
|
|
|
(fill (- fill-column len)))
|
|
|
|
|
(when (>= fill 0)
|
|
|
|
|
(concat "│" (make-string hpadding ?\s)
|
|
|
|
|
line (make-string fill ?\s)
|
|
|
|
|
(make-string hpadding ?\s) "│\n"))))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/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)))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/set-mode-line spacemacs-loading-string)
|
2015-02-16 02:25:12 +00:00
|
|
|
|
(spacemacs//redisplay))))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-20 20:01:11 +00:00
|
|
|
|
(defmacro spacemacs//insert--shortcut (shortcut-char search-label &optional no-next-line)
|
|
|
|
|
`(define-key spacemacs-mode-map ,shortcut-char (lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(unless (search-forward ,search-label (point-max) t)
|
|
|
|
|
(search-backward ,search-label (point-min) t))
|
|
|
|
|
,@(unless no-next-line
|
|
|
|
|
'((forward-line 1)))
|
|
|
|
|
(back-to-indentation))))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//insert-buttons ()
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(goto-char (point-max))
|
2015-04-19 06:11:04 +00:00
|
|
|
|
(insert " ")
|
2015-04-20 20:01:11 +00:00
|
|
|
|
(spacemacs//insert--shortcut "m" "[?]" t)
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(widget-create 'url-link
|
|
|
|
|
:tag (propertize "?" 'face 'font-lock-doc-face)
|
|
|
|
|
:help-echo "Open the quickhelp."
|
|
|
|
|
:action (lambda (&rest ignore)
|
2015-04-23 02:30:00 +00:00
|
|
|
|
(spacemacs-buffer/toggle-note (concat spacemacs-info-directory "quickhelp.txt")
|
2015-04-15 14:30:25 +00:00
|
|
|
|
;; if nil is returned, just delete the current note widgets
|
|
|
|
|
(spacemacs-buffer//insert-note-p 'quickhelp)))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
)
|
2015-04-19 06:11:04 +00:00
|
|
|
|
(insert " ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'url-link
|
2015-04-13 05:46:39 +00:00
|
|
|
|
:tag (propertize "Homepage" 'face 'font-lock-keyword-face)
|
2015-04-02 14:23:36 +00:00
|
|
|
|
:help-echo "Open the Spacemacs Github page in your browser."
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
"https://github.com/syl20bnr/spacemacs")
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(insert " ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'url-link
|
2015-04-13 05:46:39 +00:00
|
|
|
|
:tag (propertize "Documentation" 'face 'font-lock-keyword-face)
|
2015-04-02 14:23:36 +00:00
|
|
|
|
:help-echo "Open the Spacemacs documentation in your browser."
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
"https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.md")
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(insert " ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'url-link
|
2015-04-13 05:46:39 +00:00
|
|
|
|
:tag (propertize "Gitter Chat" 'face 'font-lock-keyword-face)
|
2015-04-02 14:23:36 +00:00
|
|
|
|
:help-echo "Ask questions and chat with fellow users in our chat room."
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
"https://gitter.im/syl20bnr/spacemacs")
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(insert " ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:help-echo "Update all ELPA packages to the latest versions."
|
|
|
|
|
:action (lambda (&rest ignore) (configuration-layer/update-packages))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
2015-04-13 05:46:39 +00:00
|
|
|
|
(propertize "Update" 'face 'font-lock-keyword-face))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
(insert " ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:help-echo "Rollback ELPA package upgrades if something got borked."
|
|
|
|
|
:action (lambda (&rest ignore) (call-interactively 'configuration-layer/rollback))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
2015-04-13 05:46:39 +00:00
|
|
|
|
(propertize "Rollback" 'face 'font-lock-keyword-face))
|
2015-03-02 00:53:45 +00:00
|
|
|
|
(insert "\n")
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(insert " ")
|
|
|
|
|
(widget-create 'push-button
|
2015-04-13 05:46:39 +00:00
|
|
|
|
:tag (propertize "Release Notes" 'face 'font-lock-preprocessor-face)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
:help-echo "Hide or show the Changelog"
|
2015-04-15 14:30:25 +00:00
|
|
|
|
:action (lambda (&rest ignore)
|
2015-06-03 01:36:45 +00:00
|
|
|
|
(spacemacs-buffer/toggle-note (concat spacemacs-release-notes-directory "0.103.txt")
|
2015-04-15 14:30:25 +00:00
|
|
|
|
;; if nil is returned, just delete the current note widgets
|
|
|
|
|
(spacemacs-buffer//insert-note-p 'release-note)))
|
2015-04-12 04:24:03 +00:00
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
)
|
|
|
|
|
(insert " ")
|
|
|
|
|
(widget-create 'url-link
|
2015-04-13 05:46:39 +00:00
|
|
|
|
:tag (propertize "Search in Spacemacs" 'face 'font-lock-function-name-face)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
:help-echo "Find Spacemacs package and layer configs using helm-spacemacs."
|
|
|
|
|
:action (lambda (&rest ignore) (call-interactively 'helm-spacemacs))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m")
|
2015-04-06 00:59:55 +00:00
|
|
|
|
(insert "\n\n"))
|
2015-01-26 03:36:07 +00:00
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer//insert-file-list (list-display-name list shortcut-char)
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(when (car list)
|
2015-04-20 20:01:11 +00:00
|
|
|
|
(spacemacs//insert--shortcut "r" "Recent Files:")
|
|
|
|
|
(spacemacs//insert--shortcut "p" "Projects:")
|
2015-04-13 14:18:19 +00:00
|
|
|
|
(insert list-display-name)
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(mapc (lambda (el)
|
|
|
|
|
(insert "\n ")
|
2015-04-02 14:23:36 +00:00
|
|
|
|
(widget-create 'push-button
|
|
|
|
|
:action `(lambda (&rest ignore) (find-file-existing ,el))
|
|
|
|
|
:mouse-face 'highlight
|
|
|
|
|
:follow-link "\C-m"
|
|
|
|
|
:button-prefix ""
|
|
|
|
|
:button-suffix ""
|
|
|
|
|
:format "%[%t%]"
|
|
|
|
|
(abbreviate-file-name el)))
|
2015-03-28 14:30:56 +00:00
|
|
|
|
list)))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/insert-startupify-lists ()
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(with-current-buffer (get-buffer-create "*spacemacs*")
|
|
|
|
|
(let ((buffer-read-only nil)
|
|
|
|
|
(list-separator "\n\n"))
|
|
|
|
|
(goto-char (point-max))
|
2015-04-02 04:32:38 +00:00
|
|
|
|
(page-break-lines-mode)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(spacemacs-buffer/insert-page-break)
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(mapc (lambda (el)
|
|
|
|
|
(cond
|
|
|
|
|
((eq el 'recents)
|
|
|
|
|
(recentf-mode)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(when (spacemacs-buffer//insert-file-list "Recent Files:" (recentf-elements 5) "r")
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(insert list-separator)))
|
|
|
|
|
((eq el 'bookmarks)
|
|
|
|
|
(helm-mode)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(when (spacemacs-buffer//insert-file-list "Bookmarks:" (bookmark-all-names) "b")
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(insert list-separator)))
|
|
|
|
|
((eq el 'projects)
|
|
|
|
|
(projectile-mode)
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(when (spacemacs-buffer//insert-file-list "Projects:" (projectile-relevant-known-projects) "p")
|
2015-03-28 14:30:56 +00:00
|
|
|
|
(insert list-separator))))) dotspacemacs-startup-lists))))
|
|
|
|
|
|
2015-04-12 04:24:03 +00:00
|
|
|
|
(defun spacemacs-buffer/goto-link-line ()
|
2015-02-04 04:56:52 +00:00
|
|
|
|
"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")
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(widget-forward 1))))
|
2015-02-04 04:56:52 +00:00
|
|
|
|
|
2015-04-02 14:23:36 +00:00
|
|
|
|
;;this feels like the wrong place to put these
|
|
|
|
|
(add-hook 'spacemacs-mode-hook (lambda ()
|
|
|
|
|
(local-set-key [tab] 'widget-forward)
|
2015-04-09 18:06:59 +00:00
|
|
|
|
(local-set-key [S-tab] 'widget-backward)
|
2015-04-11 00:28:37 +00:00
|
|
|
|
;; S-tab is backtab in terminal
|
2015-04-13 05:46:56 +00:00
|
|
|
|
(local-set-key [backtab] 'widget-backward)
|
|
|
|
|
(local-set-key [return] 'widget-button-press)
|
2015-04-15 14:30:25 +00:00
|
|
|
|
(local-set-key [down-mouse-1] 'widget-button-click)
|
2015-04-13 05:46:56 +00:00
|
|
|
|
))
|
2015-04-02 14:23:36 +00:00
|
|
|
|
|
2015-01-27 03:51:47 +00:00
|
|
|
|
(provide 'core-spacemacs-buffer)
|