Subject: bug#55056: [PATCH] Delete temporary Flymake Elisp files

From: Philip Kaludercic <[email-masked]>
Date: Thu, 21 Apr 2022 16:42:05 +0000

Tags: patch

My temporary directory appears to always be littered with flymake files.
The reason for this appears to be that the Elisp Flymake backend doesn't
always clean up after itself, when it should.  In the worst case I can
run out of space and that can mess up a lot of things on a system.

The below patch adds a check to the sentinel to do so.  I was a bit
paranoid and considered more process-states that might be necessary, but
I hope that someone with a better understanding of the process interface
will be able to help here.

In GNU Emacs 29.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version 2.24.33, cairo version 1.16.0)
 of 2022-04-18 built on icterid
Repository revision: 7b1881682bfbd1ff83d47b88fa8cca22c0290c17
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-native-compilation --with-cairo --with-harfbuzz
 LDFLAGS=-flto 'CFLAGS=-march=native -mtune=native -pipe''

>From 26eba81b8a05e394d495336749da171e1cdf355e Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
Date: Thu, 21 Apr 2022 17:04:19 +0200
Subject: [PATCH] Delete temporary Flymake Elisp files every time a process
 ends

* elisp-mode.el (elisp-flymake-byte-compile): Handle terminal process
states besides exit by also removing the temporary file.
---
 lisp/progmodes/elisp-mode.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 0dfff32f20..c99cf34db0 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -2101,7 +2101,11 @@ elisp-flymake-byte-compile
                            :explanation
                            (format "byte-compile process %s died" proc))))
               (ignore-errors (delete-file temp-file))
-              (kill-buffer output-buffer))))
+              (kill-buffer output-buffer)))
+          (when (memq (process-status proc) '(failed closed signal))
+            (message "Elisp flymake [%s]: %S" (buffer-file-name) (process-status proc))
+            (ignore-errors (delete-file temp-file))
+            (kill-buffer output-buffer)))
         :stderr " *stderr of elisp-flymake-byte-compile*"
         :noquery t)))))
 
-- 
2.30.2

-- 
	Philip Kaludercic