emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/reformatter 394b3a6606 55/81: Add reformatter-temp-file-in


From: ELPA Syncer
Subject: [nongnu] elpa/reformatter 394b3a6606 55/81: Add reformatter-temp-file-in-current-directory
Date: Tue, 5 Sep 2023 04:03:37 -0400 (EDT)

branch: elpa/reformatter
commit 394b3a66068d9ff71122d3b36db726244231e965
Author: Steve Purcell <steve@sanityinc.com>
Commit: Steve Purcell <steve@sanityinc.com>

    Add reformatter-temp-file-in-current-directory
---
 reformatter.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/reformatter.el b/reformatter.el
index cb8d06e277..9e3aa2e205 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -188,7 +188,8 @@ INPUT-FILE
   It must not produce the same path as the current buffer's file
   if that is set: you shouldn't be operating directly on the
   buffer's backing file.  The temporary input file will be
-  deleted automatically.
+  deleted automatically.  You might find the function
+  `reformatter-temp-file-in-current-directory' helpful.
 
 MODE
 
@@ -298,5 +299,17 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
   (insert-file-contents file nil nil nil t))
 
 
+(defun reformatter-temp-file-in-current-directory (&optional default-extension)
+  "Make a temp file in the current directory re-using the current extension.
+If the current file is not backed by a file, then use
+DEFAULT-EXTENSION."
+  (let ((temporary-file-directory default-directory)
+        (extension (if buffer-file-name
+                       (file-name-extension buffer-file-name)
+                     default-extension)))
+    (make-temp-file "reformatter" nil
+                    (when extension
+                      (concat "." extension)))))
+
 (provide 'reformatter)
 ;;; reformatter.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]