Spent hours debugging why rustic-format-buffer wasn’t working in Emacs. The error? “Program not found: No such file or directory, cargo”
The Problem
rustic-format-buffer
Error: Program not found: No such file or directory, cargo
Cargo was definitely installed and working in my terminal (zsh). But Emacs couldn’t see it.
The Debug Journey
Tried the systematic approach:
- Checked if rustic-mode was actually running (yes)
- Searched rustic repo issues (nothing relevant)
- Used
M-x debug-on-errorto trace the error - Found it failed in
rustic-buffer-workspace- literally couldn’t find cargo - Checked Emacs PATH:
M-x getenv RET PATH
Aha moment: Emacs PATH didn’t include ~/.cargo/bin!
Why This Happens
Emacs GUI on macOS doesn’t inherit shell environment variables. My zsh had cargo in PATH, but Emacs launched from Dock didn’t.
The Fix
Install exec-path-from-shell:
(use-package exec-path-from-shell
:config
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
Restart Emacs. Now rustic-format-buffer works perfectly.
Lesson
Emacs GUI environment ≠ Terminal environment. Always check M-x getenv when programs “aren’t found”.
Found the solution in this Reddit thread.
