[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/opam-switch-mode 16b8276f85 13/31: use -- for internal stu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/opam-switch-mode 16b8276f85 13/31: use -- for internal stuff |
Date: |
Mon, 14 Nov 2022 09:00:00 -0500 (EST) |
branch: elpa/opam-switch-mode
commit 16b8276f851154b7d1b80ef7026a4ed7b40ca6bd
Author: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
Commit: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
use -- for internal stuff
---
opam-switch-mode.el | 119 ++++++++++++++++++++++++++--------------------------
1 file changed, 59 insertions(+), 60 deletions(-)
diff --git a/opam-switch-mode.el b/opam-switch-mode.el
index eca2958299..912af5904f 100644
--- a/opam-switch-mode.el
+++ b/opam-switch-mode.el
@@ -54,19 +54,19 @@
:group 'external)
-(defcustom opsw-program-name "opam"
+(defcustom opsw--program-name "opam"
"Name or path of the opam binary."
:group 'opam-switch-mode
:type 'string)
-(defcustom opsw-common-options ()
+(defcustom opsw--common-options ()
"Options to be supplied to every opam invocation.
This must be a list of strings, each member string an option
accepted by opam."
:group 'opam-switch-mode
:type '(repeat string))
-(defcustom opsw-common-environment
+(defcustom opsw--common-environment
'("OPAMUTF8=never"
"OPAMCOLOR=never"
"LC_ALL=C")
@@ -90,7 +90,7 @@ background process when the opam switch changes."
;;; Code
-(defun opsw-run-command-without-stderr (sub-cmd
+(defun opsw--run-command-without-stderr (sub-cmd
&optional switch sexp
&rest args)
"Run opam SUB-CMD, without capturing error output.
@@ -106,38 +106,38 @@ Internally this function uses `process-file' internally
and will
therfore respect file-name handlers specified via
`default-directory'."
(let ((process-environment
- (append opsw-common-environment process-environment))
- (options (append args opsw-common-options)))
+ (append opsw--common-environment process-environment))
+ (options (append args opsw--common-options)))
(when switch
(push (format "--switch=%s" switch) options))
(when sexp
(push "--sexp" options))
- ;; (message "run %s %s %s" opsw-program-name sub-cmd options)
- (apply 'process-file opsw-program-name
+ ;; (message "run %s %s %s" opsw--program-name sub-cmd options)
+ (apply 'process-file opsw--program-name
nil '(t nil) nil sub-cmd options)))
-(defun opsw-command-as-string (sub-cmd &optional switch sexp &rest args)
+(defun opsw--command-as-string (sub-cmd &optional switch sexp &rest args)
"Return output of opam SUB-CMD as string or nil.
-Same as `opsw-run-command-without-stderr' but return all output
+Same as `opsw--run-command-without-stderr' but return all output
as string. Return nil if opam command fails."
(with-temp-buffer
(let ((status
- (apply 'opsw-run-command-without-stderr sub-cmd switch sexp args)))
+ (apply 'opsw--run-command-without-stderr sub-cmd switch sexp args)))
(if (eq status 0)
(buffer-string)
nil))))
-(defun opsw-get-root ()
+(defun opsw--get-root ()
"Get the opam root directory.
This is the opam variable 'root'."
- (let ((root (opsw-command-as-string "var" nil nil "root")))
+ (let ((root (opsw--command-as-string "var" nil nil "root")))
(unless root
(error "opam var root failed"))
(when (eq (aref root (1- (length root))) ?\n)
(setq root (substring root 0 -1)))
root))
-(defconst opsw-root (opsw-get-root)
+(defconst opsw--root (opsw--get-root)
"The opam root directory.")
;; Example output of opam switch. The warning is output on stderr.
@@ -156,11 +156,11 @@ This is the opam variable 'root'."
;; [WARNING] The environment is not in sync with the current switch.
;; You should run: eval $(opam env)
-(defun opsw-get-switches ()
+(defun opsw--get-switches ()
"Return all opam switches as list of strings."
(let (opam-switches)
(with-temp-buffer
- (unless (eq (opsw-run-command-without-stderr "switch") 0)
+ (unless (eq (opsw--run-command-without-stderr "switch") 0)
;; opam exit status different from 0 -- some error occured
(error "opam switch failed"))
(goto-char (point-min))
@@ -169,31 +169,31 @@ This is the opam variable 'root'."
(push (match-string 1) opam-switches))
opam-switches)))
-(defvar opsw-switch-history nil
- "Minibuffer history list for `opsw-set-switch'.")
+(defvar opsw--switch-history nil
+ "Minibuffer history list for `opsw--set-switch'.")
-(defvar opsw-saved-env nil
+(defvar opsw--saved-env nil
"Saved environment variables, overwritten by an opam switch.
This is a list of saved environment variables. Each saved
variable is a list of two strings, the variable and the value.
Set when the first chosen opam switch overwrites the
environment.")
-(defvar opsw-saved-exec-path nil
+(defvar opsw--saved-exec-path nil
"Saved value of `exec-path'.
Set when the first chosen opam switch overwrites `exec-path'.")
-(defun opsw-save-current-env (opam-env)
+(defun opsw--save-current-env (opam-env)
"Save the current environment values relevant to opam.
Argument OPAM-ENV, coming from calling `opam env', is only used
to find the environment variables to save. `exec-path' is saved
in addition to environment variables."
- (setq opsw-saved-env
+ (setq opsw--saved-env
(mapcar (lambda (x) (list (car x) (getenv (car x)))) opam-env))
- (setq opsw-saved-exec-path exec-path))
+ (setq opsw--saved-exec-path exec-path))
-(defun opsw-set-env (opam-env)
+(defun opsw--set-env (opam-env)
"Sets a new opam environment.
Environment variables in OPAM-ENV are put into the environment of
the current Emacs session. `exec-path' is changed to match the
@@ -203,39 +203,39 @@ It is unclear which value in `exec-path' corresponds to a
previously set opam switch and also which entry in the PATH
environment variable in OPAM-ENV corresponds to the new switch.
Therefore this function uses the following heuristic. First all
-entries in `exec-path' that match `opsw-root' are deleted. Then,
-the first entry for PATH that maches `opsw-root' is added at the
+entries in `exec-path' that match `opsw--root' are deleted. Then,
+the first entry for PATH that maches `opsw--root' is added at the
front of `exec-path'."
(let ((new-bin-dir
(seq-find
- (lambda (dir) (string-prefix-p opsw-root dir))
+ (lambda (dir) (string-prefix-p opsw--root dir))
(parse-colon-path (cadr (assoc "PATH" opam-env))))))
(unless new-bin-dir
(error "No opam-root directory in PATH"))
(mapc (lambda (x) (setenv (car x) (cadr x))) opam-env)
(setq exec-path
- (seq-remove (lambda (dir) (string-prefix-p opsw-root dir))
exec-path))
+ (seq-remove (lambda (dir) (string-prefix-p opsw--root dir))
exec-path))
(push new-bin-dir exec-path)))
-(defun opsw-reset-env ()
+(defun opsw--reset-env ()
"Reset process environment to the state before setting the first opam switch.
Reset all environment variables and `exec-path' to the values
they had in this emacs session before the first chosen opam
switch overwrote them."
- (mapc (lambda (x) (setenv (car x) (cadr x))) opsw-saved-env)
- (setq exec-path opsw-saved-exec-path)
- (setq opsw-saved-env nil)
- (setq opsw-saved-exec-path nil))
+ (mapc (lambda (x) (setenv (car x) (cadr x))) opsw--saved-env)
+ (setq exec-path opsw--saved-exec-path)
+ (setq opsw--saved-env nil)
+ (setq opsw--saved-exec-path nil))
-(defun opsw-get-current-switch ()
+(defun opsw--get-current-switch ()
"Return name of current switch or \"<none>\"."
(let ((current-switch (getenv "OPAM_SWITCH_PREFIX")))
(if current-switch
(file-name-nondirectory current-switch)
"<none>")))
-(defun opsw-set-switch (switch-name)
+(defun opsw--set-switch (switch-name)
"Chose and set an opam switch.
Set opam swith SWITCH-NAME, which must be a valid opam switch
name. When called interactively, the switch name must be entered
@@ -258,46 +258,45 @@ runs. This a can be used to inform other modes that may
run
background processes that depend on the currently active opam
switch.
-For obvious resons, `opsw-set-switch' will only affect emacs and
+For obvious resons, `opsw--set-switch' will only affect emacs and
not any other shells outside emacs."
(interactive
- (let* ((switches (opsw-get-switches))
- (default (car switches))
- (current-switch (opsw-get-current-switch)))
+ (let* ((switches (opsw--get-switches))
+ (current-switch (opsw--get-current-switch)))
(list
(completing-read
(format "current switch %s; switch to (empty to reset): "
current-switch)
- switches nil t "" 'opsw-switch-history nil))))
- (when (and (equal switch-name "") (not opsw-saved-env))
+ switches nil t "" 'opsw--switch-history nil))))
+ (when (and (equal switch-name "") (not opsw--saved-env))
(error "No saved opam environment, cannot reset."))
(if (equal switch-name "")
- (opsw-reset-env)
- (let ((output-string (opsw-command-as-string "env" switch-name t))
+ (opsw--reset-env)
+ (let ((output-string (opsw--command-as-string "env" switch-name t))
opam-env)
(unless output-string
(error
"opam env %s failed - probably because of invalid opam switch \"%s\""
switch-name switch-name))
(setq opam-env (car (read-from-string output-string)))
- (unless opsw-saved-env
- (opsw-save-current-env opam-env))
- (opsw-set-env opam-env)))
+ (unless opsw--saved-env
+ (opsw--save-current-env opam-env))
+ (opsw--set-env opam-env)))
(run-hooks 'opam-switch-change-opam-switch-hook))
-(defalias 'opam-switch-set-switch #'opsw-set-switch)
+(defalias 'opam-switch-set-switch #'opsw--set-switch)
;;; minor mode, keymap and menu
-(defvar opsw-mode-keymap (make-sparse-keymap)
+(defvar opsw--mode-keymap (make-sparse-keymap)
"Keymap for `opam-switch-mode'")
-(defun opsw-menu-items ()
+(defun opsw--menu-items ()
"Create list of opam switches as menu items for `easy-menu'."
(nconc
;; first the current switch as info with a separator
'(["current switch: " nil
:active t
- :suffix (opsw-get-current-switch)
+ :suffix (opsw--get-current-switch)
:help "Shows the currently selected opam switch"]
"-------")
;; then the list with all the real opam switches
@@ -305,18 +304,18 @@ not any other shells outside emacs."
(lambda (switch)
(vconcat
`(,switch
- (opsw-set-switch ,switch)
+ (opsw--set-switch ,switch)
:active t
:help ,(concat "select opam switch \"" switch "\""))))
- (opsw-get-switches))
+ (opsw--get-switches))
;; now reset as last element
'(
- ["reset" (opsw-set-switch "")
- :active opsw-saved-env
+ ["reset" (opsw--set-switch "")
+ :active opsw--saved-env
:help "reset to state when emacs was started"]
)))
-(defun opsw-setup-opam-switch-mode ()
+(defun opsw--setup-opam-switch-mode ()
"Re-define menu for `opam-switch-mode'.
This function runs when `opam-switch-mode' is enabled to setup
`opam-switch-mode'. Currently it only redefines the menu.
@@ -324,11 +323,11 @@ This function runs when `opam-switch-mode' is enabled to
setup
Note that the code for setting up the keymap and running the hook
is automatically created by `define-minor-mode'."
(easy-menu-define
- opsw-mode-menu
- opsw-mode-keymap
+ opsw--mode-menu
+ opsw--mode-keymap
"opam mode menu"
(cons "opam-switch"
- (opsw-menu-items))))
+ (opsw--menu-items))))
(define-minor-mode opam-switch-mode
"Toggle opam mode"
@@ -337,10 +336,10 @@ is automatically created by `define-minor-mode'."
;; lighter
" OPSW"
;; keymap
- opsw-mode-keymap
+ opsw--mode-keymap
:group 'opam-switch-mode
;; body
(when opam-switch-mode
- (opsw-setup-opam-switch-mode)))
+ (opsw--setup-opam-switch-mode)))
(provide 'opam-switch-mode)
- [nongnu] branch elpa/opam-switch-mode created (now a306f75d82), ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode dea35145a3 30/31: Merge pull request #7 from ProofGeneral/add-doc, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 515d08dfb3 09/31: check and handle opam errors, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode cad8510077 18/31: refactor: Run `M-x package-lint-current-buffer` and address its feedback, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 0db601100c 17/31: docs: Run `M-x checkdoc` and address its feedback, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 3d63566b0d 04/31: provide README, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode dd6a86ddad 23/31: Add LICENSE, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 16b8276f85 13/31: use -- for internal stuff,
ELPA Syncer <=
- [nongnu] elpa/opam-switch-mode 5f3d2102ae 26/31: Add OCaml keyword and https://opam.ocaml.org URL, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 7c648a0719 16/31: docs: details (#3), ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 22fa9efcb6 27/31: docs(README.md): Add install section, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode f62c708225 14/31: typo fix, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 95a3b4225a 15/31: fix: (opam-switch-mode) × 3 bug (#4), ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode a306f75d82 31/31: docs(README.md): detail, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 7306ce0fee 10/31: add separator in menu after current switch, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode e2ed274519 05/31: add emacs code documentation, also delete default switch parsing, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 7de138a0e9 07/31: add minor mode with menu bar menu, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode e681cbdcb7 29/31: chore: Update header and maintainer mailing list, ELPA Syncer, 2022/11/14