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

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

[nongnu] elpa/haskell-tng-mode 4b598b2 377/385: third party tools use pr


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode 4b598b2 377/385: third party tools use project specific PATH
Date: Wed, 6 Oct 2021 00:00:07 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit 4b598b29600e4a4170a4dc0a959e9aded93ba7e4
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    third party tools use project specific PATH
---
 haskell-tng-extra.el     | 38 +++++++++++++++++++++++++++-----------
 haskell-tng-hsinspect.el | 19 +++----------------
 haskell-tng-util.el      | 23 +++++++++++++++++++++++
 3 files changed, 53 insertions(+), 27 deletions(-)

diff --git a/haskell-tng-extra.el b/haskell-tng-extra.el
index c6d8d68..4789b04 100644
--- a/haskell-tng-extra.el
+++ b/haskell-tng-extra.el
@@ -66,39 +66,55 @@ When in a comment and called with a prefix, the comment 
will be completed."
     (haskell-tng-ormolu)))
 
 ;;;###autoload
+(defvar-local haskell-tng-stylish-haskell nil
+  "A cache of the `stylish-haskell' binary as seen from this buffer.")
 (defun haskell-tng-stylish-haskell ()
   "Apply `stylish-haskell' rules."
   ;; TODO use https://github.com/purcell/reformatter.el
   (interactive)
   (when (buffer-modified-p)
     (save-buffer))
-  (when (= 0 (call-process "stylish-haskell" nil "*stylish-haskell*" nil "-i" 
buffer-file-name))
+  (when (= 0 (call-process
+              (haskell-tng--util-cached-variable
+               (lambda () (haskell-tng--util-which "stylish-haskell"))
+               'haskell-tng-stylish-haskell)
+              nil "*stylish-haskell*" nil "-i" buffer-file-name))
     (revert-buffer t t t)))
 
 ;;;###autoload
+(defvar-local haskell-tng-ormolu nil
+  "A cache of the `ormolu' binary as seen from this buffer.")
 (defun haskell-tng-ormolu ()
   "Apply `ormolu' rules."
   ;; TODO use https://github.com/purcell/reformatter.el
-  ;; TODO pass parameters via a buffer local variable
   (interactive)
   (when (buffer-modified-p)
     (save-buffer))
-  (when (= 0 (call-process "ormolu" nil "*ormolu*" nil
-                             ;; "-p"
-                             "-o" "-XTypeApplications"
-                             "-o" "-XBangPatterns"
-                             "-o" "-XPatternSynonyms"
-                             "-m" "inplace"
-                             buffer-file-name))
+  (when (= 0 (call-process
+              (haskell-tng--util-cached-variable
+               (lambda () (haskell-tng--util-which "ormolu"))
+               'haskell-tng-ormolu)
+              nil "*ormolu*" nil
+              ;; "-p"
+              "-o" "-XTypeApplications"
+              "-o" "-XBangPatterns"
+              "-o" "-XPatternSynonyms"
+              "-m" "inplace"
+              buffer-file-name))
     (revert-buffer t t t)))
 
 ;;;###autoload
+(defvar-local haskell-tng-stack2cabal nil
+  "A cache of the `stack2cabal' binary as seen from this buffer.")
 (defun haskell-tng-stack2cabal ()
   "Prepare a stack project for use with cabal."
   (interactive)
   (when-let (default-directory
               (locate-dominating-file default-directory "stack.yaml"))
-    (call-process "stack2cabal")))
+    (call-process
+     (haskell-tng--util-cached-variable
+      (lambda () (haskell-tng--util-which "stack2cabal"))
+      'haskell-tng-stack2cabal))))
 
 ;;;###autoload
 (defun haskell-tng-goto-imports ()
@@ -136,7 +152,7 @@ When in a comment and called with a prefix, the comment 
will be completed."
    (reverse
     (seq-take-while
      (lambda (e) (let (case-fold-search)
-              (string-match-p (rx bos upper) e)))
+                   (string-match-p (rx bos upper) e)))
      (reverse
       (split-string
        (file-name-sans-extension buffer-file-name)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 40cb398..089c041 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -450,14 +450,6 @@ When using hsinspect-0.0.9, also: srcid."
          (buffer-substring-no-properties (point-min) (point-max))))
     (user-error "Could not find `.ghc.flags': add GhcFlags.Plugin and 
compile.")))
 
-(defun haskell-tng--hsinspect-ghcpath ()
-  "Obtain the ghc PATH for the current buffer."
-  (if-let (default-directory (locate-dominating-file default-directory 
".ghc.path"))
-      (with-temp-buffer
-        (insert-file-contents (expand-file-name ".ghc.path"))
-        (buffer-substring-no-properties (point-min) (point-max)))
-    (error "Could not find `.ghc.path': add GhcFlags.Plugin and compile.")))
-
 (defvar-local haskell-tng--hsinspect-imports nil)
 (defun haskell-tng--hsinspect-imports (&optional no-work flush-cache)
   (haskell-tng--util-cached
@@ -511,13 +503,8 @@ Does not persist the cache changes to disk."
   "Finds and checks the hsinspect binary for the current buffer.
 
 This is uncached, prefer `haskell-tng--hsinspect-exe'."
-  (let* ((supported '("0.0.7" "0.0.8" "0.0.9" "0.0.10" "0.0.11" "0.0.12" 
"0.0.13" "0.0.14"))
-         (ghcpath (haskell-tng--hsinspect-ghcpath))
-         (bin (locate-file
-               "hsinspect"
-               (split-string ghcpath path-separator)
-               exec-suffixes
-               #'file-executable-p)))
+  (let ((supported '("0.0.7" "0.0.8" "0.0.9" "0.0.10" "0.0.11" "0.0.12" 
"0.0.13" "0.0.14"))
+        (bin (haskell-tng--util-ghcpath-which "hsinspect")))
     (if bin
         (let ((version
                (string-trim
@@ -530,7 +517,7 @@ This is uncached, prefer `haskell-tng--hsinspect-exe'."
 
 (defun haskell-tng--hsinspect (flush-cache &rest params)
   (ignore-errors (kill-buffer "*hsinspect*"))
-  (when-let ((ghcpath (haskell-tng--hsinspect-ghcpath))
+  (when-let ((ghcpath (haskell-tng--util-ghcpath))
              (ghcflags (haskell-tng--hsinspect-ghcflags))
              (hsinspect (haskell-tng--hsinspect-exe flush-cache))
              (default-directory (haskell-tng--util-locate-dominating-file
diff --git a/haskell-tng-util.el b/haskell-tng-util.el
index 28e3d75..48c4ba3 100644
--- a/haskell-tng-util.el
+++ b/haskell-tng-util.el
@@ -184,5 +184,28 @@ RESET deletes the cache if it exists."
       (make-directory (file-name-directory file) 'create-parents)
       (prin1 var (current-buffer)))))
 
+(defun haskell-tng--util-ghcpath ()
+  "Obtain the ghc PATH for the current buffer using the `.ghc.path' from the 
`ghcflags' plugin."
+  (if-let (default-directory (locate-dominating-file default-directory 
".ghc.path"))
+      (with-temp-buffer
+        (insert-file-contents (expand-file-name ".ghc.path"))
+        (buffer-substring-no-properties (point-min) (point-max)))
+    (error "Could not find `.ghc.path': add GhcFlags.Plugin and compile.")))
+
+(defun haskell-tng--util-ghcpath-which (program)
+  "Finds a binary using buffer-specific `.ghc.path`."
+  (locate-file
+   program
+   (split-string (haskell-tng--util-ghcpath) path-separator)
+   exec-suffixes
+   #'file-executable-p))
+
+(defun haskell-tng--util-which (program)
+  "Finds a binary using buffer-specific `.ghc.path` falling back
+to allow the caller to find it on the PATH."
+  (or
+   (ignore-errors (haskell-tng--util-ghcpath-which program))
+   program))
+
 (provide 'haskell-tng-util)
 ;;; haskell-tng-util.el ends here



reply via email to

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