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). --- modules/prog-c.el | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'modules/prog-c.el') diff --git a/modules/prog-c.el b/modules/prog-c.el index d9191bf4..df32b76a 100644 --- a/modules/prog-c.el +++ b/modules/prog-c.el @@ -16,12 +16,12 @@ ;; ;; Workflow Example: ;; 1. Open a .c file → LSP auto-starts, provides completions -;; 2. S- → Compile (auto-detects Makefile/CMake/single file) -;; 3. → Quick recompile -;; 4. S- → Start GDB with multi-window layout -;; 5. or C-c f → Format code with clang-format -;; 6. M-. → Jump to function definition -;; 7. C-c l → Access LSP commands (rename, find references, etc.) +;; 2. F4 → compile + run dispatcher (dev-fkeys.el) +;; 3. S-F4 → recompile (repeat last) +;; 4. S-F6 → start GDB +;; 5. C-; f → format code with clang-format +;; 6. M-. → jump to function definition +;; 7. C-c l → LSP commands (rename, find references, etc.) ;;; Code: @@ -95,7 +95,6 @@ (use-package clang-format :if (executable-find clang-format-path) :bind (:map c-mode-base-map - ("" . clang-format-buffer) ("C-; f" . clang-format-buffer))) ;; -------------------------------- Compilation -------------------------------- @@ -135,11 +134,8 @@ ;; -------------------------------- Keybindings -------------------------------- (defun cj/c-mode-keybindings () - "Set up keybindings for C programming. -Overrides default prog-mode keybindings with C-specific commands." - ;; S-f4: Recompile (override default - C uses this more than projectile-compile) - (local-set-key (kbd "S-") #'recompile) - + "Set up C-specific S-modifier overrides on the dev F-keys. +S-F4 (recompile) is global, owned by dev-fkeys.el — not duplicated here." ;; S-f5: Static analysis placeholder (could add clang-tidy, cppcheck, etc.) (local-set-key (kbd "S-") #'cj/disabled) -- cgit v1.2.3