[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/opam-switch-mode 8a021ff128 12/31: rename to opam-switch-m
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/opam-switch-mode 8a021ff128 12/31: rename to opam-switch-mode; use opsw as prefix for internals |
Date: |
Mon, 14 Nov 2022 09:00:00 -0500 (EST) |
branch: elpa/opam-switch-mode
commit 8a021ff1286dbc3d0ee9b4554ec6d92e62a1039f
Author: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
Commit: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
rename to opam-switch-mode; use opsw as prefix for internals
---
README.md | 53 +++++------
opam-mode.el => opam-switch-mode.el | 181 ++++++++++++++++++------------------
2 files changed, 117 insertions(+), 117 deletions(-)
diff --git a/README.md b/README.md
index c5fe341420..24059e2e76 100644
--- a/README.md
+++ b/README.md
@@ -1,45 +1,42 @@
-# opam mode
+# opam switch mode
-Provide command `opam-set-switch` to change the opam switch of the
-running emacs session and minor mode `opam-mode` to select the opam
+Provide command `opam-switch-set-switch` to change the opam switch of the
+running emacs session and minor mode `opam-switch-mode` to select the opam
switch via a menu bar menu.
-The menu is generated each time the minor mode is enabled and
-contains the switches that are known at that time. If you create a
-new switch, re-enable the minor mode to get it added to the menu.
-The menu contains an additional entry "reset" to reset the
-environment to the state when emacs was started.
+The menu is generated each time the minor mode is enabled and contains the
+switches that are known at that time. If you create a new switch, re-enable
+the minor mode to get it added to the menu. The menu contains an additional
+entry "reset" to reset the environment to the state when emacs was started.
-## Command `opam-set-switch`
+## Command `opam-switch-set-switch`
-Invoke with `M-x opam-set-switch`.
+Invoke with `M-x opam-switch-set-switch`.
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
-in the minibuffer, which forces completion to a valid switch name
-or the empty string.
+Set opam swith SWITCH-NAME, which must be a valid opam switch name. When
+called interactively, the switch name must be entered in the minibuffer,
+which forces completion to a valid switch name or the empty string.
-Setting the opam switch for the first time inside emacs will save
-the current environment. Using the empty string for SWITCH-NAME
-will reset the environment to the saved values.
+Setting the opam switch for the first time inside emacs will save the
+current environment. Using the empty string for SWITCH-NAME will reset the
+environment to the saved values.
-The switch is set such that all process invocations from emacs
-respect the newly set opam switch. In addition to setting
-environment variables such as PATH and CAML_LD_LIBRARY_PATH, this
-also sets `exec-path`, which controls emacs' subprocesses
-(`call-process`, `make-process` and similar functions).
+The switch is set such that all process invocations from emacs respect the
+newly set opam switch. In addition to setting environment variables such as
+PATH and CAML_LD_LIBRARY_PATH, this also sets `exec-path`, which controls
+emacs' subprocesses (`call-process`, `make-process` and similar functions).
-When the switch is changed, `opam-change-opam-switch-hook` runs. This
-can be used to inform other modes that may run background processes
+When the switch is changed, `opam-switch-change-opam-switch-hook` runs.
+This can be used to inform other modes that may run background processes
that depend on the currently active opam switch.
-For obvious resons, `opam-set-switch` will only affect emacs and
-not any other shells outside emacs.
+For obvious resons, `opam-switch-set-switch` will only affect emacs and not
+any other shells outside emacs.
## Opam mode aware modes
-- Proof General can kill the coq background process, when the
- opam switch changes, see `coq-kill-coq-on-opam-switch`.
+- Proof General can kill the coq background process, when the opam switch
+ changes, see `coq-kill-coq-on-opam-switch`.
diff --git a/opam-mode.el b/opam-switch-mode.el
similarity index 67%
rename from opam-mode.el
rename to opam-switch-mode.el
index 967408f824..eca2958299 100644
--- a/opam-mode.el
+++ b/opam-switch-mode.el
@@ -1,4 +1,4 @@
-;;; opam-mode.el --- select opam switches within emacs -*- lexical-binding:
t; -*-
+;;; opam-switch-mode.el --- select opam switches within emacs -*-
lexical-binding: t; -*-
;;
;; Copyright (C) 2021 Hendrik Tews
;;
@@ -24,14 +24,15 @@
;;
;;; Commentary:
;;
-;; Provide command `opam-set-switch' to change the opam switch of the
-;; running emacs session and minor mode `opam-mode' to select the opam
-;; switch via a menu bar menu.
+;; Provide command `opam-switch-set-switch' to change the opam switch
+;; of the running emacs session and minor mode `opam-switch-mode' to
+;; select the opam switch via a menu bar menu.
;;
-;; `opam-set-switch' reads the name of the switch in the minibuffer,
-;; providing completion with all available switches. With no input
-;; (i.e., leaving the minibuffer empty) the environment is reset to
-;; the state before the first call of `opam-set-switch'.
+;; `opam-switch-set-switch' reads the name of the switch in the
+;; minibuffer, providing completion with all available switches. With
+;; no input (i.e., leaving the minibuffer empty) the environment is
+;; reset to the state before the first call of
+;; `opam-switch-set-switch'.
;;
;; The menu is generated each time the minor mode is enabled and
;; contains the switches that are known at that time. If you create a
@@ -39,8 +40,8 @@
;; The menu contains an additional entry "reset" to reset the
;; environment to the state when emacs was started.
;;
-;; For obvious reasons, `opam-set-switch' does not change the switch
-;; of any other shell.
+;; For obvious reasons, `opam-switch-set-switch' does not change the
+;; switch of any other shell.
;;
;;
@@ -48,24 +49,24 @@
;;; User options and variables
-(defgroup opam-mode ()
+(defgroup opam-switch-mode ()
"Customization for opam switch support in Emacs"
:group 'external)
-(defcustom opam-program-name "opam"
+(defcustom opsw-program-name "opam"
"Name or path of the opam binary."
- :group 'opam-mode
+ :group 'opam-switch-mode
:type 'string)
-(defcustom opam-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-mode
+ :group 'opam-switch-mode
:type '(repeat string))
-(defcustom opam-common-environment
+(defcustom opsw-common-environment
'("OPAMUTF8=never"
"OPAMCOLOR=never"
"LC_ALL=C")
@@ -76,20 +77,20 @@ element should have the form of ENVVARNAME=VALUE.
The process environment must ensure that output is plain ascii
without color, non-ascii arrow symbols and that it is in English.
Otherwise parsing the output of opam commands won't work."
- :group 'opam-mode
+ :group 'opam-switch-mode
:type '(repeat string))
-(defcustom opam-change-opam-switch-hook nil
+(defcustom opam-switch-change-opam-switch-hook nil
"Hook run when the opam switch changes.
This is used, for instance, to let Proof General kill the coq
background process when the opam switch changes."
- :group 'opam-mode
+ :group 'opam-switch-mode
:type '(repeat function))
;;; Code
-(defun opam-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.
@@ -105,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 opam-common-environment process-environment))
- (options (append args opam-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" opam-program-name sub-cmd options)
- (apply 'process-file opam-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 opam-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 `opam-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 'opam-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 opam-get-root ()
+(defun opsw-get-root ()
"Get the opam root directory.
This is the opam variable 'root'."
- (let ((root (opam-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 opam-root (opam-get-root)
+(defconst opsw-root (opsw-get-root)
"The opam root directory.")
;; Example output of opam switch. The warning is output on stderr.
@@ -155,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 opam-get-switches ()
+(defun opsw-get-switches ()
"Return all opam switches as list of strings."
(let (opam-switches)
(with-temp-buffer
- (unless (eq (opam-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))
@@ -168,31 +169,31 @@ This is the opam variable 'root'."
(push (match-string 1) opam-switches))
opam-switches)))
-(defvar opam-switch-history nil
- "Minibuffer history list for `opam-set-switch'.")
+(defvar opsw-switch-history nil
+ "Minibuffer history list for `opsw-set-switch'.")
-(defvar opam-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 opam-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 opam-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 opam-saved-env
+ (setq opsw-saved-env
(mapcar (lambda (x) (list (car x) (getenv (car x)))) opam-env))
- (setq opam-saved-exec-path exec-path))
+ (setq opsw-saved-exec-path exec-path))
-(defun opam-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
@@ -202,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 `opam-root' are deleted. Then,
-the first entry for PATH that maches `opam-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 opam-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 opam-root dir))
exec-path))
+ (seq-remove (lambda (dir) (string-prefix-p opsw-root dir))
exec-path))
(push new-bin-dir exec-path)))
-(defun opam-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))) opam-saved-env)
- (setq exec-path opam-saved-exec-path)
- (setq opam-saved-env nil)
- (setq opam-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 opam-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 opam-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
@@ -252,49 +253,51 @@ also sets `exec-path', which controls emacs'
subprocesses (`call-process', `make-process' and similar
functions).
-When the switch is changed, `opam-change-opam-switch-hook' runs. This
-can be used to inform other modes that may run background processes
-that depend on the currently active opam switch.
+When the switch is changed, `opam-switch-change-opam-switch-hook'
+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, `opam-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 (opam-get-switches))
+ (let* ((switches (opsw-get-switches))
(default (car switches))
- (current-switch (opam-get-current-switch)))
+ (current-switch (opsw-get-current-switch)))
(list
(completing-read
(format "current switch %s; switch to (empty to reset): "
current-switch)
- switches nil t "" 'opam-switch-history nil))))
- (when (and (equal switch-name "") (not opam-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 "")
- (opam-reset-env)
- (let ((output-string (opam-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 opam-saved-env
- (opam-save-current-env opam-env))
- (opam-set-env opam-env)))
- (run-hooks 'opam-change-opam-switch-hook))
+ (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)
;;; minor mode, keymap and menu
-(defvar opam-mode-keymap (make-sparse-keymap)
- "Keymap for `opam-mode'")
+(defvar opsw-mode-keymap (make-sparse-keymap)
+ "Keymap for `opam-switch-mode'")
-(defun opam-menu-items ()
- "Create list or opam switches as menu items for `easy-menu'."
+(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 (opam-get-current-switch)
+ :suffix (opsw-get-current-switch)
:help "Shows the currently selected opam switch"]
"-------")
;; then the list with all the real opam switches
@@ -302,42 +305,42 @@ not any other shells outside emacs."
(lambda (switch)
(vconcat
`(,switch
- (opam-set-switch ,switch)
+ (opsw-set-switch ,switch)
:active t
:help ,(concat "select opam switch \"" switch "\""))))
- (opam-get-switches))
+ (opsw-get-switches))
;; now reset as last element
'(
- ["reset" (opam-set-switch "")
- :active opam-saved-env
+ ["reset" (opsw-set-switch "")
+ :active opsw-saved-env
:help "reset to state when emacs was started"]
)))
-(defun opam-setup-opam-mode ()
- "Re-define menu when for `opam-mode'.
-This function runs when `opam-mode' is enabled to setup
-`opam-mode'. Currently it only redefines the menu.
+(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.
Note that the code for setting up the keymap and running the hook
is automatically created by `define-minor-mode'."
(easy-menu-define
- opam-mode-menu
- opam-mode-keymap
+ opsw-mode-menu
+ opsw-mode-keymap
"opam mode menu"
- (cons "opam"
- (opam-menu-items))))
+ (cons "opam-switch"
+ (opsw-menu-items))))
-(define-minor-mode opam-mode
+(define-minor-mode opam-switch-mode
"Toggle opam mode"
;; init value - should be nil
nil
;; lighter
- " OP"
+ " OPSW"
;; keymap
- opam-mode-keymap
- :group 'opam-mode
+ opsw-mode-keymap
+ :group 'opam-switch-mode
;; body
- (when opam-mode
- (opam-setup-opam-mode)))
+ (when opam-switch-mode
+ (opsw-setup-opam-switch-mode)))
-(provide 'opam-mode)
+(provide 'opam-switch-mode)
- [nongnu] elpa/opam-switch-mode 7c648a0719 16/31: docs: details (#3), (continued)
- [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
- [nongnu] elpa/opam-switch-mode a83de84719 19/31: refactor: Replace `opsw--` with `opam-switch--`, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 8a021ff128 12/31: rename to opam-switch-mode; use opsw as prefix for internals,
ELPA Syncer <=
- [nongnu] elpa/opam-switch-mode df290bd0e3 21/31: Merge pull request #6 from ProofGeneral/prepare-melpa, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode eaf04b959d 25/31: fix: Improve error handling further (if opam can't be found), ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 9d8aa6d5dc 08/31: display current switch in menu, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 2c5ccd61f8 24/31: fix: Address review comments, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode d7ccecbf51 11/31: reset proof shell in Proof General via a hook function, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 3a1c181d04 01/31: first version, can set but not reset, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode da49a0980b 03/31: license and minimal documentation, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 0c2ecc2834 02/31: add reset, cleanup, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 4f05665f5c 22/31: fix: Add missing autoloads, ELPA Syncer, 2022/11/14
- [nongnu] elpa/opam-switch-mode 4334933613 28/31: docs(README.md): Add MELPA badge, ELPA Syncer, 2022/11/14