From 2c94acd52cc92dc4ebefd999dbca771367cc3090 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 16:13:21 -0500 Subject: feat(dev-fkeys): add project-aware F4 compile/run dispatcher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I added a new module `modules/dev-fkeys.el` that owns the dev F-key block. F4 prompts via `completing-read` with a candidate set filtered by project type (compiled / interpreted / unknown). C-F4 is the compile-only fast path. M-F4 is clean + rebuild. It runs a heuristic clean command derived from the project markers (go.mod, Cargo.toml, Eask, Makefile, CMakeLists.txt) and chains `projectile-compile-project` on success. S-F4 stays on `recompile` and now lives globally instead of duplicated across prog-general.el and prog-c.el. F6 is bound globally to `projectile-test-project` as a Phase 1 stopgap. Phase 2 replaces it with the polyglot test runner spec'd in todo.org. Project-type detection runs against the projectile root and falls back to `unknown` when no marker matches. Interpreted markers are checked first so a Python or Node project with a Makefile for tasks classifies as interpreted instead of compiled. Compile + Run sequencing uses a one-shot `compilation-finish-functions` hook that self-removes on first invocation and only fires the follow-up when the status string starts with `finished`. Cleanup in the same commit: - Dropped F4/F5/F6 from `prog-general.el`'s prog-mode-hook. They are now global. - Dropped F6→format bindings from prog-c.el / prog-python.el / prog-shell.el. C-; f was already bound in each, so this is pure removal. - Dropped the duplicate S-F4 from prog-c.el. The global binding covers it. - Updated the keybinding header in prog-general.el and the workflow comments in prog-c.el / prog-shell.el. - Wired `(require 'dev-fkeys)` in init.el alongside coverage-core. TDD: 73 tests across 11 files, one per helper. Production code is split into small testable internals (`cj/--detect-project-type`, `cj/--f4-candidates`, `cj/--f4-derive-clean-cmd`, `cj/--f4-make-once-hook`, `cj/--f4-dispatch`, `cj/--f4-compile-and-run-impl`, `cj/--f4-clean-rebuild-impl`, `cj/--f4-project-root`) plus three thin interactive wrappers. Smoke tests confirm bindings register on load. Known limitation: if another `compilation-finish-functions` hook fires between my add-hook and the compile finishing, the chain can fire on the wrong compile. The hook self-removes on first invocation regardless of which compile it sees. Documented in the impl docstring. Acceptable for v1. Phase 2 will replace F6 with the polyglot test runner (tree-sitter queries for Python/Go/TS, sexp scan for Elisp, buffer-local last-test memory). --- tests/test-dev-fkeys--detect-project-type.el | 117 +++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/test-dev-fkeys--detect-project-type.el (limited to 'tests/test-dev-fkeys--detect-project-type.el') diff --git a/tests/test-dev-fkeys--detect-project-type.el b/tests/test-dev-fkeys--detect-project-type.el new file mode 100644 index 00000000..3b306484 --- /dev/null +++ b/tests/test-dev-fkeys--detect-project-type.el @@ -0,0 +1,117 @@ +;;; test-dev-fkeys--detect-project-type.el --- Tests for cj/--detect-project-type -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the project-type classifier in dev-fkeys.el. +;; The classifier returns 'compiled, 'interpreted, or 'unknown based on +;; marker files at the project root. Interpreted markers are checked first +;; so a Python or Node project with a Makefile for tasks classifies as +;; interpreted. + +;;; Code: + +(require 'ert) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'dev-fkeys) + +(defmacro test-dev-fkeys--with-project-dir (markers &rest body) + "Create a temp project dir with each filename in MARKERS as an empty file. +Bind the dir path to ROOT in BODY. Cleans up on exit." + (declare (indent 1)) + `(let ((root (make-temp-file "test-dev-fkeys-" t))) + (unwind-protect + (progn + (dolist (marker ,markers) + (write-region "" nil (expand-file-name marker root))) + ,@body) + (delete-directory root t)))) + +;;; Normal Cases + +(ert-deftest test-dev-fkeys-detect-project-type-go-mod-is-compiled () + "Normal: go.mod marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("go.mod") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-cargo-toml-is-compiled () + "Normal: Cargo.toml marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Cargo.toml") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-cmakelists-is-compiled () + "Normal: CMakeLists.txt marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("CMakeLists.txt") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-makefile-is-compiled () + "Normal: Makefile marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Makefile") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-eask-is-compiled () + "Normal: Eask marker classifies as compiled." + (test-dev-fkeys--with-project-dir '("Eask") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pyproject-is-interpreted () + "Normal: pyproject.toml marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("pyproject.toml") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-requirements-is-interpreted () + "Normal: requirements.txt marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("requirements.txt") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pipfile-is-interpreted () + "Normal: Pipfile marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("Pipfile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-package-json-is-interpreted () + "Normal: package.json marker classifies as interpreted." + (test-dev-fkeys--with-project-dir '("package.json") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-detect-project-type-interpreted-wins-over-compiled () + "Boundary: a Python project with a Makefile classifies as interpreted. +Interpreted markers are checked first so task-runner Makefiles in +Python/Node projects don't misclassify them as compiled." + (test-dev-fkeys--with-project-dir '("pyproject.toml" "Makefile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-package-json-wins-over-makefile () + "Boundary: package.json + Makefile classifies as interpreted." + (test-dev-fkeys--with-project-dir '("package.json" "Makefile") + (should (eq (cj/--detect-project-type root) 'interpreted)))) + +(ert-deftest test-dev-fkeys-detect-project-type-pure-c-with-makefile-is-compiled () + "Boundary: a Makefile alone (no interpreted markers) classifies as compiled. +This is the typical pure-C project case." + (test-dev-fkeys--with-project-dir '("Makefile") + (should (eq (cj/--detect-project-type root) 'compiled)))) + +(ert-deftest test-dev-fkeys-detect-project-type-no-markers-is-unknown () + "Boundary: directory with no markers classifies as unknown." + (test-dev-fkeys--with-project-dir '() + (should (eq (cj/--detect-project-type root) 'unknown)))) + +(ert-deftest test-dev-fkeys-detect-project-type-irrelevant-file-is-unknown () + "Boundary: unrelated files in root don't trigger any classification." + (test-dev-fkeys--with-project-dir '("README.md" "LICENSE" ".gitignore") + (should (eq (cj/--detect-project-type root) 'unknown)))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-detect-project-type-nil-root-is-unknown () + "Error: nil ROOT returns 'unknown (buffer not in a project)." + (should (eq (cj/--detect-project-type nil) 'unknown))) + +(ert-deftest test-dev-fkeys-detect-project-type-nonexistent-root-is-unknown () + "Error: a directory path that doesn't exist returns 'unknown. +file-exists-p on a non-existent path returns nil, so no marker matches." + (should (eq (cj/--detect-project-type "/nonexistent/path/xyzzy") 'unknown))) + +(provide 'test-dev-fkeys--detect-project-type) +;;; test-dev-fkeys--detect-project-type.el ends here -- cgit v1.2.3