[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/opam-switch-mode 7de138a0e9 07/31: add minor mode with men
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/opam-switch-mode 7de138a0e9 07/31: add minor mode with menu bar menu |
Date: |
Mon, 14 Nov 2022 08:59:59 -0500 (EST) |
branch: elpa/opam-switch-mode
commit 7de138a0e9ea5ab5853d76b64b365180ea87b26b
Author: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
Commit: Hendrik Tews <Hendrik.Tews@kernkonzept.com>
add minor mode with menu bar menu
---
README.md | 13 ++++++-----
opam-mode.el | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 73 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 8707c20673..590ecd24fd 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,15 @@
# opam mode
Provide command `opam-set-switch` to change the opam switch of the
-running emacs session. The command reads the name of the switch in
-the minibuffer, providing completion with all available switches,
-see the documentation of `opam-set-switch` below.
+running emacs session and minor mode `opam-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.
-Contrary to the file name, this file does not (yet) provide a minor
-mode.
## Command `opam-set-switch`
diff --git a/opam-mode.el b/opam-mode.el
index 83790d21db..4c2364ec1d 100644
--- a/opam-mode.el
+++ b/opam-mode.el
@@ -25,16 +25,23 @@
;;; Commentary:
;;
;; Provide command `opam-set-switch' to change the opam switch of the
-;; running emacs session. The command 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'.
+;; running emacs session and minor mode `opam-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'.
+;;
+;; 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.
;;
;; For obvious reasons, `opam-set-switch' does not change the switch
;; of any other shell.
;;
-;; Contrary to the file name, this file does not (yet) provide a minor
-;; mode.
;;
(require 'seq)
@@ -246,4 +253,56 @@ not any other shells outside emacs."
(opam-save-current-env opam-env))
(opam-set-env opam-env))))
+
+;;; minor mode, keymap and menu
+
+(defvar opam-mode-keymap (make-sparse-keymap)
+ "Keymap for `opam-mode'")
+
+(defun opam-menu-items ()
+ "Create list or opam switches as menu items for `easy-menu'."
+ (nconc
+ ;; first the list with all the real opam switches
+ (mapcar
+ (lambda (switch)
+ (vconcat
+ `(,switch
+ (opam-set-switch ,switch)
+ :active t
+ :help ,(concat "select opam switch \"" switch "\""))))
+ (opam-get-switches))
+ ;; now reset as last element
+ '(
+ ["reset" (opam-set-switch "")
+ :active opam-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.
+
+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
+ "opam mode menu"
+ (cons "opam"
+ (opam-menu-items))))
+
+(define-minor-mode opam-mode
+ "Toggle opam mode"
+ ;; init value - should be nil
+ nil
+ ;; lighter
+ " OP"
+ ;; keymap
+ opam-mode-keymap
+ :group 'opam-mode
+ ;; body
+ (when opam-mode
+ (opam-setup-opam-mode)))
+
(provide 'opam-mode)
- [nongnu] elpa/opam-switch-mode dd6a86ddad 23/31: Add LICENSE, (continued)
- [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, 2022/11/14
- [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 <=
- [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, 2022/11/14
- [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