mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 03:50:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -68,20 +68,19 @@ error if NAME doesn't exist."
|
||||
"Return a list of workspace structs (satisifes `+workspace-p')."
|
||||
;; We don't use `hash-table-values' because it doesn't ensure order in older
|
||||
;; versions of Emacs
|
||||
(cdr (cl-loop for persp being the hash-values of *persp-hash*
|
||||
collect persp)))
|
||||
(cl-loop for name in persp-names-cache
|
||||
if (gethash name *persp-hash*)
|
||||
collect it))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace-list-names ()
|
||||
"Return the list of names of open workspaces."
|
||||
(mapcar #'safe-persp-name (+workspace-list)))
|
||||
persp-names-cache)
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace-buffer-list (&optional persp)
|
||||
"Return a list of buffers in PERSP.
|
||||
|
||||
The buffer list is ordered by recency (same as `buffer-list').
|
||||
|
||||
PERSP can be a string (name of a workspace) or a workspace (satisfies
|
||||
`+workspace-p'). If nil or omitted, it defaults to the current workspace."
|
||||
(let ((persp (or persp (+workspace-current))))
|
||||
@@ -174,11 +173,12 @@ throws an error."
|
||||
(+workspace-new name)
|
||||
(error "%s is not an available workspace" name)))
|
||||
(let ((old-name (+workspace-current-name)))
|
||||
(setq +workspace--last
|
||||
(or (and (not (string= old-name persp-nil-name))
|
||||
old-name)
|
||||
+workspaces-main))
|
||||
(persp-frame-switch name)
|
||||
(unless (equal old-name name)
|
||||
(setq +workspace--last
|
||||
(or (and (not (string= old-name persp-nil-name))
|
||||
old-name)
|
||||
+workspaces-main))
|
||||
(persp-frame-switch name))
|
||||
(equal (+workspace-current-name) name)))
|
||||
|
||||
|
||||
@@ -268,13 +268,20 @@ workspace to delete."
|
||||
('error (+workspace-error ex t))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace/kill-session ()
|
||||
(defun +workspace/kill-session (&optional interactive)
|
||||
"Delete the current session, all workspaces, windows and their buffers."
|
||||
(interactive)
|
||||
(unless (cl-every #'+workspace-delete (+workspace-list-names))
|
||||
(+workspace-error "Could not clear session"))
|
||||
(+workspace-switch +workspaces-main t)
|
||||
(doom/kill-all-buffers (buffer-list)))
|
||||
(interactive (list t))
|
||||
(let ((windows (length (window-list)))
|
||||
(persps (length (+workspace-list-names)))
|
||||
(buffers 0))
|
||||
(let ((persp-autokill-buffer-on-remove t))
|
||||
(unless (cl-every #'+workspace-delete (+workspace-list-names))
|
||||
(+workspace-error "Could not clear session")))
|
||||
(+workspace-switch +workspaces-main t)
|
||||
(setq buffers (doom/kill-all-buffers (buffer-list)))
|
||||
(when interactive
|
||||
(message "Killed %d workspace(s), %d window(s) & %d buffer(s)"
|
||||
persps windows buffers))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace/kill-session-and-quit ()
|
||||
@@ -335,7 +342,8 @@ end of the workspace list."
|
||||
;;;###autoload
|
||||
(dotimes (i 9)
|
||||
(defalias (intern (format "+workspace/switch-to-%d" i))
|
||||
(lambda () (interactive) (+workspace/switch-to i))))
|
||||
(lambda () (interactive) (+workspace/switch-to i))
|
||||
(format "Switch to workspace #%d" (1+ i))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace/switch-to-final ()
|
||||
@@ -396,6 +404,31 @@ the next."
|
||||
|
||||
((+workspace-error "Can't delete last workspace" t)))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace/swap-left (&optional count)
|
||||
"Swap the current workspace with the COUNTth workspace on its left."
|
||||
(interactive "p")
|
||||
(let* ((current-name (+workspace-current-name))
|
||||
(count (or count 1))
|
||||
(index (- (cl-position current-name persp-names-cache :test #'equal)
|
||||
count))
|
||||
(names (remove current-name persp-names-cache)))
|
||||
(unless names
|
||||
(user-error "Only one workspace"))
|
||||
(let ((index (min (max 0 index) (length names))))
|
||||
(setq persp-names-cache
|
||||
(append (cl-subseq names 0 index)
|
||||
(list current-name)
|
||||
(cl-subseq names index))))
|
||||
(when (called-interactively-p 'any)
|
||||
(+workspace/display))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +workspace/swap-right (&optional count)
|
||||
"Swap the current workspace with the COUNTth workspace on its right."
|
||||
(interactive "p")
|
||||
(funcall-interactively #'+workspace/swap-left (- count)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Tabs display in minibuffer
|
||||
@@ -492,32 +525,46 @@ the user to open a file in the new project.
|
||||
This be hooked to `projectile-after-switch-project-hook'."
|
||||
(when dir
|
||||
(setq +workspaces--project-dir dir))
|
||||
(when (and persp-mode +workspaces--project-dir)
|
||||
(unwind-protect
|
||||
(if (and (not (null +workspaces-on-switch-project-behavior))
|
||||
(or (eq +workspaces-on-switch-project-behavior t)
|
||||
(+workspace-buffer-list)))
|
||||
(let* ((persp
|
||||
(let ((project-name (doom-project-name +workspaces--project-dir)))
|
||||
(or (+workspace-get project-name t)
|
||||
(+workspace-new project-name))))
|
||||
(new-name (persp-name persp)))
|
||||
(+workspace-switch new-name)
|
||||
(with-current-buffer (doom-fallback-buffer)
|
||||
(setq default-directory +workspaces--project-dir))
|
||||
(unless current-prefix-arg
|
||||
(funcall +workspaces-switch-project-function +workspaces--project-dir))
|
||||
(+workspace-message
|
||||
(format "Switched to '%s' in new workspace" new-name)
|
||||
'success))
|
||||
(with-current-buffer (doom-fallback-buffer)
|
||||
(setq default-directory +workspaces--project-dir)
|
||||
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
|
||||
(with-demoted-errors "Workspace error: %s"
|
||||
(+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir)))
|
||||
(unless current-prefix-arg
|
||||
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
|
||||
(setq +workspaces--project-dir nil))))
|
||||
;; HACK Clear projectile-project-root, otherwise cached roots may interfere
|
||||
;; with project switch (see #3166)
|
||||
(let (projectile-project-root)
|
||||
(when (and persp-mode +workspaces--project-dir)
|
||||
(when projectile-before-switch-project-hook
|
||||
(with-temp-buffer
|
||||
;; Load the project dir-local variables into the switch buffer, so the
|
||||
;; action can make use of them
|
||||
(setq default-directory +workspaces--project-dir)
|
||||
(hack-dir-local-variables-non-file-buffer)
|
||||
(run-hooks 'projectile-before-switch-project-hook)))
|
||||
(unwind-protect
|
||||
(if (and (not (null +workspaces-on-switch-project-behavior))
|
||||
(or (eq +workspaces-on-switch-project-behavior t)
|
||||
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
|
||||
(+workspace-buffer-list)))
|
||||
(let* ((persp
|
||||
(let ((project-name (doom-project-name +workspaces--project-dir)))
|
||||
(or (+workspace-get project-name t)
|
||||
(+workspace-new project-name))))
|
||||
(new-name (persp-name persp)))
|
||||
(+workspace-switch new-name)
|
||||
(with-current-buffer (doom-fallback-buffer)
|
||||
(setq default-directory +workspaces--project-dir)
|
||||
(hack-dir-local-variables-non-file-buffer))
|
||||
(unless current-prefix-arg
|
||||
(funcall +workspaces-switch-project-function +workspaces--project-dir))
|
||||
(+workspace-message
|
||||
(format "Switched to '%s' in new workspace" new-name)
|
||||
'success))
|
||||
(with-current-buffer (doom-fallback-buffer)
|
||||
(setq default-directory +workspaces--project-dir)
|
||||
(hack-dir-local-variables-non-file-buffer)
|
||||
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
|
||||
(with-demoted-errors "Workspace error: %s"
|
||||
(+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir)))
|
||||
(unless current-prefix-arg
|
||||
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
|
||||
(run-hooks 'projectile-after-switch-project-hook)
|
||||
(setq +workspaces--project-dir nil)))))
|
||||
|
||||
|
||||
;;
|
||||
|
||||
@@ -50,11 +50,13 @@ stored in `persp-save-dir'.")
|
||||
(persp-mode +1)))))
|
||||
:config
|
||||
(setq persp-autokill-buffer-on-remove 'kill-weak
|
||||
persp-reset-windows-on-nil-window-conf nil
|
||||
persp-nil-hidden t
|
||||
persp-auto-save-fname "autosave"
|
||||
persp-save-dir (concat doom-etc-dir "workspaces/")
|
||||
persp-set-last-persp-for-new-frames t
|
||||
persp-switch-to-added-buffer nil
|
||||
persp-kill-foreign-buffer-behaviour 'kill
|
||||
persp-remove-buffers-from-nil-persp-behaviour nil
|
||||
persp-auto-resume-time -1 ; Don't auto-load on startup
|
||||
persp-auto-save-opt (if noninteractive 0 1)) ; auto-save on kill
|
||||
@@ -62,28 +64,36 @@ stored in `persp-save-dir'.")
|
||||
(advice-add #'persp-asave-on-exit :around #'+workspaces-autosave-real-buffers-a)
|
||||
|
||||
(add-hook! '(persp-mode-hook persp-after-load-state-functions)
|
||||
(defun +workspaces-ensure-main-workspace-h (&rest _)
|
||||
"Ensure the main workspace exists and the nil workspace is never active."
|
||||
(defun +workspaces-ensure-no-nil-workspaces-h (&rest _)
|
||||
(when persp-mode
|
||||
(let (persp-before-switch-functions)
|
||||
;; The default perspective persp-mode creates (`persp-nil-name') is
|
||||
;; special and doesn't represent a real persp object, so buffers can't
|
||||
;; really be assigned to it, among other quirks. We create a *real* main
|
||||
;; workspace to fill this role.
|
||||
(unless (persp-get-by-name +workspaces-main)
|
||||
(persp-add-new +workspaces-main))
|
||||
;; Switch to it if we're in the nil perspective
|
||||
(dolist (frame (frame-list))
|
||||
(when (string= (safe-persp-name (get-current-persp frame)) persp-nil-name)
|
||||
(persp-frame-switch +workspaces-main frame)
|
||||
;; Fix #319: the warnings buffer gets swallowed by creating
|
||||
;; `+workspaces-main', so we display it manually, if it exists.
|
||||
(when-let (warnings (get-buffer "*Warnings*"))
|
||||
(save-excursion
|
||||
(display-buffer-in-side-window
|
||||
warnings '((window-height . shrink-window-if-larger-than-buffer)))))))))))
|
||||
(dolist (frame (frame-list))
|
||||
(when (string= (safe-persp-name (get-current-persp frame)) persp-nil-name)
|
||||
;; Take extra steps to ensure no frame ends up in the nil perspective
|
||||
(persp-frame-switch (or (cadr (hash-table-keys *persp-hash*))
|
||||
+workspaces-main)
|
||||
frame))))))
|
||||
|
||||
(add-hook! 'persp-mode-hook
|
||||
(defun +workspaces-init-first-workspace-h (&rest _)
|
||||
"Ensure a main workspace exists."
|
||||
(when persp-mode
|
||||
(let (persp-before-switch-functions)
|
||||
;; The default perspective persp-mode creates is special and doesn't
|
||||
;; represent a real persp object, so buffers can't really be assigned
|
||||
;; to it, among other quirks, so we get rid of it...
|
||||
(when (equal (car persp-names-cache) persp-nil-name)
|
||||
(pop persp-names-cache))
|
||||
;; ...and create a *real* main workspace to fill this role.
|
||||
(unless (or (persp-get-by-name +workspaces-main)
|
||||
;; Start from 2 b/c persp-mode counts the nil workspace
|
||||
(> (hash-table-count *persp-hash*) 2))
|
||||
(persp-add-new +workspaces-main))
|
||||
;; HACK Fix #319: the warnings buffer gets swallowed when creating
|
||||
;; `+workspaces-main', so display it ourselves, if it exists.
|
||||
(when-let (warnings (get-buffer "*Warnings*"))
|
||||
(save-excursion
|
||||
(display-buffer-in-side-window
|
||||
warnings '((window-height . shrink-window-if-larger-than-buffer))))))))
|
||||
(defun +workspaces-init-persp-mode-h ()
|
||||
(cond (persp-mode
|
||||
;; `uniquify' breaks persp-mode. It renames old buffers, which causes
|
||||
@@ -108,15 +118,15 @@ stored in `persp-save-dir'.")
|
||||
;; add buffers when they are switched to.
|
||||
(setq persp-add-buffer-on-find-file nil
|
||||
persp-add-buffer-on-after-change-major-mode nil)
|
||||
|
||||
(add-hook! '(doom-switch-buffer-hook server-visit-hook)
|
||||
(defun +workspaces-add-current-buffer-h ()
|
||||
"Add current buffer to focused perspective."
|
||||
(and persp-mode
|
||||
(not (persp-buffer-filtered-out-p
|
||||
(current-buffer)
|
||||
persp-add-buffer-on-after-change-major-mode-filter-functions))
|
||||
(persp-add-buffer (current-buffer) (get-current-persp) nil nil))))
|
||||
(or (not persp-mode)
|
||||
(persp-buffer-filtered-out-p
|
||||
(or (buffer-base-buffer (current-buffer))
|
||||
(current-buffer))
|
||||
persp-add-buffer-on-after-change-major-mode-filter-functions)
|
||||
(persp-add-buffer (current-buffer) (get-current-persp) nil nil))))
|
||||
|
||||
(add-hook 'persp-add-buffer-on-after-change-major-mode-filter-functions
|
||||
#'doom-unreal-buffer-p)
|
||||
@@ -171,7 +181,10 @@ stored in `persp-save-dir'.")
|
||||
("xt" counsel-projectile-switch-project-action-run-term "invoke term from project root")
|
||||
("X" counsel-projectile-switch-project-action-org-capture "org-capture into project")))
|
||||
|
||||
(add-hook 'projectile-after-switch-project-hook #'+workspaces-switch-to-project-h)
|
||||
(when (featurep! :completion helm)
|
||||
(after! helm-projectile
|
||||
(setcar helm-source-projectile-projects-actions
|
||||
'("Switch to Project" . +workspaces-switch-to-project-h))))
|
||||
|
||||
;; Fix #1973: visual selection surviving workspace changes
|
||||
(add-hook 'persp-before-deactivate-functions #'deactivate-mark)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; ui/workspaces/packages.el
|
||||
|
||||
(package! persp-mode)
|
||||
|
||||
(package! persp-mode :pin "391a7dc248c9c04b7ad424c696bdff578e14dd2c")
|
||||
|
||||
Reference in New Issue
Block a user