Refactor & reformat core-ui
This commit is contained in:
parent
64a88385cb
commit
4618b7afad
3 changed files with 100 additions and 89 deletions
|
@ -199,12 +199,58 @@ regex PATTERN. Returns the number of killed buffers."
|
|||
;; Hooks
|
||||
;;
|
||||
|
||||
;;;###autoload
|
||||
(defun doom|protect-visible-buffer ()
|
||||
"Don't kill the current buffer if it is visible in another window (bury it
|
||||
instead). Meant for `kill-buffer-query-functions'."
|
||||
(not (and (delq (selected-window) (get-buffer-window-list nil nil t))
|
||||
(not (member (substring (buffer-name) 0 1) '(" " "*"))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom|protect-fallback-buffer ()
|
||||
"Don't kill the scratch buffer. Meant for `kill-buffer-query-functions'."
|
||||
(not (eq (current-buffer) (doom-fallback-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom|mark-buffer-as-real ()
|
||||
"Hook function that marks the current buffer as real."
|
||||
(doom-set-buffer-real (current-buffer) t))
|
||||
|
||||
|
||||
;;
|
||||
;; Advice
|
||||
;;
|
||||
|
||||
;;;###autoload
|
||||
(defun doom*switch-to-fallback-buffer-maybe (orig-fn)
|
||||
"Advice for `kill-this-buffer'. If in a dedicated window, delete it. If there
|
||||
are no real buffers left OR if all remaining buffers are visible in other
|
||||
windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
|
||||
`kill-this-buffer'."
|
||||
(let ((buf (current-buffer)))
|
||||
(cond ((window-dedicated-p)
|
||||
(delete-window))
|
||||
((eq buf (doom-fallback-buffer))
|
||||
(message "Can't kill the fallback buffer."))
|
||||
((doom-real-buffer-p buf)
|
||||
(if (and buffer-file-name
|
||||
(buffer-modified-p buf)
|
||||
(not (y-or-n-p
|
||||
(format "Buffer %s is modified; kill anyway?" buf))))
|
||||
(message "Aborted")
|
||||
(set-buffer-modified-p nil)
|
||||
(when (or ;; if there aren't more real buffers than visible buffers,
|
||||
;; then there are no real, non-visible buffers left.
|
||||
(not (cl-set-difference (doom-real-buffer-list)
|
||||
(doom-visible-buffers)))
|
||||
;; if we end up back where we start (or previous-buffer
|
||||
;; returns nil), we have nowhere left to go
|
||||
(memq (previous-buffer) (list buf 'nil)))
|
||||
(switch-to-buffer (doom-fallback-buffer)))
|
||||
(kill-buffer buf)))
|
||||
((funcall orig-fn)))))
|
||||
|
||||
|
||||
;;
|
||||
;; Interactive commands
|
||||
;;
|
||||
|
|
|
@ -136,3 +136,10 @@ are open."
|
|||
(or (yes-or-no-p (format "››› %s" (or prompt "Quit Emacs?")))
|
||||
(ignore (message "Aborted")))
|
||||
t))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom|apply-ansi-color-to-compilation-buffer ()
|
||||
"Applies ansi codes to the compilation buffers. Meant for
|
||||
`compilation-filter-hook'."
|
||||
(with-silent-modifications
|
||||
(ansi-color-apply-on-region compilation-filter-start (point))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue