Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; Directory Local Variables -*- no-byte-compile: t -*-
((emacs-lisp-mode
(indent-tabs-mode . nil)
(fill-column . 80)
(sentence-end-double-space . t)
(checkdoc-verb-check-experimental-flag . nil)))
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: CI
on: [push, pull_request]
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
emacs-version: ['28.1', '29.4', 'snapshot']
emacs-version: ['28.1', '29.4', '30.1', 'snapshot']
steps:
- uses: actions/checkout@v4
- uses: purcell/setup-emacs@master
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@
# Undo-tree save-files
*.~undo-tree
flycheck_*.el

# Lock files
.#*

# Auto-save files
\#*\#

# Package autoloads
*-autoloads.el
*-pkg.el
119 changes: 119 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#+title: Changelog
#+author: Hayden Stanko

* 0.3.3 — 2026-03-21

** Bug fixes
- Fix daemon-mode overwriting persisted workspace name on shutdown ::
In daemon mode, =delete-frame-functions= fires before =kill-emacs-hook=,
destroying the frame's treemacs scope shelf. =--sync-before-persist=
then re-queried =(treemacs-current-workspace)=, which fell back to
the wrong workspace and overwrote the correct =--current-workspace-name=.
Fixed by (1) persisting the name to disk immediately in
=--on-workspace-switch= and (2) removing the re-capture from
=--sync-before-persist=.

** Tests
- 2 new specs: =--on-workspace-switch= disk round-trip, and
=--sync-before-persist= daemon scenario (wrong treemacs scope does
not overwrite persisted name).
- Total spec count: 104 (up from 98 in 0.3.2).

* 0.3.2 — 2026-03-21

** New features
- =declarative-project-treemacs-cache-file= defcustom :: The cache file
path is now a =defcustom= with framework-specific guidance for Doom
and Spacemacs users. A backward-compat alias preserves the old
internal name.
- =declarative-project-treemacs-reset-cache= :: Interactive command to
reset the workspace cache to a single empty Default workspace.

** Bug fixes
- Hardened =--read-cache= against corrupted/empty files :: Empty (0-byte)
or malformed cache files now fall back to minimal desired state instead
of erroring. Corrupt files trigger a =display-warning= and auto-reset.

** Tests
- 8 new cache validation specs: struct integrity, dedup, multi-workspace
project counts, unassign round-trip, corrupt/empty file recovery, setq
form validation, and normalization idempotency.
- Total spec count: 96 (up from 74 in 0.3.1).

* 0.3.1 — 2026-03-21

** Bug fixes
- Fix duplicate workspace assignments when treemacs-mode active :: The
install function's native treemacs code path was firing alongside the
desired-state model, causing duplicate project entries. The native
fallback is now gated behind =(not declarative-project-treemacs-mode)=.

** New features
- Workspace enforcement via advice :: Two new advice functions
(=after treemacs-switch-workspace= and =after treemacs--restore=)
re-apply desired state whenever treemacs switches or restores
workspaces, preventing external changes from overriding declared
assignments.

** Tests
- 7 new specs for fallback guard, advice lifecycle, and mode
registration. Total spec count: 74 (up from 52).

** Code quality
- Added GPL-3.0 license headers to all secondary =.el= and test files.
- Updated =.gitignore= with Emacs lock-file and autoload patterns.

* 0.3.0 — 2026-03-20

** Bug fixes
- Fix =warn= / =display-warning= mismatch :: All warning calls now use
=display-warning= with the ='declarative-project= type symbol, matching
existing test expectations and providing structured warning output.
- Fix treemacs =--unassign-project= nil dereference :: Wrapped workspace
lookup in =when-let= so =(treemacs-workspace->projects ws)= is never called
on a nil workspace.
- Remove tab characters from warning format strings.

** New features
- =declarative-project-install= :: Public interactive command (alias for
the internal =--install-project=). Keymap binding =C-c C-c i= now points
to the public name.
- =;;;###autoload= cookies :: Added to =declarative-project-mode= and
=org-babel-execute:declarative-project= for proper lazy-loading via
=package.el=.

** Code quality
- Added =:package-version= to all =defcustom= declarations.
- Expanded Commentary sections with full =.project= file format reference.
- Improved docstrings on minor mode, accessor functions, and public API.
- Deleted legacy ERT test file (=declarative-project-mode-test.el=) that
referenced removed API.
- Added =.dir-locals.el= for development settings.

** Tests
- 20 new Buttercup specs for =declarative-project-treemacs= module:
=--minimal-desired-state=, =--ensure-desired-state=, =--workspaces-by-name=,
cache round-trip, =--assign-project= (new workspace, existing, dedup),
=--unassign-project= (happy path + nil regression), =--remove-workspace=,
=--prune-invalid-projects=, =--override-workspaces=,
=--assign-declared-project= (hook integration),
=declarative-project-treemacs-mode= (hook add/remove).
- Expanded =test-helper.el= with =cl-defstruct= stubs for
=treemacs-workspace= / =treemacs-project= and =with-treemacs-test-state=
macro.
- Total spec count: 52 (up from 32).

* 0.2.0 — 2026-03-15

** Highlights
- Rewrote core to use hash-table based =project-resources= instead of
=cl-defstruct=.
- Absorbed =treemacs-declarative-workspaces-mode= into
=declarative-project-treemacs.el=.
- Added =ob-declarative-project.el= for Org-Babel integration.
- Added =declarative-project--install-from-content= for programmatic /
Org-Babel use without a =.project= file on disk.
- Switched test framework from ERT to Buttercup (32 specs).
- Replaced =shell-command= with =call-process= for git clone (security).
- Added CI via GitHub Actions, README, and CONTRIBUTING guide.
- Dropped =file-name-parent-directory= for Emacs 28.1 compatibility.
20 changes: 19 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,27 @@ Emacs minor mode for declarative project resource management via `.project` file
- `declarative-project--apply-treemacs-workspaces-hook` is run during install for treemacs integration
- Accessor functions: `declarative-project-workspaces`, `declarative-project-root-directory`, `declarative-project-name`

## Cache Architecture (treemacs integration)

- **Cache file**: `treemacs-declared-workspaces.el` in `user-emacs-directory` — stores desired workspace structs as a `setq` form
- **Desired-state model**: `.project` installs accumulate workspace/project structs into `--desired-state`; this list is the single source of truth for what treemacs workspaces should contain
- **Relationship to treemacs persist file**: treemacs has its own `treemacs-persist` file written on `kill-emacs-hook`. Our mode takes full control of `treemacs--workspaces`, so both files should converge.

### 3-layer persistence defense

- **Layer 1 (pre-empt)**: Sets `(put 'treemacs :state-is-restored t)` on mode enable, preventing `treemacs--maybe-load-workspaces` from ever firing
- **Layer 2 (after-restore advice)**: If `treemacs--restore` fires anyway (e.g. mode enabled late), `:after` advice re-applies desired state via `--override-workspaces`
- **Layer 3 (kill-emacs sync)**: `--sync-before-persist` runs on `kill-emacs-hook` at depth -90 (before treemacs's persist at depth 0), ensuring treemacs writes our desired state to disk

### treemacs-persp interaction

Doom's `:ui workspaces` module enables `treemacs-persp`, which sets scope type to `Perspectives` and creates "Perspective <name>" workspaces. We suppress this via `:around` advice on `treemacs-persp--ensure-workspace-exists`.

**Key design choice**: hooks that fire during normal operation (`treemacs-switch-workspace-hook`, `treemacs-select-functions`, persp-ensure advice) use `--sync-workspace-list` which maintains the workspace list without changing the current workspace. Only mode init and after-restore use `--override-workspaces` which also sets the current workspace. This prevents perspective switches and treemacs focus from resetting the user's workspace selection.

## Development

- Emacs Lisp with `lexical-binding: t`
- Package requires Emacs 28.1+
- Tests: `make test` (uses Buttercup, 25 specs)
- Tests: `make test` (uses Buttercup, 104 specs)
- Test runner auto-detects straight.el (Doom) or Cask
85 changes: 85 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at system.cuttle@gmail.com. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of actions.

**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test:
-l buttercup \
-l test-helper \
-l test-declarative-project \
-l test-declarative-project-treemacs \
-l test-ob-declarative-project \
-f buttercup-run

Expand Down
49 changes: 48 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,52 @@ When enabled, project installation creates or updates treemacs workspace
entries. Set =declarative-project-treemacs-autoprune= to =nil= to disable
automatic removal of stale project entries on mode init.

** Framework-specific configuration

*** Doom Emacs

In =packages.el=:
#+begin_src emacs-lisp
(package! declarative-project-mode
:recipe (:host github :repo "cuttlefisch/declarative-project-mode"))
#+end_src

In =config.el=:
#+begin_src emacs-lisp
(use-package! declarative-project-mode
:config
(after! treemacs
(require 'declarative-project-treemacs)
(setq declarative-project-treemacs-cache-file
(expand-file-name "treemacs-declared-workspaces.el" doom-cache-dir))
(declarative-project-treemacs-mode 1)))
#+end_src

*** Spacemacs

In =dotspacemacs-additional-packages=:
#+begin_src emacs-lisp
(declarative-project-mode
:location (recipe :fetcher github :repo "cuttlefisch/declarative-project-mode"))
#+end_src

In =dotspacemacs/user-config=:
#+begin_src emacs-lisp
(require 'declarative-project-treemacs)
(setq declarative-project-treemacs-cache-file
(expand-file-name "treemacs-declared-workspaces.el" spacemacs-cache-directory))
(declarative-project-treemacs-mode 1)
#+end_src

*** Vanilla Emacs

#+begin_src emacs-lisp
(require 'declarative-project-treemacs)
(declarative-project-treemacs-mode 1)
;; Cache file defaults to user-emacs-directory; customize if needed:
;; (setq declarative-project-treemacs-cache-file "~/.cache/emacs/treemacs-declared-workspaces.el")
#+end_src

* Spec Reference

| Field | Type | Description |
Expand All @@ -129,12 +175,13 @@ to placing the resource in the project root directory.
|--------------------------------------------+---------+---------------------------------------------------|
| =declarative-project-auto-install= | =nil= | Auto-run installation when mode activates |
| =declarative-project-treemacs-autoprune= | =t= | Remove stale project entries on treemacs mode init |
| =declarative-project-treemacs-cache-file= | =user-emacs-directory= | Path to the workspace cache file |

* Development

#+begin_src shell
cask install
make test # 32 Buttercup specs
make test # 96 Buttercup specs
#+end_src

See [[file:CONTRIBUTING.org][CONTRIBUTING.org]] for the full development guide.
Expand Down
Loading
Loading