Skip to content

MArpogaus/auto-tab-groups

Repository files navigation

https://img.shields.io/github/contributors/MArpogaus/auto-tab-groups.svg?style=flat-square https://img.shields.io/github/forks/MArpogaus/auto-tab-groups.svg?style=flat-square https://img.shields.io/github/stars/MArpogaus/auto-tab-groups.svg?style=flat-square https://img.shields.io/github/issues/MArpogaus/auto-tab-groups.svg?style=flat-square https://img.shields.io/github/license/MArpogaus/auto-tab-groups.svg?style=flat-square https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555

auto tab groups

About The Project

This package provides automated tab group management for Emacs, allowing you to associate commands with specific tab groups. Heavily inspired by project-tab-groups.el, this package generalizes the concept to arbitrary commands, providing a more flexible approach to organizing your Emacs workflow. It automatically switches to or creates tab groups when specified commands are invoked, streamlining navigation and buffer management. This package has been implemented with simplicity in mind. It is a very thin layer that leverages Emacs’ tab bar mode for a user-defined workflow, adding very little complexity to it. All the heavy lifting is done by tab-bar.el. Please refer to the documentation to learn about tab bar related commands. An optional “eye-candy” mode is provided for enhanced tab bar styling. However, by default, any further tab bar related configurations are handed to the user.

Result with the example configuration provided below:

screenshot.png

Getting Started

Prerequisites

  • Emacs 28.1 or later, including tab-bar.el and project.el.
  • optionally nerd-icons for build id “eye-candy” mode

Installation

Complete configuration example using straight.el

(use-package auto-tab-groups
  :straight (:host github :repo "MArpogaus/auto-tab-groups")
  :after tab-bar project nerd-icons
  :custom
  ;; Automatically create tabs for denote, dirvish and customize buffers
  (auto-tab-groups-create-commands
   '(((denote-create-note denote-menu-list-notes consult-denote-find consult-denote-grep) . "denote")
     ((custom-buffer-create-internal) . "customize")
     ((dirvish dirvish-fd) . "dirvish")))
  (auto-tab-groups-close-commands
   '((dirvish-quit "dirvish" :ignore-result t)
     (Custom-buffer-done "customize" :ignore-result t)))
  ;; Customize height of tabs
  (auto-tab-groups-eyecandy-tab-height 25)
  ;; Define tab group icons (requires nerd-icons)
  (auto-tab-groups-eyecandy-icons
   '(("HOME"       . (:style "suc" :icon "custom-emacs"))
     ("dirvish"    . (:style "suc" :icon "custom-folder_oct"))
     ("denote"     . (:style "md"  :icon "notebook_edit"))
     ("customize"  . (:style "cod" :icon "settings"))
     ("^\\[P\\] *" . (:style "oct" :icon "repo"))
     ("^\\[T\\] *" . (:style "cod" :icon "remote"))))
  ;; Remove prefix from project groups
  (auto-tab-groups-eyecandy-tab-bar-group-name-format-function
   (lambda (tab-group-name)
     (if (string-match "^\\[.\\] *" tab-group-name)
         (substring tab-group-name (match-end 0))
       tab-group-name)))
  :bind
  ("<your-binding>" . auto-tab-groups-new-group)
  :init
  ;; automatically assign projects to groups
  (auto-tab-groups-project-mode)
  ;; Enable modern tabs style
  (auto-tab-groups-eyecandy-mode)
  ;; Enable automatic tab group management based on the rules defined above
  (auto-tab-groups-mode)
  :hook
  ;; HACK: Re-nable eyecandy mode after tab-bar-mode has been disabled
  (tab-bar-mode . auto-tab-groups-eyecandy-mode))

Manual Installation

  1. Download auto-tab-groups.el, auto-tab-groups-project.el and auto-tab-groups-eyecandy.el.
  2. Place them in your Emacs load-path.
  3. Add the following to your init file:
    (require 'auto-tab-groups)
    (auto-tab-groups-mode 1)
        

If you don’t want to enable the provided eye-candy mode for tab bar styling, you might at least want to display the tab groups, by customizing tab-bar-format:

(setq tab-bar-format '(tab-bar-format-tabs-groups
                       ;;... additional format functions
                       ))

Please refer to the documentation of tab-bar-mode for details.

Usage

auto-tab-groups helps to implement automatic task separation, using build in tab bar groups. A call of a elisp function defined in auto-tab-groups-create-commands will create a new group or switch to an existing one with the given name. A call of a elisp function defined in auto-tab-groups-close-commands will close the corresponding group and all tabs belonging to it.

The package itself provides only a single user facing command auto-tab-groups-new-group for the convenient creation of new groups. It is not planed to extend its functionality any further and instead keep the code base as small and stable as possible. All commands for managing tabs and tab groups are provided by tab-bar.el.

Customization

auto-tab-groups

You can customize the behavior of auto-tab-groups using the following options:

OptionTypeDescription
auto-tab-groups-create-commandsalistCommands to trigger tab group creation or switching.
auto-tab-groups-close-commandsalistCommands to trigger tab group closure.
auto-tab-groups-new-choicemultipleAdjust the behavior when new tab is created.
auto-tab-groups-initial-group-namestringSpecify the name of the initial tab group.
auto-tab-groups-before-create-hookhookHook run before tab group creation.
auto-tab-groups-after-create-hookhookHook run after tab group creation.
auto-tab-groups-before-delete-hookhookHook run before tab group deletion.
auto-tab-groups-after-delete-hookhookHook run after tab group deletion.

auto-tab-groups-create-commands and auto-tab-groups-close-commands are alists where:

  • CAR: command (symbol) or list of commands.
  • CDR: tab group name (string) or function returning a string.

For create-commands, the CDR can be a function that receives the command’s result. The tab group is created if it doesn’t exist, otherwise, Emacs switches to it. close-commands work similarly, closing the specified tab group after the command is run.

auto-tab-groups-project

This package provides a minor mode to integrate with project.el, similar to project-tab-groups.el, simply enable it with:

(auto-tab-groups-project-mode)

or

(setq auto-tab-groups-project-mode 1)

This mode dos currently not offer any customization.

auto-tab-groups-eyecandy

The auto-tab-groups-eyecandy minor mode provides additional customization options for enhanced tab bar styling:

OptionTypeDescription
auto-tab-groups-eyecandy-iconsalistMap tab group names to icons.
auto-tab-groups-eyecandy-tab-heightnumberTab height in pixels.
auto-tab-groups-eyecandy-default-iconstringDefault icon for tab groups.

auto-tab-groups-eyecandy-icons is an alist where:

  • CAR: tab group name (string) or predicate function.
  • CDR: icon string.

Alternative Packages

  • tabspaces, to leverage the Emacs tab bar and the Emacs built-in project.el to create buffer-isolated workspaces that also integrate with version-controlled projects.
  • project-tab-groups, implements automatic management of tab groups in the context of project.el-based projects only. If you just want project isolation, use this.
  • activities, which allows the user to manage frames/tabs, windows, and buffers according to their purpose.

Contributing

Any Contributions are greatly appreciated!

License

Distributed under the GPLv3 License.

Contact

Marcel Arpogaus - [email protected] (encrypted with [ROT13](https://rot13.com/))

Project Link: https://github.com/MArpogaus/auto-tab-groups

Acknowledgments

About

Simple auto tab group creator for specified commands

Resources

License

Stars

Watchers

Forks

Packages

No packages published