apheleia icon indicating copy to clipboard operation
apheleia copied to clipboard

Error on emacs lisp files.

Open nitincodery opened this issue 1 year ago • 2 comments

OS: Windows Emacs: 29.3

Failed to run diff: Output file descriptor of apheleia-diff is closed

nitincodery avatar Dec 20 '24 11:12 nitincodery

I don't think the problem is with elisp files. I observed a similar error message, when applying apheleia to a C# buffer, using the csharpier reformatter. The problem in my case was the diff program was either not available on exec-path , or it was the wrong diff program. On Windows there are different variants of diff.exe; for example I have the chocolatey package unxUtils installed, and it includes a diff.exe. But that diff.exe does not support the --rcs option, which apheleia relies on.

By happy circumstance, the Git package installs a set of gnu-compatible unix-ish utilities including a diff.exe that supports --rcs. The solution for me was to ensure that the directory containing those utilities, /Program Files/Git/usr/bin , appeared before any other directories that might contain a different diff.exe, in the exec-path variable.

(defun reorder-list (list predicate)
  "Reorders LIST so that elements satisfying PREDICATE come first.
Returns a new list with elements reordered according to PREDICATE.
The original list is not modified."
  (let (matches non-matches)
    (dolist (item list)
      (if (funcall predicate item)
          (push item matches)
        (push item non-matches)))
    (nconc (reverse matches) (reverse non-matches))))

(defun preferred-path-entry (entry)
"returns t if the entry is to be preferred"
   (or
      (string-match-p (regexp-quote "Git/usr/bin") entry)
      (string-match-p (regexp-quote (concat (getenv "HOME") "/bin")) entry)
      ))

(defun maybe-reorder-exec-path-entries ()
  "re-orders the exec-path entries to ensure some dirs are preferred above others."
  (setq exec-path (reorder-list exec-path #'preferred-path-entry)))

(if (eq system-type 'windows-nt)
  (progn
     (add-to-list 'exec-path   "c:/Program Files/Git/usr/bin")  ;; needed for diff, for apheleia
     (maybe-reorder-exec-path-entries)))

DinoChiesa avatar Feb 16 '25 02:02 DinoChiesa

Strange, I have https://www.gnu.org/software/diffutils/ from scoop and its diff.exe has --rcs option, after reading your comment, I moved git's usr/bin directory above in path, and now I it's giving me error that git's diff.exe doesn't have --rcs operand (git from https://gitforwindows.org) and it doesn't have --rcs option I checked, whereas, diffutils package's diff.exe has --rcs option. And I had that always above in path.

Also, I made a PR #334 for issue #276 regarding --rcs using diffutils diff.exe which does have --rcs, so it isn't about --rcs maybe?

nitincodery avatar Feb 16 '25 08:02 nitincodery