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

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

[nongnu] elpa/reformatter e7216e8d89 3/3: Merge pull request #55 from Da


From: ELPA Syncer
Subject: [nongnu] elpa/reformatter e7216e8d89 3/3: Merge pull request #55 from DamienCassou/add-working-directory
Date: Tue, 3 Sep 2024 07:49:49 -0400 (EDT)

branch: elpa/reformatter
commit e7216e8d89bfeb9da76733c0b3bcaf2ecb4adfbd
Merge: 0d29a04d69 0f6554cfd4
Author: Steve Purcell <steve@sanityinc.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #55 from DamienCassou/add-working-directory
    
    Add :working-directory
---
 reformatter.el | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/reformatter.el b/reformatter.el
index 3ea3d2885b..fc1ca5b444 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -83,12 +83,12 @@ 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)
+(defun reformatter--do-region (name beg end program args stdin stdout 
input-file exit-code-success-p display-errors working-directory)
   "Do the work of reformatter called NAME.
-Reformats the current buffer's region from BEG to END using
-PROGRAM and ARGS.  For args STDIN, STDOUT, INPUT-FILE,
-EXIT-CODE-SUCCESS-P and DISPLAY-ERRORS see the documentation of
-the `reformatter-define' macro."
+Reformats the current buffer's region from BEG to END using PROGRAM and
+ARGS. When DISPLAY-ERRORS is non-nil, shows a buffer if the formatting
+fails. For args STDIN, STDOUT, INPUT-FILE, EXIT-CODE-SUCCESS-P and
+WORKING-DIRECTORY see the documentation of the `reformatter-define' macro."
   (cl-assert input-file)
   (cl-assert (functionp exit-code-success-p))
   (when (and input-file
@@ -103,7 +103,8 @@ the `reformatter-define' macro."
          ;; some hand-rolled reformatter functions that this
          ;; library was written to replace.
          (coding-system-for-read 'utf-8)
-         (coding-system-for-write 'utf-8))
+         (coding-system-for-write 'utf-8)
+         (default-directory (or working-directory default-directory)))
     (unwind-protect
         (progn
           (write-region beg end input-file nil :quiet)
@@ -142,7 +143,7 @@ the `reformatter-define' macro."
       (delete-file stdout-file))))
 
 ;;;###autoload
-(cl-defmacro reformatter-define (name &key program args (mode t) (stdin t) 
(stdout t) input-file lighter keymap group (exit-code-success-p 'zerop))
+(cl-defmacro reformatter-define (name &key program args (mode t) (stdin t) 
(stdout t) input-file lighter keymap group (exit-code-success-p 'zerop) 
working-directory)
   "Define a reformatter command with NAME.
 
 When called, the reformatter will use PROGRAM and any ARGS to
@@ -234,7 +235,13 @@ EXIT-CODE-SUCCESS-P
   which accepts an integer process exit code, and returns non-nil
   if that exit code is considered successful.  This could be a
   lambda, quoted symbol or sharp-quoted symbol.  If not supplied,
-  the code is considered successful if it is `zerop'."
+  the code is considered successful if it is `zerop'.
+
+WORKING-DIRECTORY
+
+  Directory where your reformatter program is started. If provided, this
+  should be a form that evaluates to a string at runtime. Default is the
+  value of `default-directory' in the buffer."
   (declare (indent defun))
   (cl-assert (symbolp name))
   (cl-assert (functionp exit-code-success-p))
@@ -285,7 +292,7 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
                  (reformatter--do-region
                   ',name beg end
                   ,program ,args ,stdin ,stdout input-file
-                  #',exit-code-success-p display-errors))
+                  #',exit-code-success-p display-errors ,working-directory))
              (when (file-exists-p input-file)
                (delete-file input-file)))))
 



reply via email to

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