[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
- [nongnu] elpa/haskell-tng-mode 2050c16 323/385: bad parameter order, (continued)
- [nongnu] elpa/haskell-tng-mode 2050c16 323/385: bad parameter order, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 2d50a06 358/385: enable CI, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 923fa9e 344/385: bugfixes in jump-to-definition, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3939303 334/385: importing from the hsinspect index will update the buffer cache, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3ea52c1 341/385: special case jumping to inplace packages, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4217d98 378/385: fixup! third party tools use project specific PATH, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f7f0e0f 383/385: moar extras, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 2017d07 384/385: widen hsinspect range, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 083e80a 110/385: assert on alternative indentation order, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ec1ac46 361/385: document a bug, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4b598b2 377/385: third party tools use project specific PATH,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode aaf7c55 370/385: support for hsinspect-lsp, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b3e6c9a 113/385: compilation mode regression tests vs haskell-mode, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 99a7f10 337/385: cleanup, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e6d8761 343/385: local jump-to-definition should error, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c31afdb 272/385: missing CPP case, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 85c4dd5 233/385: fix bugfix in goto-import, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5c157fb 255/385: rigid ormolu support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 64ec84d 260/385: if/then/else indentation, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1d53572 243/385: bugfixes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d1e599a 285/385: switch formatting backend based on project config, ELPA Syncer, 2021/10/06