spacemacs-buffer: Added optional feature to show file icons (#15332)

Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
This commit is contained in:
Lucius Hu 2022-02-15 01:52:00 -05:00 committed by GitHub
parent f2afab0c32
commit b7e1dee13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 291 additions and 258 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 552 B

View File

@ -216,6 +216,12 @@ Spacemacs buffer."
'boolean
'spacemacs-dotspacemacs-init)
(spacemacs|defc dotspacemacs-startup-buffer-show-icons t
"If true, show file icons for entries and headings on spacmeacs buffer.
This has no effect in terminal or if \"all-the-icons\" is not installed."
'boolean
'spacemacs-dotspacemacs-init)
(spacemacs|defc dotspacemacs-scratch-mode 'text-mode
"Default major mode of the scratch buffer."
'symbol

View File

@ -60,10 +60,6 @@
(concat spacemacs-banner-directory "img/spacemacs-badge.png")
"Spacemacs official badge image.")
(defconst spacemacs-purple-heart-png
(concat spacemacs-banner-directory "img/heart.png")
"Purple heart emoji.")
(defconst spacemacs-gplv3-official-png
(concat spacemacs-banner-directory "img/gplv3.png")
"GPLv3 official badge image.")

View File

@ -74,6 +74,30 @@ Internal use, do not set this variable.")
(defvar spacemacs-buffer-mode-map (make-sparse-keymap)
"Keymap for spacemacs buffer mode.")
(defvar spacemacs-buffer--random-banner nil
"The random banner chosen.")
(defvar spacemacs-buffer-note-preview-lines 5
"If it's a positive integer, show the notes first number of lines.
If nil, show the full note.")
(defvar spacemacs-buffer--note-preview-nr-of-removed-lines nil
"Store the number of removed lines from the notes:
Quick Help and Release Notes.")
(defvar spacemacs-buffer--errors nil
"List of errors during startup.")
(defvar spacemacs-buffer--idle-numbers-timer nil
"This stores the idle numbers timer.")
(defvar spacemacs-buffer--startup-list-number nil
"This accumulates the numbers that are typed in the home buffer.
It's cleared when the idle timer runs.")
(defvar spacemacs-buffer--last-width nil
"Previous width of spacemacs-buffer.")
(defun spacemacs-buffer/key-bindings ()
(let ((map spacemacs-buffer-mode-map))
(when dotspacemacs-show-startup-list-numbers
@ -129,8 +153,8 @@ FILE: the path to the file containing the banner."
(let ((banner-width 0))
(while (not (eobp))
(let ((line-length (- (line-end-position) (line-beginning-position))))
(if (< banner-width line-length)
(setq banner-width line-length)))
(when (< banner-width line-length)
(setq banner-width line-length)))
(forward-line 1))
(goto-char 0)
(let ((margin (max 0 (floor (/ (- spacemacs-buffer--window-width
@ -152,14 +176,13 @@ Cate special text banner can de reachable via `998', `cat' or `random*'.
`random' ignore special banners whereas `random*' does not."
(let ((banner (spacemacs-buffer//choose-banner))
(buffer-read-only nil))
(progn
(when banner
(spacemacs-buffer/message (format "Banner: %s" banner))
(if (image-type-available-p (intern (file-name-extension banner)))
(spacemacs-buffer//insert-image-banner banner)
(spacemacs-buffer//insert-ascii-banner-centered banner)))
(spacemacs-buffer//insert-buttons)
(spacemacs//redisplay))))
(when banner
(spacemacs-buffer/message (format "Banner: %s" banner))
(if (image-type-available-p (intern (file-name-extension banner)))
(spacemacs-buffer//insert-image-banner banner)
(spacemacs-buffer//insert-ascii-banner-centered banner)))
(spacemacs-buffer//insert-buttons)
(spacemacs//redisplay)))
(defun spacemacs-buffer/display-startup-note ()
"Decide of the startup note and display it if relevant."
@ -210,19 +233,15 @@ Cate special text banner can de reachable via `998', `cat' or `random*'.
(spacemacs-buffer//get-banner-path 1)))
(t (spacemacs-buffer//get-banner-path 1)))))
(defvar spacemacs-buffer--random-banner nil
"The random banner chosen.")
(defun spacemacs-buffer//choose-random-text-banner (&optional all)
"Return the full path of a banner chosen randomly.
If ALL is non-nil then truly all banners can be selected."
(setq spacemacs-buffer--random-banner
(or spacemacs-buffer--random-banner
(let* ((files (directory-files spacemacs-banner-directory t ".*\.txt"))
(count (length files))
;; -2 to remove the two last ones (easter eggs)
(choice (random (- count (if all 0 2)))))
(nth choice files)))))
(unless spacemacs-buffer--random-banner
(let* ((files (directory-files spacemacs-banner-directory t ".*\.txt"))
(count (length files))
;; -2 to remove the two last ones (easter eggs)
(choice (random (- count (if all 0 2)))))
(setq spacemacs-buffer--random-banner (nth choice files)))))
(defun spacemacs-buffer//get-banner-path (index)
"Return the full path to banner with index INDEX."
@ -270,14 +289,14 @@ Right justified, based on the Spacemacs buffers window width."
(intern (file-name-extension badge-path))))
(create-image badge-path)))
(badge-size (when badge (car (image-size badge))))
(heart-path spacemacs-purple-heart-png)
(heart (when (and (display-graphic-p)
(image-type-available-p
(intern (file-name-extension badge-path))))
(create-image heart-path)))
(heart-size (when heart (car (image-size heart))))
(build-lhs "Made with ")
(build-rhs " by the community")
(build-by (concat "Made with "
(if (and dotspacemacs-startup-buffer-show-icons
(display-graphic-p)
(or (fboundp 'all-the-icons-faicon)
(require 'all-the-icons nil 'noerror)))
(all-the-icons-faicon "heart" :height 0.8 :v-adjust -0.05)
"heart")
" by the community"))
(proudly-free "Proudly free software")
(gplv3-path spacemacs-gplv3-official-png)
(gplv3 (when (and (display-graphic-p)
@ -286,35 +305,28 @@ Right justified, based on the Spacemacs buffers window width."
(create-image gplv3-path)))
(gplv3-size (when gplv3 (car (image-size gplv3))))
(buffer-read-only nil))
(when (or badge heart gplv3)
(goto-char (point-max))
(spacemacs-buffer/insert-page-break)
(insert "\n")
(when badge
(insert-image badge)
(spacemacs-buffer//center-line badge-size))
(when heart
(when badge (insert "\n\n"))
(insert build-lhs)
(insert-image heart)
(insert build-rhs)
(spacemacs-buffer//center-line (+ (length build-lhs)
heart-size
(length build-rhs)))
(insert "\n"))
(when gplv3
(insert "\n")
(widget-create 'url-link
:tag proudly-free
:help-echo "What is free software?"
:mouse-face 'highlight
:follow-link "\C-m"
"https://www.gnu.org/philosophy/free-sw.en.html")
(spacemacs-buffer//center-line (+ 2 (length proudly-free)))
(insert "\n\n")
(insert-image gplv3)
(spacemacs-buffer//center-line gplv3-size)
(insert "\n"))))))
(goto-char (point-max))
(spacemacs-buffer/insert-page-break)
(insert "\n")
(when badge
(insert-image badge)
(spacemacs-buffer//center-line badge-size)
(insert "\n\n"))
(insert build-by)
(spacemacs-buffer//center-line (length build-by))
(insert "\n\n")
(widget-create 'url-link
:tag proudly-free
:help-echo "What is free software?"
:mouse-face 'highlight
:follow-link "\C-m"
"https://www.gnu.org/philosophy/free-sw.en.html")
(spacemacs-buffer//center-line (+ 2 (length proudly-free)))
(when gplv3
(insert "\n\n")
(insert-image gplv3)
(spacemacs-buffer//center-line gplv3-size)
(insert "\n")))))
(defmacro spacemacs-buffer||notes-adapt-caption-to-width (caption
caption-length
@ -334,14 +346,6 @@ WIDTH: current external width of the note's frame."
(setq ,caption nil
,caption-length 0))))
(defvar spacemacs-buffer-note-preview-lines 5
"If it's a positive integer, show the notes first number of lines.
If nil, show the full note.")
(defvar spacemacs-buffer--note-preview-nr-of-removed-lines nil
"Store the number of removed lines from the notes:
Quick Help and Release Notes.")
(defun spacemacs-buffer//if-note-preview-remove-rest-of-note ()
"If `spacemacs-buffer-note-preview-lines' is a positive integer,
remove the rest of the note, after the variables line number."
@ -388,18 +392,18 @@ MIN-WIDTH is the minimal width of the frame, frame included. The frame will not
(paragraph-start "\f\\|[ \t]*$\\|[ \t]*[-+*] \\|[ \t]*[0-9]+[.)] ")
(topcaption-length (if topcaption (length topcaption) 0))
(botcaption-length (if botcaption (length botcaption) 0)))
(setq max-width (or max-width width)
min-width (or min-width 1)
max-width (if (< max-width min-width) min-width max-width)
max-width (if (> max-width spacemacs-buffer--window-width)
spacemacs-buffer--window-width
max-width))
(when (< width min-width)
;; min-width defaults to 1
;; max-width defaults to width, but truncated between min-width and window-width
(setq min-width (or min-width 1)
max-width (min (max (or max-width width) min-width)
spacemacs-buffer--window-width))
(cond
((< width min-width)
(setq width min-width
fill-column (max 0 (- min-width 2 (* hpadding 2)))))
(when (> width max-width)
((> width max-width)
(setq width max-width
fill-column (max 0 (- max-width 2 (* hpadding 2)))))
fill-column (max 0 (- max-width 2 (* hpadding 2))))))
(spacemacs-buffer||notes-adapt-caption-to-width topcaption
topcaption-length
width)
@ -466,7 +470,8 @@ ADDITIONAL-WIDGETS: a function for inserting a widget under the frame."
(match-end 1)
'type 'help-url
'help-args (list (match-string 1)))))
(funcall additional-widgets)
(when additional-widgets
(funcall additional-widgets))
(spacemacs-buffer//center-line)
(delete-trailing-whitespace (line-beginning-position)
(line-end-position)))))
@ -704,9 +709,6 @@ ARGS: format string arguments."
(when init-file-debug
(message "(Spacemacs) %s" (apply 'format msg args))))
(defvar spacemacs-buffer--errors nil
"List of errors during startup.")
(defun spacemacs-buffer/error (msg &rest args)
"Display MSG as an Error message in `*Messages*' buffer.
ARGS: format string arguments."
@ -784,7 +786,7 @@ instead of:
(let* ((func-name (spacemacs-buffer//startup-list-jump-func-name search-label))
(func-name-symbol (intern func-name)))
(eval `(defun ,func-name-symbol ()
(interactive)
(interactive)
(unless (search-forward ,search-label (point-max) t)
(search-backward ,search-label (point-min) t))
,@(unless no-next-line
@ -933,16 +935,23 @@ by pressing its number key."
(when (car list)
(insert list-display-name)
(mapc (lambda (el)
(insert "\n ")
(let* ((button-text-prefix
(let ((button-prefix
(concat
"\n "
(when dotspacemacs-show-startup-list-numbers
(format "%2s" (number-to-string
spacemacs-buffer--startup-list-nr))))
(button-text
(concat
(when dotspacemacs-show-startup-list-numbers
(concat button-text-prefix " "))
(abbreviate-file-name el))))
(format "%2s " (number-to-string spacemacs-buffer--startup-list-nr)))
" "
(when dotspacemacs-startup-buffer-show-icons
(cond
((file-remote-p el)
(all-the-icons-octicon "radio-tower" :height 0.8 :v-adjust -0.05))
((file-directory-p el)
(all-the-icons-icon-for-dir el))
(t
(all-the-icons-icon-for-file (file-name-nondirectory el) :height 0.8 :v-adjust -0.05))))
" "))
(button-text (abbreviate-file-name el)))
(insert button-prefix)
(widget-create 'push-button
:action `(lambda (&rest ignore)
(find-file-existing ,el))
@ -950,6 +959,7 @@ by pressing its number key."
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:button-face nil
:format "%[%t%]" button-text))
(setq spacemacs-buffer--startup-list-nr
(1+ spacemacs-buffer--startup-list-nr)))
@ -960,19 +970,23 @@ by pressing its number key."
"Insert an interactive grouped list of files in the home buffer.
LIST-DISPLAY-NAME: the displayed title of the list.
GROUPED-LIST: a list of string pathnames made interactive in this function."
(when (car grouped-list)
(when (car-safe grouped-list)
(insert list-display-name)
(mapc (lambda (group)
(insert "\n ")
(let* ((button-text-prefix
(when dotspacemacs-show-startup-list-numbers
(format "%2s" (number-to-string
spacemacs-buffer--startup-list-nr))))
(button-text-project
(let* ((group-remote-p (file-remote-p (car group)))
(button-prefix
(concat
"\n "
(when dotspacemacs-show-startup-list-numbers
(concat button-text-prefix " "))
(abbreviate-file-name (car group)))))
(format "%2s " (number-to-string spacemacs-buffer--startup-list-nr)))
" "
(when dotspacemacs-startup-buffer-show-icons
(if group-remote-p
(all-the-icons-octicon "radio-tower" :height 0.8 :v-adjust -0.05)
(all-the-icons-icon-for-dir (car group))))
" "))
(button-text-project (abbreviate-file-name (car group))))
(insert button-prefix)
(widget-create 'push-button
:action `(lambda (&rest ignore)
(find-file-existing ,(car group)))
@ -984,16 +998,20 @@ GROUPED-LIST: a list of string pathnames made interactive in this function."
(setq spacemacs-buffer--startup-list-nr
(1+ spacemacs-buffer--startup-list-nr))
(mapc (lambda (el)
(let* ((button-text-prefix
(when dotspacemacs-show-startup-list-numbers
(format "%2s" (number-to-string
spacemacs-buffer--startup-list-nr))))
(button-text-filename
(let* ((button-prefix
(concat
"\n "
(when dotspacemacs-show-startup-list-numbers
(concat button-text-prefix " "))
(abbreviate-file-name el))))
(insert "\n ")
(format "%2s " (number-to-string spacemacs-buffer--startup-list-nr)))
" "
(when dotspacemacs-startup-buffer-show-icons
(if (or group-remote-p
(file-remote-p (concat (car group) el)))
(all-the-icons-octicon "radio-tower" :height 0.8 :v-adjust -0.05)
(all-the-icons-icon-for-file (file-name-nondirectory el) :height 0.8 :v-adjust -0.05)))
" "))
(button-text-filename (abbreviate-file-name el)))
(insert button-prefix)
(widget-create 'push-button
:action `(lambda (&rest ignore)
(find-file-existing
@ -1015,20 +1033,28 @@ LIST: a list of string bookmark names made interactive in this function."
(when (car list)
(insert list-display-name)
(mapc (lambda (el)
(insert "\n ")
(let* ((filename (bookmark-get-filename el))
(button-text-prefix
(when dotspacemacs-show-startup-list-numbers
(format "%2s" (number-to-string
spacemacs-buffer--startup-list-nr))))
(button-text
(button-prefix
(concat
"\n "
(when dotspacemacs-show-startup-list-numbers
(concat button-text-prefix " "))
(if filename
(format "%s - %s"
el (abbreviate-file-name filename))
(format "%s" el)))))
(format "%2s " (number-to-string spacemacs-buffer--startup-list-nr)))
" "
(when dotspacemacs-startup-buffer-show-icons
(cond
((file-remote-p filename)
(all-the-icons-octicon "radio-tower" :height 0.8 :v-adjust -0.05))
((file-directory-p filename)
(all-the-icons-icon-for-dir filename))
(t
(all-the-icons-icon-for-file (file-name-nondirectory filename) :height 0.8 :v-adjust -0.05))))
" "))
(button-text
(if filename
(format "%s - %s"
el (abbreviate-file-name filename))
(format "%s" el))))
(insert button-prefix)
(widget-create 'push-button
:action `(lambda (&rest ignore) (bookmark-jump ,el))
:mouse-face 'highlight
@ -1045,13 +1071,11 @@ LIST: a list of string bookmark names made interactive in this function."
TYPES: list of `org-mode' types to fetch."
(require 'org-agenda)
(let ((date (calendar-gregorian-from-absolute (org-today))))
(apply #'append
(cl-loop for file in (org-agenda-files nil 'ifmode)
collect
(spacemacs-buffer//make-org-items
(cl-loop for file in (org-agenda-files nil 'ifmode)
append (spacemacs-buffer//make-org-items
file
(apply 'org-agenda-get-day-entries file date
types))))))
types)))))
(defun spacemacs-buffer//agenda-list ()
"Return today's agenda."
@ -1067,23 +1091,17 @@ TYPES: list of `org-mode' types to fetch."
"Make a spacemacs-buffer org item list.
FILE: file name.
ITEMS:"
(cl-loop
for item in items
collect
(spacemacs-buffer//make-org-item file item)))
(cl-loop for item in items
collect (spacemacs-buffer//make-org-item file item)))
(defun spacemacs-buffer//make-org-item (file item)
"Make a spacemacs-buffer version of an org item.
FILE: file name.
ITEM:"
(list (cons "text"
(get-text-property 0 'txt item))
(cons "file" file)
(cons "pos"
(marker-position
(get-text-property 0 'org-marker item)))
(cons "time"
(get-text-property 0 'time item))))
`(("text" . ,(get-text-property 0 'txt item))
("file" . ,file)
("pos" . ,(marker-position (get-text-property 0 'org-marker item)))
("time" . ,(get-text-property 0 'time item))))
(defun spacemacs-buffer//org-jump (el)
"Action executed when using an item in the home buffer's todo list.
@ -1122,25 +1140,27 @@ LIST: list of `org-agenda' entries in the todo list."
(string< (cdr (assoc "time" a))
(cdr (assoc "time" b))))))))
(mapc (lambda (el)
(insert "\n ")
(let* ((button-text-prefix
(when dotspacemacs-show-startup-list-numbers
(format "%2s" (number-to-string
spacemacs-buffer--startup-list-nr))))
(button-text
(let* ((button-prefix
(concat
"\n "
(when dotspacemacs-show-startup-list-numbers
(concat button-text-prefix " "))
(format "%s %s %s"
(let ((filename (cdr (assoc "file" el))))
(if dotspacemacs-home-shorten-agenda-source
(file-name-nondirectory filename)
(abbreviate-file-name filename)))
(if (not (eq "" (cdr (assoc "time" el))))
(format "- %s -"
(cdr (assoc "time" el)))
"-")
(cdr (assoc "text" el))))))
(format "%2s " (number-to-string spacemacs-buffer--startup-list-nr)))
" "
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01))
" "))
(button-text
(format "%s %s %s"
(let ((filename (cdr (assoc "file" el))))
(if dotspacemacs-home-shorten-agenda-source
(file-name-nondirectory filename)
(abbreviate-file-name filename)))
(if (not (eq "" (cdr (assoc "time" el))))
(format "- %s -"
(cdr (assoc "time" el)))
"-")
(cdr (assoc "text" el)))))
(insert button-prefix)
(widget-create 'push-button
:action `(lambda (&rest ignore)
(spacemacs-buffer//org-jump ',el))
@ -1173,15 +1193,30 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(cl-subseq seq start (and (number-or-marker-p end)
(min len end)))))
(defun spacemacs-buffer//propertize-heading (icon text &optional shortcut-char)
(concat
(when dotspacemacs-startup-buffer-show-icons
(concat (concat icon " ")))
(propertize text 'face 'font-lock-keyword-face)
(when shortcut-char
(propertize (concat " (" shortcut-char ")")
'face 'font-lock-comment-face))))
(defun spacemacs-buffer//insert-errors ()
(when (spacemacs-buffer//insert-string-list
"Errors:" spacemacs-buffer--errors)
(spacemacs-buffer//propertize-heading
(all-the-icons-material "error" :face 'font-lock-keyword-face)
"Errors:" "e")
spacemacs-buffer--errors)
(spacemacs-buffer||add-shortcut "e" "Errors:")
(insert spacemacs-buffer-list-separator)))
(defun spacemacs-buffer//insert-warnings ()
(when (spacemacs-buffer//insert-string-list
"Warnings:" spacemacs-buffer--warnings)
(spacemacs-buffer//propertize-heading
(all-the-icons-material "warning" :face 'font-lock-keyword-face)
"Warnings:" "w")
spacemacs-buffer--warnings)
(spacemacs-buffer||add-shortcut "w" "Warnings:")
(insert spacemacs-buffer-list-separator)))
@ -1197,7 +1232,9 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(setq spacemacs-buffer//recent-files-list
(spacemacs//subseq spacemacs-buffer//recent-files-list 0 list-size))
(when (spacemacs-buffer//insert-file-list
"Recent Files:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "history" :face 'font-lock-keyword-face :v-adjust -0.05)
"Recent Files:" "r")
spacemacs-buffer//recent-files-list)
(spacemacs-buffer||add-shortcut "r" "Recent Files:"))
(insert spacemacs-buffer-list-separator))
@ -1206,7 +1243,9 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(unless recentf-mode (recentf-mode))
(unless projectile-mode (projectile-mode))
(when (spacemacs-buffer//insert-files-by-dir-list
"Recent Files by Project:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05)
"Recent Files by Project:" "R")
(mapcar (lambda (group)
(cons (car group)
(spacemacs//subseq (reverse (cdr group))
@ -1220,15 +1259,19 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-todos (list-size)
(when (spacemacs-buffer//insert-todo-list
"ToDo:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "check" :face 'font-lock-keyword-face :v-adjust -0.05)
"To-Do:" "d")
(spacemacs//subseq (spacemacs-buffer//todo-list)
0 list-size))
(spacemacs-buffer||add-shortcut "d" "ToDo:")
(spacemacs-buffer||add-shortcut "d" "To-Do:")
(insert spacemacs-buffer-list-separator)))
(defun spacemacs-buffer//insert-agenda (list-size)
(when (spacemacs-buffer//insert-todo-list
"Agenda:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "calendar" :face 'font-lock-keyword-face :v-adjust -0.05)
"Agenda:" "c")
(spacemacs//subseq (spacemacs-buffer//agenda-list)
0 list-size))
(spacemacs-buffer||add-shortcut "c" "Agenda:")
@ -1239,7 +1282,9 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(helm-mode))
(require 'bookmark)
(when (spacemacs-buffer//insert-bookmark-list
"Bookmarks:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face :v-adjust -0.05)
"Bookmarks:" "b")
(spacemacs//subseq (bookmark-all-names)
0 list-size))
(spacemacs-buffer||add-shortcut "b" "Bookmarks:")
@ -1248,7 +1293,9 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-projects (list-size)
(unless projectile-mode (projectile-mode))
(when (spacemacs-buffer//insert-file-list
"Projects:"
(spacemacs-buffer//propertize-heading
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05)
"Projects:" "p")
(spacemacs//subseq (projectile-relevant-known-projects)
0 list-size))
(spacemacs-buffer||add-shortcut "p" "Projects:")
@ -1259,23 +1306,30 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//do-insert-startupify-lists ()
"Insert the startup lists in the current buffer."
(setq spacemacs-buffer--startup-list-nr 1)
(dolist (els (append '(warnings) dotspacemacs-startup-lists))
(let ((el (or (car-safe els) els))
(list-size (or (cdr-safe els)
spacemacs-buffer-startup-lists-length)))
(cond
((eq el 'warnings)
(spacemacs-buffer//insert-errors)
(spacemacs-buffer//insert-warnings))
((eq el 'recents) (spacemacs-buffer//insert-recent-files list-size))
((eq el 'recents-by-project)
(spacemacs-buffer//insert-recent-files-by-project list-size))
((eq el 'todos) (spacemacs-buffer//insert-todos list-size))
((eq el 'agenda) (spacemacs-buffer//insert-agenda list-size))
((eq el 'bookmarks) (spacemacs-buffer//insert-bookmarks list-size))
((and (eq el 'projects)
(fboundp 'projectile-mode))
(spacemacs-buffer//insert-projects list-size))))))
(let ((dotspacemacs-startup-buffer-show-icons dotspacemacs-startup-buffer-show-icons))
(if (display-graphic-p)
(unless (or (fboundp 'all-the-icons-octicon)
(require 'all-the-icons nil 'noerror))
(message "Package `all-the-icons' isn't installed")
(setq dotspacemacs-startup-buffer-show-icons nil))
(setq dotspacemacs-startup-buffer-show-icons nil))
(dolist (els (append '(warnings) dotspacemacs-startup-lists))
(let ((el (or (car-safe els) els))
(list-size (or (cdr-safe els)
spacemacs-buffer-startup-lists-length)))
(cond
((eq el 'warnings)
(spacemacs-buffer//insert-errors)
(spacemacs-buffer//insert-warnings))
((eq el 'recents) (spacemacs-buffer//insert-recent-files list-size))
((eq el 'recents-by-project)
(spacemacs-buffer//insert-recent-files-by-project list-size))
((eq el 'todos) (spacemacs-buffer//insert-todos list-size))
((eq el 'agenda) (spacemacs-buffer//insert-agenda list-size))
((eq el 'bookmarks) (spacemacs-buffer//insert-bookmarks list-size))
((and (eq el 'projects)
(fboundp 'projectile-mode))
(spacemacs-buffer//insert-projects list-size)))))))
(defun spacemacs-buffer//get-buffer-width ()
"Return the length of longest line in the current buffer."
@ -1284,8 +1338,7 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(let ((current-max 0))
(while (not (eobp))
(let ((line-length (- (line-end-position) (line-beginning-position))))
(if (< current-max line-length)
(setq current-max line-length)))
(setq current-max (max current-max line-length)))
(forward-line 1))
current-max)))
@ -1294,12 +1347,11 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(let* ((lists-width (spacemacs-buffer//get-buffer-width))
(margin (max 0 (- spacemacs-buffer--buttons-position
spacemacs-buffer-buttons-startup-lists-offset)))
(final-padding (if (< spacemacs-buffer--window-width
(+ margin lists-width))
(max 0 (floor (/ (- spacemacs-buffer--window-width
lists-width)
2)))
margin)))
(width-diff (- spacemacs-buffer--window-width lists-width))
(final-padding (cond
((>= width-diff margin) margin)
((< width-diff 0) 0)
(t (floor (/ width-diff 2))))))
(goto-char (point-min))
(while (not (eobp))
(beginning-of-line)
@ -1328,13 +1380,6 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(search-forward "[")
(left-char 2))))
(defvar spacemacs-buffer--idle-numbers-timer nil
"This stores the idle numbers timer.")
(defvar spacemacs-buffer--startup-list-number nil
"This accumulates the numbers that are typed in the home buffer.
It's cleared when the idle timer runs.")
(defun spacemacs-buffer/jump-to-number-startup-list-line ()
"Jump to the startup list line with the typed number.
@ -1358,10 +1403,10 @@ can be adjusted with the variable:
'spacemacs-buffer/stop-waiting-for-additional-numbers))))
(defun spacemacs-buffer//re-line-starts-with-nr-space (nr-string)
(concat "^\s?*" nr-string " "))
(concat "^ +" nr-string "[0-9]* +. "))
(defun spacemacs-buffer/jump-to-line-starting-with-nr-space (nr-string)
"Jump to the line number that starts with NR."
"Jump to the line begins with NR-STRING, skipping non-digit prefix."
(let ((prev-point (point)))
(goto-char (window-start))
(if (not (re-search-forward
@ -1376,10 +1421,8 @@ can be adjusted with the variable:
(let (message-log-max) ; only show in minibuffer
(message "Couldn't find startup list number: %s"
spacemacs-buffer--startup-list-number)))
(back-to-indentation)
(message "Opening file/dir: %s"
(replace-regexp-in-string "^\s*" ""
(widget-value (widget-at (point)))))
(widget-value (widget-at (point))))
(widget-button-press (point)))))
(defun spacemacs-buffer/stop-waiting-for-additional-numbers ()
@ -1408,9 +1451,6 @@ can be adjusted with the variable:
(force-mode-line-update)
(spacemacs-buffer/goto-link-line)))
(defvar spacemacs-buffer--last-width nil
"Previous width of spacemacs-buffer.")
(defun spacemacs-buffer/goto-buffer (&optional refresh)
"Create the special buffer for `spacemacs-buffer-mode' and switch to it.
REFRESH if the buffer should be redrawn.
@ -1443,10 +1483,10 @@ If a prefix argument is given, switch to it in an other, possibly new window."
(spacemacs-buffer/insert-banner-and-buttons)
(when (bound-and-true-p spacemacs-initialized)
(spacemacs-buffer//notes-redisplay-current-note)
(configuration-layer/display-summary emacs-start-time)
(when dotspacemacs-startup-lists
(spacemacs-buffer/insert-startup-lists))
(spacemacs-buffer//insert-footer)
(configuration-layer/display-summary emacs-start-time)
(spacemacs-buffer/set-mode-line spacemacs--default-mode-line)
(force-mode-line-update)
(spacemacs-buffer-mode)))

View File

@ -246,9 +246,10 @@ Note: the hooked function is not executed when in dumped mode."
(when spacemacs--delayed-user-theme
(spacemacs/load-theme spacemacs--delayed-user-theme
spacemacs--fallback-theme t))
(configuration-layer/display-summary emacs-start-time)
(spacemacs-buffer//startup-hook)
(configuration-layer/display-summary emacs-start-time)
(spacemacs/check-for-new-version nil spacemacs-version-check-interval)
(spacemacs-buffer/goto-link-line)
(setq spacemacs-initialized t)
(setq gc-cons-threshold (car dotspacemacs-gc-cons)
gc-cons-percentage (cadr dotspacemacs-gc-cons))

View File

@ -202,6 +202,11 @@ It should only modify the values of Spacemacs settings."
;; The minimum delay in seconds between number key presses. (default 0.4)
dotspacemacs-startup-buffer-multi-digit-delay 0.4
;; If non-nil, show file icons for entries and headings on Spacemacs home buffer.
;; This has no effect in terminal or if "all-the-icons" package or the font
;; is not installed. (default nil)
dotspacemacs-startup-buffer-show-icons nil
;; Default major mode for a new empty buffer. Possible values are mode
;; names such as `text-mode'; and `nil' to use Fundamental mode.
;; (default `text-mode')

View File

@ -29,7 +29,6 @@
company
(company-posframe :toggle auto-completion-use-company-posframe)
(company-box :toggle auto-completion-use-company-box)
(all-the-icons :toggle auto-completion-use-company-box)
(company-quickhelp :toggle auto-completion-enable-help-tooltip)
(company-statistics :toggle auto-completion-enable-sort-by-usage)
counsel
@ -161,65 +160,47 @@
(unless (eq auto-completion-enable-help-tooltip 'manual)
(company-quickhelp-mode))))))
(defun auto-completion/init-all-the-icons ()
(use-package all-the-icons
:after company
:config
(progn
(eval-and-compile
;; Icons selected by liguangsheng
;; https://github.com/liguangsheng/emacsd/blob/master/lisp/init-completion.el
(defun my-company-box-icon (family icon &rest args)
"Defines icons using `all-the-icons' for `company-box'."
(when icon
(let ((icon (pcase family
('octicon (all-the-icons-octicon icon :height 0.8 :v-adjust -0.05 args))
('faicon (all-the-icons-faicon icon :height 0.8 :v-adjust -0.0575))
('material (all-the-icons-material icon :height 0.8 :v-adjust -0.225 args))
('alltheicon (all-the-icons-alltheicon icon :height 0.8 args)))))
(unless (symbolp icon)
(concat icon
(propertize " " 'face 'variable-pitch)))))))
(setq company-box-icons-all-the-icons
`((Unknown . ,(my-company-box-icon 'octicon "file-text"))
(Text . ,(my-company-box-icon 'faicon "file-text-o"))
(Method . ,(my-company-box-icon 'faicon "cube"))
(Function . ,(my-company-box-icon 'faicon "cube"))
(Constructor . ,(my-company-box-icon 'faicon "cube"))
(Field . ,(my-company-box-icon 'faicon "tag"))
(Variable . ,(my-company-box-icon 'faicon "tag"))
(Class . ,(my-company-box-icon 'faicon "cog"))
(Interface . ,(my-company-box-icon 'faicon "cogs"))
(Module . ,(my-company-box-icon 'alltheicon "less"))
(Property . ,(my-company-box-icon 'faicon "wrench"))
(Unit . ,(my-company-box-icon 'faicon "tag"))
(Value . ,(my-company-box-icon 'faicon "tag"))
(Enum . ,(my-company-box-icon 'faicon "file-text-o"))
(Keyword . ,(my-company-box-icon 'material "format_align_center"))
(Snippet . ,(my-company-box-icon 'material "content_paste"))
(Color . ,(my-company-box-icon 'material "palette"))
(File . ,(my-company-box-icon 'faicon "file"))
(Reference . ,(my-company-box-icon 'faicon "tag"))
(Folder . ,(my-company-box-icon 'faicon "folder"))
(EnumMember . ,(my-company-box-icon 'faicon "tag"))
(Constant . ,(my-company-box-icon 'faicon "tag"))
(Struct . ,(my-company-box-icon 'faicon "cog"))
(Event . ,(my-company-box-icon 'faicon "bolt"))
(Operator . ,(my-company-box-icon 'faicon "tag"))
(TypeParameter . ,(my-company-box-icon 'faicon "cog"))
(Template . ,(my-company-box-icon 'octicon "file-code")))))))
(defun auto-completion/init-company-box ()
(use-package company-box
:hook '(company-mode . company-box-mode)
:commands 'company-box-doc-manually
:init (setq company-box-icons-alist 'company-box-icons-all-the-icons)
:custom
(company-box-backends-colors nil)
(company-box-max-candidates 1000)
(company-box-doc-enable nil)
(company-box-icons-alist 'company-box-icons-all-the-icons)
(company-box-icons-all-the-icons
`((Unknown . ,(all-the-icons-octicon "file-text" :height 0.8 :v-adjust -0.05))
(Text . ,(all-the-icons-faicon "file-text-o" :height 0.8 :v-adjust -0.0575))
(Method . ,(all-the-icons-faicon "cube" :height 0.8 :v-adjust -0.0575))
(Function . ,(all-the-icons-faicon "cube" :height 0.8 :v-adjust -0.0575))
(Constructor . ,(all-the-icons-faicon "cube" :height 0.8 :v-adjust -0.0575))
(Field . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Variable . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Class . ,(all-the-icons-faicon "cog" :height 0.8 :v-adjust -0.0575))
(Interface . ,(all-the-icons-faicon "cogs" :height 0.8 :v-adjust -0.0575))
(Module . ,(all-the-icons-alltheicon "less" :height 0.8))
(Property . ,(all-the-icons-faicon "wrench" :height 0.8 :v-adjust -0.0575))
(Unit . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Value . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Enum . ,(all-the-icons-faicon "file-text-o" :height 0.8 :v-adjust -0.0575))
(Keyword . ,(all-the-icons-material "format_align_center" :height 0.8 :v-adjust -0.225))
(Snippet . ,(all-the-icons-material "content_paste" :height 0.8 :v-adjust -0.225))
(Color . ,(all-the-icons-material "palette" :height 0.8 :v-adjust -0.225))
(File . ,(all-the-icons-faicon "file" :height 0.8 :v-adjust -0.0575))
(Reference . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Folder . ,(all-the-icons-faicon "folder" :height 0.8 :v-adjust -0.0575))
(EnumMember . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Constant . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(Struct . ,(all-the-icons-faicon "cog" :height 0.8 :v-adjust -0.0575))
(Event . ,(all-the-icons-faicon "bolt" :height 0.8 :v-adjust -0.0575))
(Operator . ,(all-the-icons-faicon "tag" :height 0.8 :v-adjust -0.0575))
(TypeParameter . ,(all-the-icons-faicon "cog" :height 0.8 :v-adjust -0.0575))
(Template . ,(all-the-icons-octicon "file-code" :height 0.8 :v-adjust -0.05))))
:init
:config
(progn
(spacemacs|hide-lighter company-box-mode)
(setq company-box-backends-colors nil
company-box-max-candidates 1000
company-box-doc-enable nil)
(add-hook 'company-box-selection-hook
(lambda (selection frame) (company-box-doc--hide frame)))
(cl-case auto-completion-enable-help-tooltip

View File

@ -23,6 +23,7 @@
(setq spacemacs-visual-packages
'(
all-the-icons
(ansi-colors :location built-in)
desktop
;; `display-fill-column-indicator' is available in Emacs 27+
@ -34,6 +35,9 @@
popwin
(zoom-frm :location local)))
(defun spacemacs-visual/init-all-the-icons ()
(use-package all-the-icons
:defer t))
(defun spacemacs-visual/init-ansi-colors ()
(add-hook 'compilation-filter-hook