Skip to content

Key buffer reuse on structured identities - #625

Merged
dakra merged 2 commits into
mainfrom
feat/structured-identity
Aug 12, 2026
Merged

dakra merged 2 commits into
mainfrom
feat/structured-identity

Conversation

@dakra

@dakra dakra commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Fixes #432.

Problem

ghostel-project keyed terminals by a buffer name derived from the project directory's basename, so two projects sharing a basename (~/a/b and ~/d/b) mapped to the same *b-ghostel* identity: the second project reused the first project's terminal, and the project cycle commands conflated the two.

Change

Buffer identity becomes a structured alist instead of a name string (ghostel-identity, public):

  • kind (mandatory): term, compile, exec, eshell, or a third-party symbol.
  • Scope keys, composable: project-root for project terminals, name for plain terminals, command (program + args) for exec-style buffers; room for future scopes (tab, workspace).
  • instance marks reusable slots.

Slot reuse compares whole identities; scoped listings match subsets via the new ghostel-identity-match-p. ghostel and ghostel-project are thin wrappers over a shared core; the buffer name is purely cosmetic. The identity-scope cycle commands include numbered instances and exclude non-terminal buffers (e.g. a running ghostel-compile). ghostel-exec gains an optional IDENTITY argument so third-party packages can tag and filter their own buffers.

Bookmarks store the identity alist. Bookmarks of exec/eshell-visual buffers become restorable: the recorded command reattaches to a live buffer running that command, or respawns it in the bookmarked directory (restored buffers are plain ghostel-exec buffers without kind-specific wiring; the argv is saved to the bookmark file in plaintext).

Behavior changes

  • A numeric prefix of 1 selects the default terminal (formerly a separate *ghostel*<1> buffer).
  • Bookmarks saved by older versions still restore but spawn a fresh terminal instead of reusing a live one.
  • With a non-nil ghostel-buffer-name-function, a title clear reverts to the creation-time name recorded in the new ghostel--initial-name.

Testing

make -j8 all (elisp, native, zig, evil suites). New ERT coverage: same-basename collision repro, subset matching, numbered-instance scoping, next-free instances, kind exclusion, bookmark reattach/respawn/failure-cleanup, render-free title-clear revert. Live-verified in sandboxed Emacs sessions: plain slots, project flows (including cd cross-contamination), compile identity across the view-mode switch, eshell visual commands, bookmark reattach/respawn.

dakra added 2 commits August 12, 2026 15:01
Two projects sharing a directory basename rendered the same
project-prefixed buffer name, so ghostel-project reused one project's
terminal for the other and the project cycle commands conflated them.

Replace the name-string ghostel--buffer-identity with a structured
ghostel-identity alist: a mandatory kind (term, compile, exec, eshell,
or a third-party symbol), composable scope keys such as project-root
and the plain-terminal name, and an instance number on reusable slots.
Slot reuse compares whole identities; scoped listings match subsets
via the new ghostel-identity-match-p.  ghostel and ghostel-project
become thin wrappers over a shared ghostel--start core.

The buffer name is now purely cosmetic; the new buffer-local
ghostel--initial-name records the creation name as the title-clear
revert target.  Bookmarks store the identity alist and reuse live
buffers only through slot identities, so shared kind-only identities
cannot hijack an unrelated buffer; legacy string records restore
identity-less.  ghostel-exec gains an optional IDENTITY argument for
third-party kinds.  Remote project roots are keyed verbatim, since
TRAMP path normalization depends on connection state.
ghostel-exec records its program and arguments in the identity's
command key; callers passing IDENTITY store it verbatim and add their
own command key for restorable bookmarks.  The eshell visual-command
integration does the same.

Jumping to such a bookmark reattaches to a live ghostel buffer whose
identity command equals the record's -- buffer names may have been
uniquified or changed since -- and otherwise respawns the recorded
command in the bookmarked directory, killing the partial buffer if
the spawn fails.  The typed cd on reuse is limited to shells; command
buffers are left alone.  Restored buffers are plain ghostel-exec
buffers without kind-specific wiring, and the argv is saved to the
bookmark file in plaintext.
@dakra
dakra force-pushed the feat/structured-identity branch 2 times, most recently from 75c119c to fd53e45 Compare August 12, 2026 14:21
@dakra
dakra merged commit fd53e45 into main Aug 12, 2026
29 checks passed
@dakra
dakra deleted the feat/structured-identity branch August 12, 2026 14:26

This branch was previously deployed

1 inactive deployment
github-pages — fd53e45e Deployed Aug 12, 2026 by dakra via deploy #155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ghostel-project incorrectly reuses terminal buffers for same-named projects in different directories.

1 participant