Polish *doom* integration
This commit is contained in:
parent
204847f95c
commit
770e38273e
2 changed files with 57 additions and 39 deletions
|
@ -10,10 +10,11 @@
|
||||||
"The global and persistent scratch buffer for doom.")
|
"The global and persistent scratch buffer for doom.")
|
||||||
(defvar doom-buffer-name "*doom*"
|
(defvar doom-buffer-name "*doom*"
|
||||||
"The name of the doom scratch buffer.")
|
"The name of the doom scratch buffer.")
|
||||||
|
(defvar-local doom-buffer-edited nil
|
||||||
|
"If non-nil, the scratch buffer has been edited.")
|
||||||
|
|
||||||
(define-derived-mode doom-mode text-mode "DOOM"
|
(define-derived-mode doom-mode text-mode "DOOM"
|
||||||
"Major mode for special DOOM buffers."
|
"Major mode for special DOOM buffers.")
|
||||||
:group 'doom)
|
|
||||||
|
|
||||||
;; Don't kill the scratch buffer
|
;; Don't kill the scratch buffer
|
||||||
(add-hook! 'kill-buffer-query-functions
|
(add-hook! 'kill-buffer-query-functions
|
||||||
|
@ -25,6 +26,11 @@
|
||||||
(doom-mode-init)
|
(doom-mode-init)
|
||||||
(setq mode-line-format nil))
|
(setq mode-line-format nil))
|
||||||
|
|
||||||
|
(defun doom-mode-erase-on-insert ()
|
||||||
|
(erase-buffer)
|
||||||
|
(setq doom-buffer-edited t)
|
||||||
|
(remove-hook 'evil-insert-state-entry-hook 'doom-mode-erase-on-insert t))
|
||||||
|
|
||||||
(defun doom-mode-init (&optional auto-detect-frame)
|
(defun doom-mode-init (&optional auto-detect-frame)
|
||||||
(unless (buffer-live-p doom-buffer) (setq doom-buffer nil))
|
(unless (buffer-live-p doom-buffer) (setq doom-buffer nil))
|
||||||
(let ((old-scratch (get-buffer "*scratch*")))
|
(let ((old-scratch (get-buffer "*scratch*")))
|
||||||
|
@ -36,18 +42,23 @@
|
||||||
(setq doom-buffer (get-buffer-create doom-buffer-name)))
|
(setq doom-buffer (get-buffer-create doom-buffer-name)))
|
||||||
(with-current-buffer doom-buffer
|
(with-current-buffer doom-buffer
|
||||||
(doom-mode)
|
(doom-mode)
|
||||||
|
(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)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
|
(setq doom-buffer-edited nil)
|
||||||
(insert
|
(insert
|
||||||
(let* ((auto-detect-frame (or auto-detect-frame (not (display-graphic-p))))
|
(let* ((auto-detect-frame (or auto-detect-frame (not (display-graphic-p))))
|
||||||
(width (- (if auto-detect-frame (window-width) (cdr (assq 'width default-frame-alist))) 3))
|
(width (if auto-detect-frame
|
||||||
(lead (make-string (truncate (/ (- width 78) 2)) ? )))
|
(window-width)
|
||||||
|
(cdr (assq 'width default-frame-alist))))
|
||||||
|
(height (if auto-detect-frame
|
||||||
|
(window-height)
|
||||||
|
(cdr (assq 'height default-frame-alist))))
|
||||||
|
(lead (make-string (truncate (max 0 (/ (- width 78) 2))) ? )))
|
||||||
(concat
|
(concat
|
||||||
(propertize
|
(propertize
|
||||||
(concat
|
(concat
|
||||||
(make-string (min 3 (/ (if auto-detect-frame
|
(make-string (min 3 (truncate (/ height 5))) ?\n)
|
||||||
(window-height)
|
|
||||||
(cdr (assq 'height default-frame-alist))) 5))
|
|
||||||
?\n)
|
|
||||||
lead "================= =============== =============== ======== ========\n"
|
lead "================= =============== =============== ======== ========\n"
|
||||||
lead "\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //\n"
|
lead "\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //\n"
|
||||||
lead "||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||\n"
|
lead "||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||\n"
|
||||||
|
@ -71,15 +82,15 @@
|
||||||
"\n\n"
|
"\n\n"
|
||||||
(propertize
|
(propertize
|
||||||
(s-trim-right
|
(s-trim-right
|
||||||
(s-center (1- width) "Press `,m` to open recent files, or `,E` to access emacs.d"))
|
(s-center (max 0 (1- width)) "Press `,m` to open recent files, or `,E` to access emacs.d"))
|
||||||
'face 'font-lock-keyword-face)
|
'face 'font-lock-keyword-face)
|
||||||
(concat
|
(concat
|
||||||
"\n\n"
|
"\n\n"
|
||||||
(s-trim-right (s-center (- width 2)
|
(s-trim-right (s-center (max 0 (- width 2))
|
||||||
(format "Loaded in %.3fs"
|
(format "Loaded in %.3fs"
|
||||||
(float-time (time-subtract after-init-time emacs-start-time)))))))))
|
(float-time (time-subtract after-init-time emacs-start-time)))))))))
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
(doom|update-scratch-buffer)))
|
(doom|update-scratch-buffer nil t)))
|
||||||
|
|
||||||
(provide 'core-scratch)
|
(provide 'core-scratch)
|
||||||
;;; core-scratch.el ends here
|
;;; core-scratch.el ends here
|
||||||
|
|
|
@ -51,11 +51,12 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(--filter (memq it assocbuf) (buffer-list))
|
(--filter (memq it assocbuf) (buffer-list))
|
||||||
(buffer-list)))
|
(buffer-list)))
|
||||||
project-root)
|
project-root)
|
||||||
(aif (and project-p (doom/project-root t))
|
(append (aif (and project-p (doom/project-root t))
|
||||||
(funcall (if (eq project-p 'not) '-remove '-filter)
|
(funcall (if (eq project-p 'not) '-remove '-filter)
|
||||||
(lambda (b) (projectile-project-buffer-p b it))
|
(lambda (b) (projectile-project-buffer-p b it))
|
||||||
buffers)
|
buffers)
|
||||||
buffers)))
|
buffers)
|
||||||
|
(list doom-buffer))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/get-buffer-names (&optional project-p)
|
(defun doom/get-buffer-names (&optional project-p)
|
||||||
|
@ -96,24 +97,25 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(-filter #'doom/real-buffer-p (or buffer-list (doom/get-buffers))))
|
(-filter #'doom/real-buffer-p (or buffer-list (doom/get-buffers))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/kill-real-buffer ()
|
(defun doom/kill-real-buffer (&optional arg)
|
||||||
"Kill buffer (but only bury scratch buffer), then switch to a real buffer. Only buries
|
"Kill buffer (but only bury scratch buffer), then switch to a real buffer. Only buries
|
||||||
the buffer if it is being displayed in another window."
|
the buffer if it is being displayed in another window."
|
||||||
(interactive)
|
(interactive (list t))
|
||||||
(let (new-dir)
|
(if (eq doom-buffer (current-buffer))
|
||||||
(if (string-match-p doom-buffer-name (or (buffer-name) ""))
|
|
||||||
(progn
|
(progn
|
||||||
(doom-mode-init t)
|
(when (= (length (get-buffer-window-list doom-buffer nil t)) 1)
|
||||||
(message "Already in the scratch buffer"))
|
(doom-mode-init t))
|
||||||
(setq new-dir (doom/project-root))
|
(when arg (message "Already in scratch buffer")))
|
||||||
(if (> (length (get-buffer-window-list (current-buffer) nil t)) 1)
|
(let ((new-dir (doom/project-root)))
|
||||||
(bury-buffer)
|
(if (doom/popup-p (selected-window))
|
||||||
(kill-this-buffer))
|
(doom/popup-close)
|
||||||
(if (doom/popup-p (selected-window))
|
(if (> (length (get-buffer-window-list (current-buffer) nil t)) 1)
|
||||||
(doom/popup-close)
|
(bury-buffer)
|
||||||
(unless (doom/real-buffer-p (current-buffer))
|
(kill-this-buffer))
|
||||||
(doom/previous-real-buffer)
|
(unless (doom/real-buffer-p (current-buffer))
|
||||||
(doom|update-scratch-buffer-cwd new-dir))))))
|
(doom/previous-real-buffer))
|
||||||
|
(when (get-buffer-window-list doom-buffer nil t)
|
||||||
|
(doom|update-scratch-buffer new-dir))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/kill-unreal-buffers ()
|
(defun doom/kill-unreal-buffers ()
|
||||||
|
@ -189,13 +191,18 @@ left, create a scratch buffer."
|
||||||
(cl-incf i)))))
|
(cl-incf i)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/real-buffer-p (&optional buffer-or-name)
|
(defun doom/real-buffer-p (&optional buffer)
|
||||||
(let ((buffer (if buffer-or-name (get-buffer buffer-or-name) (current-buffer))))
|
"Returns whether BUFFER a 'real' buffer or not. Real means it isn't a popup,
|
||||||
(when (buffer-live-p buffer)
|
temporary, scratch or special buffer."
|
||||||
(not (--any? (if (stringp it)
|
(setq buffer (get-buffer (or buffer (current-buffer))))
|
||||||
(string-match-p it (buffer-name buffer))
|
(when (buffer-live-p buffer)
|
||||||
(eq (buffer-local-value 'major-mode buffer) it))
|
(with-current-buffer buffer
|
||||||
doom-unreal-buffers)))))
|
(not (or (apply #'derived-mode-p
|
||||||
|
(-filter 'symbolp doom-unreal-buffers))
|
||||||
|
(--any? (if (stringp it)
|
||||||
|
(string-match-p it (buffer-name buffer))
|
||||||
|
(eq major-mode it))
|
||||||
|
doom-unreal-buffers))))))
|
||||||
|
|
||||||
;; Inspired by spacemacs <https://github.com/syl20bnr/spacemacs/blob/master/spacemacs/funcs.el>
|
;; Inspired by spacemacs <https://github.com/syl20bnr/spacemacs/blob/master/spacemacs/funcs.el>
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -222,7 +229,7 @@ left, create a scratch buffer."
|
||||||
(evil-define-command doom:kill-all-buffers (&optional bang)
|
(evil-define-command doom:kill-all-buffers (&optional bang)
|
||||||
"Kill all project buffers. If BANG, kill *all* buffers (in workgroup)."
|
"Kill all project buffers. If BANG, kill *all* buffers (in workgroup)."
|
||||||
(interactive "<!>")
|
(interactive "<!>")
|
||||||
(doom--kill-buffers (doom/get-buffers (not bang)))
|
(doom--kill-buffers (--filter (eq it doom-buffer) (doom/get-buffers (not bang))))
|
||||||
(mapc (lambda (w) (when (eq (window-buffer w) doom-buffer)
|
(mapc (lambda (w) (when (eq (window-buffer w) doom-buffer)
|
||||||
(delete-window w)))
|
(delete-window w)))
|
||||||
(doom/get-visible-windows)))
|
(doom/get-visible-windows)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue