Skip to content

Commit

Permalink
refactor(opam-switch--get-switches): Use command opam switch -s (#17)
Browse files Browse the repository at this point in the history
so we avoid regexp filtering code.

Close #15
  • Loading branch information
erikmd committed Jul 26, 2023
1 parent e91244a commit 96bf9a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

- **README.md**: Mention Tuareg and Merlin, regarding opam-switch-mode support
- **release.sh**: Remove noise (empty headings) in **NEWS.md** at release time
- (opam-switch--get-switches): Use command `opam switch -s`, so we avoid regexp filtering code, closes [#15](https://github.com/ProofGeneral/opam-switch-mode/issues/15)

### Removed

Expand Down
19 changes: 7 additions & 12 deletions opam-switch-mode.el
Expand Up @@ -181,17 +181,13 @@ This function should not be called directly; see `opam-switch--root'."

(defun opam-switch--get-switches ()
"Return all opam switches as list of strings."
(let (opam-switches)
(with-temp-buffer
;; FIXME: Use "opam switch -s" ?
(unless (eq (opam-switch--run-command-without-stderr "switch") 0)
;; opam exit status different from 0 -- some error occured
(error "Command 'opam switch' failed"))
(goto-char (point-min))
(forward-line) ;Skip first (header) line.
(while (re-search-forward "^.. *\\([^ \n\t]+\\)" nil t)
(push (match-string 1) opam-switches))
(nreverse opam-switches))))
(with-temp-buffer
(unless
(eq (opam-switch--run-command-without-stderr "switch" nil nil "-s") 0)
;; option -s means --short
;; opam exit status different from 0 implies some error occured
(error "Command 'opam switch' failed"))
(split-string (buffer-string) "\n" t)))

(defvar opam-switch--switch-history nil
"Minibuffer history list for `opam-switch-set-switch'.")
Expand Down Expand Up @@ -393,7 +389,6 @@ is automatically created by `define-minor-mode'."
(define-minor-mode opam-switch-mode
"Toggle opam-switch mode.
The mode can be enabled only if opam is found and \"opam var root\" succeeds."
;; FIXME: Should we include the current switch in the lighter?
:lighter (:eval (opam-switch-mode-lighter))
(if (not opam-switch-mode)
(opam-switch--reset-env)
Expand Down

0 comments on commit 96bf9a2

Please sign in to comment.