[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement e7ca33ef5c 2/4: Change: (ement-room-browse-url) U
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement e7ca33ef5c 2/4: Change: (ement-room-browse-url) Use `read-multiple-choice' |
Date: |
Sat, 27 Jan 2024 00:57:56 -0500 (EST) |
branch: externals/ement
commit e7ca33ef5c8e14a4046bb23df941f39bfff03191
Author: Phil Sainty <phil@catalyst.net.nz>
Commit: Phil Sainty <phil@catalyst.net.nz>
Change: (ement-room-browse-url) Use `read-multiple-choice'
Fixes #241, and also provides mouse support.
Add: (ement--read-multiple-choice) Wrapper for `read-multiple-choice'
to bypass the hard-coded multi-column formatting in the help buffer
(as it tends to wrap poorly).
---
ement-lib.el | 13 +++++++++++++
ement-room.el | 26 ++++++++++++++++----------
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/ement-lib.el b/ement-lib.el
index 9682aa8f23..77718de2f8 100644
--- a/ement-lib.el
+++ b/ement-lib.el
@@ -1778,6 +1778,19 @@ seconds, etc."
(minutes (dividef seconds 60)))
(list years days hours minutes seconds))))
+(defun ement--read-multiple-choice (prompt choices &optional help)
+ "Wrapper for `read-multiple-choice'."
+ ;; Bypasses the hard-coded multi-column formatting in the help buffer
+ ;; (which often doesn't wrap nicely) in favour of one option per line.
+ (let ((help-format (if help
+ (concat (replace-regexp-in-string "%" "%%" help)
+ "\n\n%s")
+ "%s"))
+ (help-choices (mapconcat (lambda (c)
+ (format "%c: %s\n" (car c) (caddr c)))
+ choices)))
+ (read-multiple-choice prompt choices (format help-format help-choices))))
+
;;; Footer
(provide 'ement-lib)
diff --git a/ement-room.el b/ement-room.el
index fb7a4c5276..6f773225ef 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -1175,16 +1175,22 @@ are passed to `browse-url'."
(when event-id
(ement-room-find-event event-id)))
;; Room not joined: offer to join it or load link in browser.
- (pcase-exhaustive (completing-read
- (format "Room <%s> not joined on current session.
Join it, or load link with browser?"
- (or room-alias room-id))
- '("Join room" "Load link with browser") nil t)
- ("Join room" (ement-join-room (or room-alias room-id) ement-session
- :then (when event-id
- (lambda (room session)
- (ement-view-room room
session)
- (ement-room-find-event
event-id)))))
- ("Load link with browser"
+ (pcase-exhaustive
+ (cadr (ement--read-multiple-choice
+ (format "Room <%s> not joined on current session. Join it,
or load link with browser?"
+ (or room-alias room-id))
+ '((?j "join" "Join room in ement.el")
+ (?w "web browser" "Open URL in web browser"))
+ "\
+You are not currently joined to that room. You can either join the room
+in ement.el, or visit the link URL in your web browser."))
+ ("join"
+ (ement-join-room (or room-alias room-id) ement-session
+ :then (when event-id
+ (lambda (room session)
+ (ement-view-room room session)
+ (ement-room-find-event event-id)))))
+ ("web browser"
(let ((handler (cons ement-room-matrix.to-url-regexp
#'ement-room-browse-url)))
;; Note that `browse-url-handlers' was added in 28.1;
;; prior to that `browse-url-browser-function' served double-duty.