doomemacs/core/defuns/defuns-workgroup.el

195 lines
7.4 KiB
EmacsLisp
Raw Normal View History

2015-06-15 09:05:52 +02:00
;;; defuns-workgroup.el
2016-04-20 21:36:32 -04:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom|wg-cleanup ()
(doom/popup-close-all)
2016-04-20 21:36:32 -04:00
(when (and (featurep 'neotree) (neo-global--window-exists-p))
(neotree-hide)))
2015-06-15 09:05:52 +02:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/wg-projectile-switch-project ()
(let ((project-root (doom/project-root)))
(doom:workgroup-new nil (file-name-nondirectory (directory-file-name project-root)) t)
2016-10-05 12:48:12 +02:00
(doom-reload-scratch-buffer project-root)
(when (featurep 'neotree)
(neotree-projectile-action))))
2015-06-15 09:05:52 +02:00
;;;###autoload (autoload 'doom:workgroup-save "defuns-workgroup" nil t)
(evil-define-command doom:workgroup-save (&optional bang session-name)
2016-04-12 15:56:04 -04:00
(interactive "<!><a>")
(unless (wg-workgroup-list)
(wg-create-workgroup wg-first-wg-name))
2016-05-20 22:37:30 -04:00
(doom|wg-cleanup)
(wg-save-session-as (if session-name
(concat wg-workgroup-directory session-name)
2016-04-12 15:56:04 -04:00
(if bang
2016-05-20 22:37:30 -04:00
(concat wg-workgroup-directory (f-filename (doom/project-root)))
2016-04-12 15:56:04 -04:00
wg-session-file))))
2015-06-15 09:05:52 +02:00
;;;###autoload (autoload 'doom:workgroup-load "defuns-workgroup" nil t)
(evil-define-command doom:workgroup-load (&optional bang session-name)
2016-04-12 15:56:04 -04:00
(interactive "<!><a>")
(let ((session-file (if session-name
(concat wg-workgroup-directory session-name)
2016-05-20 22:37:30 -04:00
(let ((sess (concat wg-workgroup-directory (f-filename (doom/project-root)))))
2016-04-12 15:56:04 -04:00
(if bang
(when (file-exists-p sess)
sess)
wg-session-file)))))
(unless session-file
(user-error "No session found"))
(wg-open-session session-file))
2016-05-20 22:37:30 -04:00
(doom/workgroup-display t))
2015-06-15 09:05:52 +02:00
2016-03-03 01:36:42 -05:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/clear-sessions ()
2016-03-03 01:36:42 -05:00
"Delete all session files."
(interactive)
(mapc 'delete-file (f-glob (expand-file-name "*" wg-workgroup-directory))))
2016-05-20 22:37:30 -04:00
;;;###autoload (autoload 'doom:workgroup-new "defuns-workgroup" nil t)
(evil-define-command doom:workgroup-new (bang name &optional silent)
2016-03-23 11:51:29 -04:00
"Create a new workgroup. If BANG, overwrite any workgroup named NAME."
2015-06-15 09:05:52 +02:00
(interactive "<!><a>")
(unless name
(setq name (format "#%s" (1+ (length (wg-session-workgroup-list (wg-current-session t)))))))
2016-03-03 01:36:42 -05:00
(let ((new-wg (wg-get-workgroup name t)))
(when (and new-wg bang)
2016-04-12 15:56:04 -04:00
(wg-delete-workgroup new-wg)
(setq new-wg nil))
(setq new-wg (or new-wg (wg-make-and-add-workgroup name t)))
2016-05-20 22:37:30 -04:00
(add-to-list 'doom-wg-names (wg-workgroup-uid new-wg))
2016-03-03 01:36:42 -05:00
(wg-switch-to-workgroup new-wg))
(unless silent
2016-05-20 22:37:30 -04:00
(doom--workgroup-display (wg-previous-workgroup t)
NARF v0.7.0 vcs: + +git-gutter to conf-modes; -git-gutter from evil-insert-state-exit + switch github-browse-file for browse-at-remote + fix <leader>ob; add <leader>d[./sr] vc bindings + vc-annotate bindings and initial state Workgroups2 integration: + don't mess with buffers (speeds up emacs a lot!) + unicode numbers in display + single display function + remember workgroup uid instead (and smarter :tabrename) + clean up after wg update Org-mode + give highlight precedence to links in org-mode + enable encryption + config clean up + use different font for org + exclude attachments in recentf + redo latex and inline-image config + add narf/org-open-notes + update file templates for org CRM Mode-line + polish mode-line + decouple from spaceline-segments.el + refactor narf|spaceline-env-update + add macro-recording and buffer-size indicators to mode-line + python: '2>&1' in env-command + flycheck fringe indicator: change to arrow Aesthetics + update narf-dark-theme + add narf-minibuffer-active face + change writing indicator in writing-mode Misc + fix whitespace in display-startup-echo-area-message + reset fonts for more unicode characters + custom imenu entries + helm-imenu fontification + enable yascroll-bar in REPLs + reorganize my-commands.el + force quit iedit on ESC in normal mode + update snippets submodule + remove ido init (helm handles it all) [EXPERIMENTAL] + back to Terminus(TTF) font + popwin: update config for git-gutter and vc-diff windows + highlight :g[lobal] and :al[ign] matches + decouple narf/get-buffers+narf/get-all-buffers from wg-mess-with-buffer-list + fix narf/helm-buffers-dwim (add interactive form)
2015-12-11 16:51:04 -05:00
(format "Created %s" name)
'success)))
2015-06-15 09:05:52 +02:00
2016-05-20 22:37:30 -04:00
;;;###autoload (autoload 'doom:workgroup-rename "defuns-workgroup" nil t)
(evil-define-command doom:workgroup-rename (bang &optional new-name)
NARF v0.7.0 vcs: + +git-gutter to conf-modes; -git-gutter from evil-insert-state-exit + switch github-browse-file for browse-at-remote + fix <leader>ob; add <leader>d[./sr] vc bindings + vc-annotate bindings and initial state Workgroups2 integration: + don't mess with buffers (speeds up emacs a lot!) + unicode numbers in display + single display function + remember workgroup uid instead (and smarter :tabrename) + clean up after wg update Org-mode + give highlight precedence to links in org-mode + enable encryption + config clean up + use different font for org + exclude attachments in recentf + redo latex and inline-image config + add narf/org-open-notes + update file templates for org CRM Mode-line + polish mode-line + decouple from spaceline-segments.el + refactor narf|spaceline-env-update + add macro-recording and buffer-size indicators to mode-line + python: '2>&1' in env-command + flycheck fringe indicator: change to arrow Aesthetics + update narf-dark-theme + add narf-minibuffer-active face + change writing indicator in writing-mode Misc + fix whitespace in display-startup-echo-area-message + reset fonts for more unicode characters + custom imenu entries + helm-imenu fontification + enable yascroll-bar in REPLs + reorganize my-commands.el + force quit iedit on ESC in normal mode + update snippets submodule + remove ido init (helm handles it all) [EXPERIMENTAL] + back to Terminus(TTF) font + popwin: update config for git-gutter and vc-diff windows + highlight :g[lobal] and :al[ign] matches + decouple narf/get-buffers+narf/get-all-buffers from wg-mess-with-buffer-list + fix narf/helm-buffers-dwim (add interactive form)
2015-12-11 16:51:04 -05:00
(interactive "<!><a>")
(let* ((wg (wg-current-workgroup))
(wg-uid (wg-workgroup-uid wg))
(old-name (wg-workgroup-name wg)))
(if bang
2016-05-20 22:37:30 -04:00
(setq doom-wg-names (delete wg-uid doom-wg-names))
NARF v0.7.0 vcs: + +git-gutter to conf-modes; -git-gutter from evil-insert-state-exit + switch github-browse-file for browse-at-remote + fix <leader>ob; add <leader>d[./sr] vc bindings + vc-annotate bindings and initial state Workgroups2 integration: + don't mess with buffers (speeds up emacs a lot!) + unicode numbers in display + single display function + remember workgroup uid instead (and smarter :tabrename) + clean up after wg update Org-mode + give highlight precedence to links in org-mode + enable encryption + config clean up + use different font for org + exclude attachments in recentf + redo latex and inline-image config + add narf/org-open-notes + update file templates for org CRM Mode-line + polish mode-line + decouple from spaceline-segments.el + refactor narf|spaceline-env-update + add macro-recording and buffer-size indicators to mode-line + python: '2>&1' in env-command + flycheck fringe indicator: change to arrow Aesthetics + update narf-dark-theme + add narf-minibuffer-active face + change writing indicator in writing-mode Misc + fix whitespace in display-startup-echo-area-message + reset fonts for more unicode characters + custom imenu entries + helm-imenu fontification + enable yascroll-bar in REPLs + reorganize my-commands.el + force quit iedit on ESC in normal mode + update snippets submodule + remove ido init (helm handles it all) [EXPERIMENTAL] + back to Terminus(TTF) font + popwin: update config for git-gutter and vc-diff windows + highlight :g[lobal] and :al[ign] matches + decouple narf/get-buffers+narf/get-all-buffers from wg-mess-with-buffer-list + fix narf/helm-buffers-dwim (add interactive form)
2015-12-11 16:51:04 -05:00
(unless new-name
(user-error "You didn't enter in a name"))
(wg-rename-workgroup new-name wg)
2016-05-20 22:37:30 -04:00
(add-to-list 'doom-wg-names wg-uid)
(doom--workgroup-display wg (format "Renamed '%s'->'%s'" old-name new-name) 'success))))
2015-06-15 09:05:52 +02:00
2016-05-20 22:37:30 -04:00
;;;###autoload (autoload 'doom:workgroup-delete "defuns-workgroup" nil t)
(evil-define-command doom:workgroup-delete (&optional bang name)
(interactive "<!><a>")
(let* ((current-wg (wg-current-workgroup))
(wg-name (or name (wg-workgroup-name current-wg))))
(when bang
(setq wg-name (wg-read-workgroup-name)))
(let ((wg (wg-get-workgroup name)))
2016-05-20 22:37:30 -04:00
(setq doom-wg-names (delete (wg-workgroup-uid wg) doom-wg-names))
(if (eq wg current-wg)
(wg-kill-workgroup)
(wg-delete-workgroup wg))
2016-05-20 22:37:30 -04:00
(doom--workgroup-display nil (format "Deleted %s" wg-name) 'success))))
2015-06-15 09:05:52 +02:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom:kill-other-workgroups ()
2015-06-15 09:05:52 +02:00
"Kill all other workgroups."
(interactive)
(let (workgroup (wg-current-workgroup))
(dolist (w (wg-session-workgroup-list (wg-current-session t)))
2015-06-15 09:05:52 +02:00
(unless (wg-current-workgroup-p w)
(wg-kill-workgroup w)))))
2016-05-20 22:37:30 -04:00
(defun doom--workgroup-display (&optional suppress-update message message-face)
(message "%s%s" (doom/workgroup-display suppress-update t)
NARF v0.7.0 vcs: + +git-gutter to conf-modes; -git-gutter from evil-insert-state-exit + switch github-browse-file for browse-at-remote + fix <leader>ob; add <leader>d[./sr] vc bindings + vc-annotate bindings and initial state Workgroups2 integration: + don't mess with buffers (speeds up emacs a lot!) + unicode numbers in display + single display function + remember workgroup uid instead (and smarter :tabrename) + clean up after wg update Org-mode + give highlight precedence to links in org-mode + enable encryption + config clean up + use different font for org + exclude attachments in recentf + redo latex and inline-image config + add narf/org-open-notes + update file templates for org CRM Mode-line + polish mode-line + decouple from spaceline-segments.el + refactor narf|spaceline-env-update + add macro-recording and buffer-size indicators to mode-line + python: '2>&1' in env-command + flycheck fringe indicator: change to arrow Aesthetics + update narf-dark-theme + add narf-minibuffer-active face + change writing indicator in writing-mode Misc + fix whitespace in display-startup-echo-area-message + reset fonts for more unicode characters + custom imenu entries + helm-imenu fontification + enable yascroll-bar in REPLs + reorganize my-commands.el + force quit iedit on ESC in normal mode + update snippets submodule + remove ido init (helm handles it all) [EXPERIMENTAL] + back to Terminus(TTF) font + popwin: update config for git-gutter and vc-diff windows + highlight :g[lobal] and :al[ign] matches + decouple narf/get-buffers+narf/get-all-buffers from wg-mess-with-buffer-list + fix narf/helm-buffers-dwim (add interactive form)
2015-12-11 16:51:04 -05:00
(propertize message 'face message-face)))
2015-09-30 13:50:30 -04:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/workgroup-display (&optional suppress-update return-p message)
2015-09-30 13:50:30 -04:00
(interactive)
(awhen (wg-current-session t)
(unless (eq suppress-update t)
2016-05-20 22:37:30 -04:00
(doom/workgroup-update-names (if (wg-workgroup-p suppress-update) suppress-update)))
(let ((output (wg-display-internal
(lambda (workgroup index)
(if (not workgroup) wg-nowg-string
(wg-element-display
workgroup
(format " [%d] %s " (1+ index) (wg-workgroup-name workgroup))
'wg-current-workgroup-p)))
(wg-session-workgroup-list it))))
(if return-p
output
(message "%s%s" output (or message ""))))))
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/workgroup-update-names (&optional wg)
(let ((wg (or wg (wg-current-workgroup))))
2016-05-20 22:37:30 -04:00
(unless (member (wg-workgroup-uid wg) doom-wg-names)
(ignore-errors
(let ((old-name (wg-workgroup-name wg))
2016-05-20 22:37:30 -04:00
(new-name (f-filename (doom/project-root))))
(unless (string= new-name old-name)
(wg-rename-workgroup new-name wg)))))))
2016-05-20 22:37:30 -04:00
(defun doom--switch-to-workgroup (direction &optional count)
(interactive "<c>")
(assert (memq direction '(left right)))
(condition-case err
(progn
(if count
(wg-switch-to-workgroup-at-index (1- count))
(funcall (intern (format "wg-switch-to-workgroup-%s" direction))))
2016-05-20 22:37:30 -04:00
(doom/workgroup-display t))
(error (doom/workgroup-display t nil (format "Nope! %s" (cadr err))))))
2015-09-30 13:50:30 -04:00
2016-05-20 22:37:30 -04:00
;;;###autoload (autoload 'doom:switch-to-workgroup-left "defuns-workgroup" nil t)
(evil-define-command doom:switch-to-workgroup-left (count)
2015-09-30 13:50:30 -04:00
(interactive "<c>")
2016-05-20 22:37:30 -04:00
(doom--switch-to-workgroup 'left))
2015-09-30 13:50:30 -04:00
2016-05-20 22:37:30 -04:00
;;;###autoload (autoload 'doom:switch-to-workgroup-right "defuns-workgroup" nil t)
(evil-define-command doom:switch-to-workgroup-right (count)
2015-09-30 13:50:30 -04:00
(interactive "<c>")
2016-05-20 22:37:30 -04:00
(doom--switch-to-workgroup 'right))
2015-09-30 13:50:30 -04:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom:switch-to-workgroup-at-index (index)
2015-09-30 13:50:30 -04:00
(interactive)
2016-05-20 22:37:30 -04:00
(doom/workgroup-update-names)
(let ((wg (nth index (wg-workgroup-list-or-error)))
msg)
(if wg
(unless (eq wg (wg-current-workgroup t))
(wg-switch-to-workgroup-at-index index))
(setq msg (format "No tab #%s" (1+ index))))
2016-05-20 22:37:30 -04:00
(doom/workgroup-display t nil msg)))
2015-09-30 13:50:30 -04:00
2015-11-21 16:22:40 -05:00
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/undo-window-change ()
2015-11-21 16:22:40 -05:00
(interactive)
(call-interactively (if (wg-current-workgroup t) 'wg-undo-wconfig-change 'winner-undo)))
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/redo-window-change ()
2015-11-21 16:22:40 -05:00
(interactive)
(call-interactively (if (wg-current-workgroup t) 'wg-redo-wconfig-change 'winner-redo)))
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/close-window-or-workgroup ()
(interactive)
(if (doom/popup-p)
2016-05-20 22:37:30 -04:00
(doom/popup-close)
(when (doom/kill-real-buffer)
(if (and (one-window-p t)
(> (length (wg-workgroup-list)) 1))
(if (string= (wg-workgroup-name (wg-current-workgroup)) wg-first-wg-name)
(evil-window-delete)
(doom:workgroup-delete))
(evil-window-delete)))))
2015-06-15 09:05:52 +02:00
(provide 'defuns-workgroup)
;;; defuns-workgroup.el ends here