[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/reformatter 897f3ba503 67/81: Handle slashes in names of c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/reformatter 897f3ba503 67/81: Handle slashes in names of created functions |
Date: |
Tue, 5 Sep 2023 04:03:38 -0400 (EDT) |
branch: elpa/reformatter
commit 897f3ba503d4a14abf61304bfef7f2f154e6e941
Author: Johannes Maier <johannes.maier@active-group.de>
Commit: Johannes Maier <johannes.maier@mailbox.org>
Handle slashes in names of created functions
Previously, if the symbol passed to `reformatter-define' contained a
slash, then the actual formatting would fail due to `make-temp-file'
trying to create a directory. Use a sanitized symbol name as basis
for the tempfile name instead.
---
reformatter-tests.el | 14 +++++++++++++-
reformatter.el | 15 ++++++++++++---
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/reformatter-tests.el b/reformatter-tests.el
index 7b126fe818..586b12aa75 100644
--- a/reformatter-tests.el
+++ b/reformatter-tests.el
@@ -55,6 +55,19 @@
(reformatter-tests-shfmt-tempfile-in-stdout)
(should (equal "[ foo ] && echo yes\n" (buffer-string)))))
+;; Same as `reformatter-tests-shfmt-tempfile-in-stdout', but with a
+;; slash in the symbol name.
+(reformatter-define reformatter-tests-tempfile/with-slash-in-symbol-name
+ :program "shfmt"
+ :stdin nil
+ :args (list input-file))
+
+(ert-deftest reformatter-tests-tempfile-with-slash-in-symbol-name ()
+ (with-temp-buffer
+ (insert "[ foo ] && echo yes\n")
+ (reformatter-tests-tempfile/with-slash-in-symbol-name)
+ (should (equal "[ foo ] && echo yes\n" (buffer-string)))))
+
;; Modify a file in place
(reformatter-define reformatter-tests-shfmt-in-place
:program "shfmt"
@@ -69,6 +82,5 @@
(should (equal "[ foo ] && echo yes\n" (buffer-string)))))
-
(provide 'reformatter-tests)
;;; reformatter-tests.el ends here
diff --git a/reformatter.el b/reformatter.el
index b54dcb5761..1289f7c5f9 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -76,6 +76,13 @@
(require 'cl-lib))
(require 'ansi-color)
+(defun reformatter--make-temp-file (sym)
+ "Create a temporary file whose filename is based on SYM, but with
+slashes replaced by underscores. `make-temp-file' fails
+otherwise as it cannot create intermediate directories."
+ (make-temp-file
+ (replace-regexp-in-string "/" "_" (symbol-name sym))))
+
(defun reformatter--do-region (name beg end program args stdin stdout
input-file exit-code-success-p display-errors)
"Do the work of reformatter called NAME.
Reformats the current buffer's region from BEG to END using
@@ -89,8 +96,8 @@ the `reformatter-define' macro."
(string= (file-truename input-file)
(file-truename (buffer-file-name))))
(error "The reformatter must not operate on the current file in-place"))
- (let* ((stderr-file (make-temp-file (symbol-name name)))
- (stdout-file (make-temp-file (symbol-name name)))
+ (let* ((stderr-file (reformatter--make-temp-file name))
+ (stdout-file (reformatter--make-temp-file name))
;; Setting this coding system might not universally be
;; the best default, but was apparently necessary for
;; some hand-rolled reformatter functions that this
@@ -268,7 +275,9 @@ might use:
When called interactively, or with prefix argument
DISPLAY-ERRORS, shows a buffer if the formatting fails."
(interactive "rp")
- (let ((input-file ,(if input-file input-file `(make-temp-file
,(symbol-name name)))))
+ (let ((input-file ,(if input-file
+ input-file
+ (reformatter--make-temp-file name))))
;; Evaluate args with input-file bound
(unwind-protect
(progn
- [nongnu] elpa/reformatter 00413b21ec 28/81: Add reminder to use a `defgroup` form, (continued)
- [nongnu] elpa/reformatter 00413b21ec 28/81: Add reminder to use a `defgroup` form, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter dc6278a6b1 49/81: Merge pull request #23 from purcell/non-zero-exit, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter c9450a39c3 32/81: Merge pull request #8 from wbolster/patch-1, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 48605c92a7 42/81: Add CI, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter e15598a0cc 40/81: Prefer `delete-trailing-whitespace` to the aggressive `whitespace-cleanup`, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 1bf00b2aa3 43/81: Add FUNDING.yml, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 16a7b32736 25/81: Prefer zerop to (eq 0 ...), ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter ac980a8797 27/81: Fix typo in comment, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter aeef16ff67 53/81: Support formatters that operate on files in place, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 27348d5da3 31/81: Use string as modeline lighter format in README, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 897f3ba503 67/81: Handle slashes in names of created functions,
ELPA Syncer <=
- [nongnu] elpa/reformatter 45c0add950 57/81: Move conditional input file path to compile time, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 5aa8c18679 59/81: Specify "from" in nix-env invocation, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 452a99b556 66/81: Add Emacs 28.1 to CI matrix, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 394b3a6606 55/81: Add reformatter-temp-file-in-current-directory, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 576d339aa8 60/81: Add Emacs 27.2 to CI matrix, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 19582a205e 62/81: Use Emacs > 21 define-minor-mode call convention, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter b57f5d4800 65/81: Merge pull request #33 from bcc32/display-call-process-signal-error-in-buffer, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 7ba5486696 56/81: Clarify that extension does not include the dot, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter c9cf3f0227 80/81: Merge pull request #42 from purcell/dependabot/github_actions/actions/checkout-4, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 6c4f35dd2b 81/81: Merge pull request #43 from purcell/dependabot/github_actions/cachix/install-nix-action-23, ELPA Syncer, 2023/09/05