;;; ymh-tabs.el --- Extensions to organising tabs -*- lexical-binding: t; -*- ;;; Commentary: ;; Initially inspired by ;; https://mihaiolteanu.me/emacs-workspace-management.html. ;;; Code: (defun ymh-tabs--create (name) "Create the NAME tab if it doesn't exist already." (condition-case nil (unless (equal (alist-get 'name (tab-bar--current-tab)) name) (tab-bar-rename-tab-by-name name name) nil) (error (tab-new) (tab-bar-rename-tab name) t))) (defun ymh-tabs--get-name-from-path (dir) "Get a tab name from a project path DIR." (file-name-base (directory-file-name dir))) (defun ymh-tabs-switch-project (dir) "\"Switch\" to another project by running an Emacs command. The available commands are presented as a dispatch menu made from `project-switch-commands'. When called in a program, it will use the project corresponding to directory DIR." (interactive (list (project-prompt-project-dir))) (let ((proj-name (ymh-tabs--get-name-from-path dir))) (if (ymh-tabs--create proj-name) (project-switch-project dir) (tab-bar-switch-to-tab proj-name)))) (provide 'ymh-tabs) ;;; ymh-tabs.el ends here