]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure temp file is deleted in makefile overview
authorStefan Kangas <stefankangas@gmail.com>
Fri, 28 Oct 2022 00:26:44 +0000 (02:26 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Fri, 28 Oct 2022 20:23:08 +0000 (22:23 +0200)
* lisp/progmodes/make-mode.el (makefile-create-up-to-date-overview):
Ensure temp file is always deleted.

lisp/progmodes/make-mode.el

index 5f265212992686d33e3eafa99fe7a47fb04eac0f..92d8a739a5f50a65033e3dc44a5ff9e48d1a0f2a 100644 (file)
@@ -1504,39 +1504,38 @@ dependency in the makefile."
       ;; writing the current contents of the makefile buffer.
       ;;
       (let ((saved-target-table makefile-target-table)
-           (this-buffer (current-buffer))
-           (makefile-up-to-date-buffer
-            (get-buffer-create makefile-up-to-date-buffer-name))
-           (filename (makefile-save-temporary))
-           ;;
-           ;; Forget the target table because it may contain picked-up filenames
-           ;; that are not really targets in the current makefile.
-           ;; We don't want to query these, so get a new target-table with just the
-           ;; targets that can be found in the makefile buffer.
-           ;; The 'old' target table will be restored later.
-           ;;
-           (real-targets (progn
-                           (makefile-pickup-targets)
-                           makefile-target-table))
-           (prereqs makefile-has-prereqs)
-           )
-
-       (set-buffer makefile-up-to-date-buffer)
-       (setq buffer-read-only nil)
-       (erase-buffer)
-       (makefile-query-targets filename real-targets prereqs)
-       (if (zerop (buffer-size))               ; if it did not get us anything
-           (progn
-             (kill-buffer (current-buffer))
-             (message "No overview created!")))
-       (set-buffer this-buffer)
-       (setq makefile-target-table saved-target-table)
-       (if (get-buffer makefile-up-to-date-buffer-name)
-           (progn
-             (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name))
-             (shrink-window-if-larger-than-buffer)
-             (sort-lines nil (point-min) (point-max))
-             (setq buffer-read-only t))))))
+            (this-buffer (current-buffer))
+            (makefile-up-to-date-buffer
+             (get-buffer-create makefile-up-to-date-buffer-name))
+            (filename (makefile-save-temporary))
+            ;;
+            ;; Forget the target table because it may contain picked-up filenames
+            ;; that are not really targets in the current makefile.
+            ;; We don't want to query these, so get a new target-table with just the
+            ;; targets that can be found in the makefile buffer.
+            ;; The 'old' target table will be restored later.
+            ;;
+            (real-targets (progn
+                            (makefile-pickup-targets)
+                            makefile-target-table))
+            (prereqs makefile-has-prereqs))
+        (unwind-protect
+            (progn
+              (set-buffer makefile-up-to-date-buffer)
+              (setq buffer-read-only nil)
+              (erase-buffer)
+              (makefile-query-targets filename real-targets prereqs)
+              (when (zerop (buffer-size))     ; if it did not get us anything
+                (kill-buffer (current-buffer))
+                (message "No overview created!"))
+              (set-buffer this-buffer)
+              (setq makefile-target-table saved-target-table)
+              (when (get-buffer makefile-up-to-date-buffer-name)
+                (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name))
+                (shrink-window-if-larger-than-buffer)
+                (sort-lines nil (point-min) (point-max))
+                (setq buffer-read-only t)))
+          (ignore-errors (delete-file filename))))))
 
 (defun makefile-save-temporary ()
   "Create a temporary file from the current makefile buffer."