From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Erik Martin-Dorel <erik.martin-dorel@irit.fr>
Cc: emacs-devel@gnu.org
Subject: Re: [nongnu] elpa/opam-switch-mode 8b8670ca8b 1/3: feat(opam-switch-mode-lighter): Show the switch name in the mode-bar
Date: Tue, 11 Jul 2023 16:21:33 -0400 [thread overview]
Message-ID: <jwvedleusc6.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20230711200015.24AC2C06C6C@vcs2.savannah.gnu.org> (ELPA Syncer's message of "Tue, 11 Jul 2023 16:00:14 -0400 (EDT)")
Salut Erik¸
> + (progn (opam-switch-set-switch ,switch)
> + (redraw-display))
> :active t
> :help ,(concat "Select opam switch \"" switch "\"")])
> (opam-switch--get-switches))
> ;; now reset as last element
> '(
> - ["reset" (opam-switch-set-switch "")
> + ["reset"
> + (progn (opam-switch-set-switch "")
> + (redraw-display))
Instead of `redraw-display` you want `force-mode-line-update`.
And you probably want to put it into `opam-switch-set-switch` rather
than duplicating it after every call:
Also, in some circumstances the mode lines can be updated fairly often
(e.g. after every key press, and/or every process output received by
a filter), so it might be worthwhile to memoize/precompute the
lighter rather than recompute it every time the modeline is updated.
So maybe the patch below?
Stefan
diff --git a/opam-switch-mode.el b/opam-switch-mode.el
index 0ec42aa123..b13cbb75d7 100644
--- a/opam-switch-mode.el
+++ b/opam-switch-mode.el
@@ -93,6 +93,8 @@ background process before the opam switch changes."
;;; Code:
+(defvar opam-switch--mode-lighter nil)
+
(defun opam-switch--run-command-without-stderr (sub-cmd
&optional switch sexp
&rest args)
@@ -321,6 +323,8 @@ not any other shells outside Emacs."
(unless opam-switch--saved-env
(opam-switch--save-current-env opam-env))
(opam-switch--set-env opam-env prefix)))
+ (setq opam-switch--mode-lighter nil)
+ (force-mode-line-update t)
(run-hooks 'opam-switch-change-opam-switch-hook))
(define-obsolete-function-alias 'opam-switch--set-switch
@@ -343,17 +347,13 @@ not any other shells outside Emacs."
;; then the list with all the real opam switches
(mapcar
(lambda (switch)
- `[,switch
- (progn (opam-switch-set-switch ,switch)
- (redraw-display))
+ `[,switch (opam-switch-set-switch ,switch)
:active t
:help ,(concat "Select opam switch \"" switch "\"")])
(opam-switch--get-switches))
;; now reset as last element
'(
- ["reset"
- (progn (opam-switch-set-switch "")
- (redraw-display))
+ ["reset" (opam-switch-set-switch "")
:active opam-switch--saved-env
:help "Reset to state when Emacs was started"])))
@@ -376,10 +376,12 @@ is automatically created by `define-minor-mode'."
(defun opam-switch-mode-lighter ()
"Return the lighter for opam-switch-mode which indicates the current switch."
- (let* ((current-switch (opam-switch--get-current-switch))
- ;; handle the case of local switches for better UX
- (shortened (replace-regexp-in-string ".*/" "…/" current-switch t t)))
- (format " OPSW-%s" shortened)))
+ (or opam-switch--mode-lighter
+ (let* ((current-switch (opam-switch--get-current-switch))
+ ;; handle the case of local switches for better UX
+ (shortened (replace-regexp-in-string ".*/" "…/"
+ current-switch t t)))
+ (setq opam-switch--mode-lighter (format " OPSW-%s" shortened)))))
;;;###autoload
(define-minor-mode opam-switch-mode
next parent reply other threads:[~2023-07-11 20:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <168910561415.26377.10324105754705665342@vcs2.savannah.gnu.org>
[not found] ` <20230711200015.24AC2C06C6C@vcs2.savannah.gnu.org>
2023-07-11 20:21 ` Stefan Monnier [this message]
2023-07-11 21:09 ` [nongnu] elpa/opam-switch-mode 8b8670ca8b 1/3: feat(opam-switch-mode-lighter): Show the switch name in the mode-bar Erik Martin-Dorel
2023-07-11 22:09 ` Stefan Monnier
2023-07-12 12:13 ` Erik Martin-Dorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvedleusc6.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=erik.martin-dorel@irit.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).