magit-section

Create interactive hierarchical collapsible section-based UIs in Emacs buffers.

3|Updated Nov 10, 2025
One-click install
npx skills add https://github.com/hugoduncan/library-skills --skill magit-section
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: magit-section
Source: https://github.com/hugoduncan/library-skills/tree/main/plugins/emacs-libraries/skills/magit-section
Command: npx skills add https://github.com/hugoduncan/library-skills --skill magit-section

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

magit-section provides a robust framework for building tree-like, collapsible buffers with sections that can contain nested content, navigation, and per-section behavior—ideal for complex interfaces like Magit's.

Core Features & Use Cases

  • Hierarchical Sections: Create nested sections with headings and bodies.
  • Visibility & Caching: Collapse/expand sections with caching of visibility state.
  • Navigation & Actions: Built-in movement and per-section keymaps for custom actions.
  • Data Association: Attach arbitrary values to sections for rich interactivity.
  • Use Cases: File browsers, log viewers, configuration inspectors, and custom UIs.

Quick Start

To begin:

  • Require the library: (require 'magit-section)
  • Create a root section and nested sections:
    (magit-insert-section (root)
      (magit-insert-heading "Root")
      (magit-insert-section (child "child-1")
        (magit-insert-heading "Child 1")
        (insert "Content here")))
    
  • Navigate with TAB to toggle visibility or use movement commands like magit-section-forward/ backward.

Frequently Asked Questions about magit-section

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create collapsible sections in Emacs buffers?

Collapsible sections in Emacs buffers are created using magit-section's hierarchical framework. Use `magit-insert-section` to define nested sections with headings and bodies, then toggle visibility with `TAB` or movement commands. This enables interactive tree-like UIs for file browsers, log viewers, and custom interfaces.

Can I attach custom data and keymaps to individual sections?

Yes, magit-section supports per-section keymaps and arbitrary data association. Attach values to sections to enable rich interactivity and custom actions on specific content areas. This allows building responsive UIs where each section responds to navigation and keyboard input independently.

How does visibility state persist across buffer refreshes?

magit-section caches visibility state so expanded or collapsed sections retain their state when the buffer refreshes. This persistence eliminates lost context during navigation and content updates, critical for long-lived buffers like file explorers and log viewers.

What's the best way to build tree-like UIs in Emacs?

Building tree-like UIs in Emacs requires a hierarchical section framework with nested content, per-section navigation, and visibility controls. magit-section provides all these primitives—section creation, visibility toggling, keymaps, and data storage—in a single cohesive library designed for complex interactive buffers.

Do I need prior Emacs Lisp experience to use magit-section?

magit-section is an advanced library requiring Emacs Lisp proficiency to implement custom UIs. The framework handles section rendering, visibility, and navigation; you define section structure and content. Familiarity with Emacs buffer manipulation and keymaps accelerates development.

Can magit-section handle deeply nested hierarchies with many sections?

magit-section supports arbitrarily deep nesting and handles large hierarchies through deferred body evaluation and efficient visibility caching. Sections only render visible content, making it suitable for explorers and inspectors presenting thousands of nested items without performance degradation.