2016-05-21 18:54:58 -04:00
|
|
|
;;; core-scratch.el
|
|
|
|
|
|
|
|
(setq initial-major-mode 'doom-mode
|
|
|
|
initial-scratch-message "\n Loading..."
|
2016-05-21 23:08:06 -04:00
|
|
|
inhibit-startup-screen t
|
|
|
|
;; shuts up emacs at startup
|
|
|
|
inhibit-startup-echo-area-message user-login-name)
|
|
|
|
|
|
|
|
(defvar doom-buffer nil
|
|
|
|
"The global and persistent scratch buffer for doom.")
|
2016-06-18 01:30:12 -04:00
|
|
|
(defvar doom-buffer-name " *doom*"
|
2016-05-21 23:08:06 -04:00
|
|
|
"The name of the doom scratch buffer.")
|
2016-06-08 14:37:28 -04:00
|
|
|
(defvar doom-buffer-edited nil
|
2016-05-23 17:12:18 -04:00
|
|
|
"If non-nil, the scratch buffer has been edited.")
|
2016-05-21 18:54:58 -04:00
|
|
|
|
2016-10-05 12:48:12 +02:00
|
|
|
(define-derived-mode doom-mode fundamental-mode
|
2016-10-06 14:15:37 +02:00
|
|
|
(concat "v" doom-version)
|
2016-05-23 17:12:18 -04:00
|
|
|
"Major mode for special DOOM buffers.")
|
2016-05-21 18:54:58 -04:00
|
|
|
|
|
|
|
;; Don't kill the scratch buffer
|
2016-05-21 23:08:06 -04:00
|
|
|
(add-hook! 'kill-buffer-query-functions
|
2016-06-08 14:37:28 -04:00
|
|
|
(not (eq doom-buffer (current-buffer))))
|
2016-05-21 18:54:58 -04:00
|
|
|
|
2016-10-05 12:48:12 +02:00
|
|
|
(add-hook 'emacs-startup-hook 'doom--reload-scratch-buffer)
|
2016-09-15 14:34:18 +02:00
|
|
|
|
2016-10-05 12:48:12 +02:00
|
|
|
;; Don't rename these buffers. That could cause problems.
|
2016-05-30 04:02:01 -04:00
|
|
|
(after! uniquify
|
2016-09-08 11:59:46 +02:00
|
|
|
(setq uniquify-ignore-buffers-re (regexp-quote doom-buffer-name)))
|
2016-05-30 04:02:01 -04:00
|
|
|
|
2016-10-05 12:48:12 +02:00
|
|
|
(defun doom*scratch-split-hack (&rest _)
|
|
|
|
"Removes the window margins before attempting a vertical-split on the scratch
|
|
|
|
buffer. Without this, it would refuse to split, saying 'too small to split'."
|
|
|
|
(when (eq (current-buffer) doom-buffer)
|
|
|
|
(set-window-margins nil 0 0)))
|
|
|
|
(advice-add 'split-window :before 'doom*scratch-split-hack)
|
|
|
|
|
|
|
|
(defun doom|mode-erase-on-insert ()
|
|
|
|
"Erase the buffer and prepare it to be used like a normal buffer."
|
2016-05-23 17:12:18 -04:00
|
|
|
(erase-buffer)
|
2016-10-05 12:48:12 +02:00
|
|
|
(set-window-margins (get-buffer-window doom-buffer) 0 0)
|
2016-10-06 14:15:37 +02:00
|
|
|
(setq doom-buffer-edited t
|
|
|
|
mode-line-format (doom-modeline)
|
|
|
|
doom--scratch-width nil)
|
2016-10-05 12:48:12 +02:00
|
|
|
(remove-hook 'evil-insert-state-entry-hook 'doom|mode-erase-on-insert t))
|
2016-05-23 17:12:18 -04:00
|
|
|
|
2016-10-05 12:48:12 +02:00
|
|
|
(defun doom-reload-scratch-buffer (&optional dir)
|
|
|
|
"Update the DOOM scratch buffer (or create it, if it doesn't exist)."
|
|
|
|
(when (and (get-buffer-window-list doom-buffer nil t)
|
|
|
|
(or (not doom-buffer-edited) dir)
|
|
|
|
(not (minibuffer-window-active-p (minibuffer-window))))
|
|
|
|
(doom--reload-scratch-buffer dir)))
|
2016-09-15 14:34:18 +02:00
|
|
|
|
2016-10-06 14:15:37 +02:00
|
|
|
(defvar doom--scratch-width nil)
|
|
|
|
(defvar doom--scratch-height nil)
|
2016-10-05 12:48:12 +02:00
|
|
|
(defun doom--reload-scratch-buffer (&optional dir)
|
|
|
|
;; Rename the old scratch buffer, if it exists.
|
2016-05-21 18:54:58 -04:00
|
|
|
(let ((old-scratch (get-buffer "*scratch*")))
|
|
|
|
(when old-scratch
|
|
|
|
(with-current-buffer old-scratch
|
|
|
|
(rename-buffer doom-buffer-name)
|
|
|
|
(setq doom-buffer old-scratch))))
|
2016-10-05 12:48:12 +02:00
|
|
|
;; Ensure the doom buffer is alive!
|
2016-09-15 14:34:18 +02:00
|
|
|
(unless (buffer-live-p doom-buffer)
|
|
|
|
(setq doom-buffer nil))
|
2016-05-21 18:54:58 -04:00
|
|
|
(unless doom-buffer
|
|
|
|
(setq doom-buffer (get-buffer-create doom-buffer-name)))
|
2016-10-05 12:48:12 +02:00
|
|
|
;; Fill it with the splash screen content
|
2016-05-21 18:54:58 -04:00
|
|
|
(with-current-buffer doom-buffer
|
|
|
|
(doom-mode)
|
2016-10-05 12:48:12 +02:00
|
|
|
(add-hook 'evil-insert-state-entry-hook 'doom|mode-erase-on-insert nil t)
|
|
|
|
(add-hook 'after-change-major-mode-hook 'doom|mode-erase-on-insert nil t)
|
2016-05-23 17:12:18 -04:00
|
|
|
(setq doom-buffer-edited nil)
|
2016-10-06 14:15:37 +02:00
|
|
|
(let ((width 78)
|
|
|
|
updates-p height)
|
2016-10-05 12:48:12 +02:00
|
|
|
(mapc (lambda (window)
|
|
|
|
(set-window-margins window 0 0)
|
|
|
|
(let ((pad (max 0 (- (truncate (/ (window-width window) 2)) (truncate (/ width 2))))))
|
|
|
|
(set-window-margins window pad pad)
|
|
|
|
(setq height (max 0
|
|
|
|
(min (or height 9999)
|
2016-10-06 17:21:00 +02:00
|
|
|
(- (truncate (/ (window-height window) 2)) 12))))))
|
2016-10-05 12:48:12 +02:00
|
|
|
(get-buffer-window-list doom-buffer nil t))
|
2016-10-06 14:15:37 +02:00
|
|
|
(when (or (not doom--scratch-width)
|
|
|
|
(not doom--scratch-height)
|
|
|
|
(/= doom--scratch-width width)
|
2016-10-06 17:21:00 +02:00
|
|
|
(/= doom--scratch-height height))
|
2016-10-06 14:15:37 +02:00
|
|
|
(erase-buffer)
|
2016-10-06 20:12:31 +02:00
|
|
|
(insert (make-string (if height (max 0 height) 0) ?\n)
|
|
|
|
(propertize
|
2016-10-06 14:15:37 +02:00
|
|
|
(concat
|
|
|
|
"================= =============== =============== ======== ========\n"
|
|
|
|
"\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //\n"
|
|
|
|
"||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||\n"
|
|
|
|
"|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||\n"
|
|
|
|
"||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||\n"
|
|
|
|
"|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||\n"
|
|
|
|
"||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||\n"
|
|
|
|
"|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||\n"
|
|
|
|
"||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||\n"
|
|
|
|
"|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||\n"
|
|
|
|
"|| `' || || `' || || `' || || | \\ / | ||\n"
|
|
|
|
"|| .===' `===. .==='.`===. .===' /==. | \\/ | ||\n"
|
|
|
|
"|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||\n"
|
|
|
|
"|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||\n"
|
|
|
|
"|| .==' _-' '-__\\._-' '-_./__-' `' |. /| | ||\n"
|
|
|
|
"||.==' _-' `' | /==.||\n"
|
|
|
|
"==' _-' E M A C S \\/ `==\n"
|
2016-10-06 20:12:31 +02:00
|
|
|
"\\ _-' `-_ /\n"
|
|
|
|
" `'' ``'")
|
2016-10-06 14:15:37 +02:00
|
|
|
'face 'font-lock-comment-face)
|
|
|
|
"\n\n"
|
2016-10-06 20:12:31 +02:00
|
|
|
(s-center 73 (doom--scratch-info))
|
|
|
|
"\n\n"
|
|
|
|
(s-center
|
|
|
|
78 (propertize (format "Loaded %d packages in %s"
|
|
|
|
(length doom-packages)
|
|
|
|
(emacs-init-time))
|
|
|
|
'face '(:inherit font-lock-comment-face
|
|
|
|
:height 0.9))))
|
2016-10-06 14:15:37 +02:00
|
|
|
(setq doom--scratch-width width
|
|
|
|
doom--scratch-height height)))
|
|
|
|
(goto-char 1521)
|
2016-10-05 12:48:12 +02:00
|
|
|
(when dir (setq default-directory dir))
|
|
|
|
(setq mode-line-format (doom-modeline 'scratch))
|
2016-10-06 14:15:37 +02:00
|
|
|
;; Readjust the scratch buffer if it is visible, when the frame changes.
|
2016-10-05 12:48:12 +02:00
|
|
|
(add-hook 'window-configuration-change-hook 'doom-reload-scratch-buffer)))
|
2016-05-21 18:54:58 -04:00
|
|
|
|
2016-10-06 20:12:31 +02:00
|
|
|
;; TODO Less hard-coded
|
|
|
|
(defun doom--scratch-info ()
|
2016-10-06 17:21:00 +02:00
|
|
|
(let ((all-the-icons-scale-factor 1.3)
|
2016-10-06 14:15:37 +02:00
|
|
|
(all-the-icons-default-adjust -0.05)
|
2016-10-06 20:12:31 +02:00
|
|
|
(start (point))
|
|
|
|
(sep " ")
|
2016-10-07 20:53:56 +02:00
|
|
|
(last-session-p (and (featurep 'workgroups2)
|
|
|
|
(f-exists-p wg-session-file)))
|
2016-10-06 20:12:31 +02:00
|
|
|
end)
|
|
|
|
(unless last-session-p
|
|
|
|
(setq sep " "))
|
2016-10-06 14:15:37 +02:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert-text-button
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"mark-github"
|
|
|
|
:face 'font-lock-keyword-face)
|
|
|
|
(propertize " Homepage" 'face 'font-lock-keyword-face))
|
2016-10-06 17:21:00 +02:00
|
|
|
'action '(lambda (_) (browse-url "https://github.com/hlissner/.emacs.d"))
|
|
|
|
'follow-link t)
|
2016-10-06 14:15:37 +02:00
|
|
|
|
2016-10-06 20:12:31 +02:00
|
|
|
(insert sep " ")
|
2016-10-06 14:15:37 +02:00
|
|
|
|
|
|
|
(insert-text-button
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"file-text"
|
|
|
|
:face 'font-lock-keyword-face)
|
|
|
|
(propertize " Recent files" 'face 'font-lock-keyword-face))
|
2016-10-06 17:21:00 +02:00
|
|
|
'action '(lambda (_) (call-interactively 'counsel-recentf))
|
|
|
|
'follow-link t)
|
2016-10-06 14:15:37 +02:00
|
|
|
|
2016-10-06 20:12:31 +02:00
|
|
|
(insert sep)
|
2016-10-06 14:15:37 +02:00
|
|
|
|
|
|
|
(insert-text-button
|
|
|
|
(concat (all-the-icons-octicon
|
2016-10-06 20:12:31 +02:00
|
|
|
"tools"
|
2016-10-06 14:15:37 +02:00
|
|
|
:face 'font-lock-keyword-face)
|
2016-10-06 20:12:31 +02:00
|
|
|
(propertize " Edit emacs.d" 'face 'font-lock-keyword-face))
|
|
|
|
'action '(lambda (_) (find-file (f-expand "init.el" doom-emacs-dir)))
|
2016-10-06 17:21:00 +02:00
|
|
|
'follow-link t)
|
2016-10-06 14:15:37 +02:00
|
|
|
|
2016-10-06 20:12:31 +02:00
|
|
|
(when last-session-p
|
|
|
|
(insert sep)
|
2016-10-06 14:15:37 +02:00
|
|
|
|
2016-10-06 20:12:31 +02:00
|
|
|
(insert-text-button
|
|
|
|
(concat (all-the-icons-octicon
|
|
|
|
"history"
|
|
|
|
:face 'font-lock-keyword-face)
|
|
|
|
(propertize " Reload last session" 'face 'font-lock-keyword-face))
|
|
|
|
'action '(lambda (_) (doom:workgroup-load))
|
|
|
|
'follow-link t))
|
2016-10-06 14:15:37 +02:00
|
|
|
|
|
|
|
(setq end (point))
|
|
|
|
(buffer-string))))
|
|
|
|
|
2016-05-21 18:54:58 -04:00
|
|
|
(provide 'core-scratch)
|
|
|
|
;;; core-scratch.el ends here
|