Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changelog in spacemacs buffer #1070

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Here's some demo content for the changelog.
2 changes: 2 additions & 0 deletions core/core-dotspacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ banner, `random' chooses a random text banner in `core/banners'
directory. A string value must be a path to a .PNG file.
If the value is nil then no banner is displayed.")

(defvar dotspacemacs-always-show-changelog t)

(defvar dotspacemacs-configuration-layers '()
"List of configuration layers to load. If it is the symbol `all' instead
of a list then all discovered layers will be installed.")
Expand Down
3 changes: 3 additions & 0 deletions core/core-load-paths.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
(defconst spacemacs-cache-directory
(expand-file-name (concat user-emacs-directory ".cache/"))
"Spacemacs storage area for persistent files.")
(defconst spacemacs-changelog-file
(expand-file-name (concat user-emacs-directory "CHANGELOG.md"))
"Spacemacs changelog")

(defconst user-home-directory
(expand-file-name "~/")
Expand Down
116 changes: 89 additions & 27 deletions core/core-spacemacs-buffer.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
(defconst spacemacs--banner-length 75
"Width of a banner.")

(defvar spacemacs--changelog-widgets ())

(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.
Expand All @@ -31,6 +33,8 @@ Doge special text banner can be reachable via `999', `doge' or `random*'.
(insert-file-contents banner))
(spacemacs//inject-version)
(spacemacs/insert-buttons)
(when (eq t dotspacemacs-always-show-changelog)
(spacemacs/toggle-changelog))
(spacemacs//redisplay))))

(defun spacemacs//choose-banner ()
Expand Down Expand Up @@ -103,6 +107,24 @@ buffer, right justified."
(delete-char (length injected))
(insert injected))))

(defun spacemacs//insert-changelog ()
(save-excursion
(beginning-of-buffer)
(search-forward "Spacemacs\]")
(next-line)
(let* ((file-contents (with-temp-buffer (insert-file-contents spacemacs-changelog-file) (buffer-string)))
(changelog-header "\nCHANGELOG"))
(setq spacemacs--changelog-widgets (cons (widget-create 'text changelog-header) spacemacs--changelog-widgets))
(setq spacemacs--changelog-widgets (cons (widget-create 'text (concat "\n" file-contents)) spacemacs--changelog-widgets)))))

(defun spacemacs/toggle-changelog ()
(if (eq spacemacs--changelog-widgets nil)
(spacemacs//insert-changelog)
(mapc (lambda (el)
(widget-delete el)
(setq spacemacs--changelog-widgets (remove el spacemacs--changelog-widgets)))
spacemacs--changelog-widgets)))

(defun spacemacs/set-mode-line (format)
"Set mode-line format for spacemacs buffer."
(with-current-buffer (get-buffer-create "*spacemacs*")
Expand Down Expand Up @@ -153,43 +175,78 @@ buffer, right justified."
(defun spacemacs/insert-buttons ()
(goto-char (point-max))
(insert " ")
(insert-button "[Homepage]" 'action
(lambda (b) (browse-url "https://github.com/syl20bnr/spacemacs"))
'follow-link t 'help-echo "Open the Spacemacs Github page in your browser.")
(widget-create 'url-link
:tag "Homepage"
:help-echo "Open the Spacemacs Github page in your browser."
:mouse-face 'highlight
:follow-link "\C-m"
"https://github.com/syl20bnr/spacemacs")
(insert " ")
(insert-button "[Documentation]" 'action
(lambda (b) (browse-url "https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.md"))
'follow-link t 'help-echo "Open the Spacemacs documentation in your browser.")
(widget-create 'url-link
:tag "Documentation"
: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")
(insert " ")
(insert-button "[Gitter Chat]" 'action
(lambda (b) (browse-url "https://gitter.im/syl20bnr/spacemacs"))
'follow-link t 'help-echo "Ask questions and chat with fellow users in our chat room.")
(widget-create 'url-link
:tag "Gitter Chat"
: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")
(insert " ")
(insert-button "[Update]" 'action
(lambda (b) (configuration-layer/update-packages))
'follow-link t 'help-echo "Update all ELPA packages to the latest versions.")
(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"
"Update")
(insert " ")
(insert-button "[Rollback]" 'action
(lambda (b) (call-interactively 'configuration-layer/rollback))
'follow-link t 'help-echo "Rollback ELPA package upgrades if something got borked.")
(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"
"Rollback")
(insert "\n")
(let ((button-title "[Search in Spacemacs]"))
(let ((button-title "[Toggle Changelog] [Search in Spacemacs]"))
; Compute the correct number of spaces to center the button.
(dotimes (i (/ (- spacemacs--banner-length (string-width button-title) 1) 2)) (insert " "))
(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."))
(widget-create 'push-button
:help-echo "Hide or show the Changelog"
:action (lambda (&rest ignore) (spacemacs/toggle-changelog))
:mouse-face 'highlight
:follow-link "\C-m"
"Toggle Changelog"))
(widget-insert " ")
(widget-create 'url-link
: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"
"Search in Spacemacs")
(insert "\n\n")
)

(defun spacemacs//insert-file-list (list-display-name list)
(defun spacemacs//insert-file-list (list-display-name list shortcut-char)
(when (car list)
(insert list-display-name)
(define-key spacemacs-mode-map shortcut-char `(lambda ()
(interactive)
(goto-char ,(point))
(next-line)
(back-to-indentation)))
(insert (concat " " (format "[%s] " shortcut-char) list-display-name))
(mapc (lambda (el)
(insert "\n ")
(insert-button el
'action `(lambda (b) (find-file-existing ,el))
'follow-link t))
(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)))
list)))

(defun spacemacs/insert-startupify-lists ()
Expand All @@ -204,15 +261,15 @@ buffer, right justified."
(cond
((eq el 'recents)
(recentf-mode)
(when (spacemacs//insert-file-list " Recent Files:" (recentf-elements 5))
(when (spacemacs//insert-file-list "Recent Files:" (recentf-elements 5) "r")
(insert list-separator)))
((eq el 'bookmarks)
(helm-mode)
(when (spacemacs//insert-file-list " Bookmarks:" (bookmark-all-names))
(when (spacemacs//insert-file-list "Bookmarks:" (bookmark-all-names) "b")
(insert list-separator)))
((eq el 'projects)
(projectile-mode)
(when (spacemacs//insert-file-list " Projects:" (projectile-relevant-known-projects))
(when (spacemacs//insert-file-list "Projects:" (projectile-relevant-known-projects) "p")
(insert list-separator))))) dotspacemacs-startup-lists))))

(defun spacemacs/goto-link-line ()
Expand All @@ -225,4 +282,9 @@ buffer, right justified."
(re-search-forward "Homepage")
(beginning-of-line))))

;;this feels like the wrong place to put these
(add-hook 'spacemacs-mode-hook (lambda ()
(local-set-key [tab] 'widget-forward)
(local-set-key [S-tab] 'widget-backward)))

(provide 'core-spacemacs-buffer)
2 changes: 2 additions & 0 deletions core/templates/.spacemacs.template
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ before layers configuration."
;; If the value is nil then no banner is displayed.
;; dotspacemacs-startup-banner 'official
dotspacemacs-startup-banner 'official
;; t if you always want to see the changelog at startup
dotspacemacs-always-show-changelog t
;; List of items to show in the startup buffer. If nil it is disabled.
;; Possible values are: `recents' `bookmarks' `projects'."
dotspacemacs-startup-lists '(recents projects)
Expand Down