Skip to content

Emacs: Display a buffer's project in its mode line (rendered obsolete in Emacs 30)

License

Notifications You must be signed in to change notification settings

fritzgrabo/project-mode-line-tag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ Emacs 30 adds the project-mode-line facility, which renders this package obsolete.

project-mode-line-tag.el

Provides a global minor mode to display information about a buffer’s project (a “project tag”) in its mode line.

To derive a buffer’s project tag, we first look for dir-local variables named project-mode-line-tag or project-name. If none of these are set, we call the project-name function if it exists (Emacs 29), and fall back to the project’s directory name (e.g. bar for /code/foo/bar) otherwise.

In addition, if one of project-mode-line-tag-template or project-name-template is present, it is used as the format-string in a call to format to further customize the project tag. The format-string is expected to have a single %s sequence which will be substituted with the current project tag. This can be useful if you want to have all projects in a directory share a common prefix, for example.

Installation

If you use MELPA, an easy way to install this package is via package-install. Alternatively, download project-mode-line-tag.el, put it in your load-path and require it. Finally, use (project-mode-line-tag-mode 1) or M-x project-mode-line-tag-mode to turn on the provided minor mode.

If you use both MELPA and use-package, you can use this, too:

(use-package project-mode-line-tag
  :ensure
  :config
  (project-mode-line-tag-mode 1))

Screenshot

Showing 3 windows; from top to bottom:

  • Project tag project-mode-line-tag derived from its buffer’s related project.el project’s root directory.
  • Project tag foobar derived from the project-name dir-local variable that applies to its buffer.
  • None of the above, so no project tag.

screenshots/project-mode-line-tag.png

The face applied to the project tag and the format of how to display it in the mode line are fully customizable.

Related packages

  • Check out the cascading-dir-locals package if you want to use nested dir-local variables.
  • The tab-bar-groups package integrates with this package and applies the current tab bar group’s color to the project tag in the mode line. You might want to use this in combination with the project-tab-groups package if you follow a “one tab group per project” workflow.

About

Emacs: Display a buffer's project in its mode line (rendered obsolete in Emacs 30)

Resources

License

Stars

Watchers

Forks