[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/opam-switch-mode d3a7536570 2/4: refactor: Memoize (opam-s
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/opam-switch-mode d3a7536570 2/4: refactor: Memoize (opam-switch-mode-lighter) to speed-up mode-line updates |
Date: |
Wed, 12 Jul 2023 10:00:27 -0400 (EDT) |
branch: elpa/opam-switch-mode
commit d3a75365702ae49eaad9324bbb90f0234a4df451
Author: Erik Martin-Dorel <erik@martin-dorel.org>
Commit: Erik Martin-Dorel <erik@martin-dorel.org>
refactor: Memoize (opam-switch-mode-lighter) to speed-up mode-line updates
Patch devised by @monnier (thanks!)
Co-authored-by: Stefan Monnier <monnier@iro.umontreal.ca>
---
NEWS.md | 1 +
opam-switch-mode.el | 15 +++++++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index bbb0abbc54..f4a12c7265 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -15,6 +15,7 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/).
- **README.md**: Use vanilla (not GitHub-flavored) Markdown syntax for snippets
- Replace (redraw-display) with (force-mode-line-update t)
+- Memoize (opam-switch-mode-lighter) to speed-up mode-line updates
### Removed
diff --git a/opam-switch-mode.el b/opam-switch-mode.el
index 065873e2ee..42ef7c41e9 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,7 @@ 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))
@@ -375,10 +378,14 @@ 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