emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ement 5ef7417ee5 4/4: Merge: Improve view-room prompt


From: ELPA Syncer
Subject: [elpa] externals/ement 5ef7417ee5 4/4: Merge: Improve view-room prompt
Date: Sat, 27 Jan 2024 00:57:56 -0500 (EST)

branch: externals/ement
commit 5ef7417ee5e8d4e691a362282bce4172fce64dea
Merge: 97be65ab08 cad27f594f
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Merge: Improve view-room prompt
---
 README.org    |  3 ++-
 ement-lib.el  | 13 +++++++++++++
 ement-room.el | 40 ++++++++++++++++++++++++++++++----------
 3 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/README.org b/README.org
index 9b74d9494f..2df224121d 100644
--- a/README.org
+++ b/README.org
@@ -295,7 +295,8 @@ Ement.el doesn't support encrypted rooms natively, but it 
can be used transparen
 
 ** 0.15-pre
 
-Nothing new yet.
+*Changes*
++ Improve prompt used when viewing a room that is not joined.  
([[https://github.com/alphapapa/ement.el/issues/241][#241]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]].)
 
 ** 0.14
 
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 423551dd56..6f773225ef 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -1175,16 +1175,35 @@ 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" (apply #'browse-url url args)))))))
+        (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.
+             ;; TODO: Remove compat code when requiring Emacs >=28.
+             ;; (See also `ement-room-mode'.)
+             (cond ((boundp 'browse-url-handlers)
+                    (let ((browse-url-handlers (remove handler 
browse-url-handlers)))
+                      (apply #'browse-url url args)))
+                   ((consp browse-url-browser-function)
+                    (let ((browse-url-browser-function (remove handler 
browse-url-browser-function)))
+                      (apply #'browse-url url args)))
+                   (t
+                    (apply #'browse-url url args))))))))))
 
 (defun ement-room-find-event (event-id)
   "Go to EVENT-ID in current buffer."
@@ -2092,6 +2111,7 @@ and erases the buffer."
   ;; Set the URL handler.  Note that `browse-url-handlers' was added in 28.1;
   ;; prior to that `browse-url-browser-function' served double-duty.
   ;; TODO: Remove compat code when requiring Emacs >=28.
+  ;; (See also `ement-room-browse-url'.)
   (let ((handler (cons ement-room-matrix.to-url-regexp 
#'ement-room-browse-url)))
     (if (boundp 'browse-url-handlers)
         (setq-local browse-url-handlers (cons handler browse-url-handlers))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]