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

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

[nongnu] elpa/mastodon 51132d0868 08/27: Merge pull request 'Use display


From: ELPA Syncer
Subject: [nongnu] elpa/mastodon 51132d0868 08/27: Merge pull request 'Use display-buffer to allow customization' (#522) from rahguzar/mastodon.el:display-buffer into develop
Date: Fri, 23 Feb 2024 13:00:54 -0500 (EST)

branch: elpa/mastodon
commit 51132d08682b7b13473d24a4bf60417541905c81
Merge: a01eec0d57 2e6bcd41a9
Author: martianh <martianh@noreply.codeberg.org>
Commit: martianh <martianh@noreply.codeberg.org>

    Merge pull request 'Use display-buffer to allow customization' (#522) from 
rahguzar/mastodon.el:display-buffer into develop
    
    Reviewed-on: https://codeberg.org/martianh/mastodon.el/pulls/522
---
 lisp/mastodon-auth.el | 31 +++++++++++++------------------
 lisp/mastodon-http.el |  1 -
 lisp/mastodon-tl.el   |  4 ++--
 lisp/mastodon-toot.el | 19 ++++++-------------
 lisp/mastodon.el      | 14 ++++++++------
 5 files changed, 29 insertions(+), 40 deletions(-)

diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 279377ba2d..9f9d128188 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -105,30 +105,25 @@ code. Copy this code and paste it in the minibuffer 
prompt."
 
 (defun mastodon-auth--show-notice (notice buffer-name &optional ask)
   "Display NOTICE to user.
-NOTICE is displayed in vertical split occupying 50% of total
+By default NOTICE is displayed in vertical split occupying 50% of total
 width.  The buffer name of the buffer being displayed in the
 window is BUFFER-NAME.
 When optional argument ASK is given which should be a string, use
 ASK as the minibuffer prompt.  Return whatever user types in
 response to the prompt.
 When ASK is absent return nil."
-  (let ((buffer (get-buffer-create buffer-name))
-        (inhibit-read-only t)
-        ask-value window)
-    (set-buffer buffer)
-    (erase-buffer)
-    (insert notice)
-    (fill-region (point-min) (point-max))
-    (read-only-mode)
-    (setq window (select-window
-                  (split-window (frame-root-window) nil 'left)
-                  t))
-    (switch-to-buffer buffer t)
-    (when ask
-      (setq ask-value (read-string ask))
-      (kill-buffer buffer)
-      (delete-window window))
-    ask-value))
+  (if ask
+      (read-string ask)
+    (let ((buffer (get-buffer-create buffer-name))
+          (inhibit-read-only t))
+      (set-buffer buffer)
+      (erase-buffer)
+      (insert notice)
+      (fill-region (point-min) (point-max))
+      (read-only-mode)
+      (prog1 nil
+        (pop-to-buffer buffer '(display-buffer-in-side-window
+                                (side . left) (window-width . 0.5)))))))
 
 (defun mastodon-auth--request-authorization-code ()
   "Ask authorization code and return it."
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index a357672a12..541c92e66f 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -240,7 +240,6 @@ Callback to `mastodon-http--get-response-async', usually
 
 (defun mastodon-http--process-headers ()
   "Return an alist of http response headers."
-  (switch-to-buffer (current-buffer))
   (goto-char (point-min))
   (let* ((head-str (buffer-substring-no-properties
                     (point-min)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index d462918c74..d21edafe86 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -292,7 +292,7 @@ It is active where point is placed by 
`mastodon-tl--goto-next-item.'")
   "Evaluate BODY in a new or existing buffer called BUFFER.
 MODE-FUN is called to set the major mode.
 OTHER-WINDOW means call `switch-to-buffer-other-window' rather
-than `switch-to-buffer'."
+than `pop-to-buffer'."
   (declare (debug t)
            (indent 3))
   `(with-current-buffer (get-buffer-create ,buffer)
@@ -301,7 +301,7 @@ than `switch-to-buffer'."
        (funcall ,mode-fun)
        (if ,other-window
            (switch-to-buffer-other-window ,buffer)
-         (switch-to-buffer ,buffer))
+         (pop-to-buffer ,buffer '(display-buffer-same-window)))
        ,@body)))
 
 (defmacro mastodon-tl--do-if-item (&rest body)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index bffa20e1e5..462f92566a 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1698,20 +1698,13 @@ REPLY-REGION is a string to be injected into the 
buffer."
 URLs always = 23, and domain names of handles are not counted.
 This is how mastodon does it.
 CW is the content warning, which contributes to the character count."
-  (with-temp-buffer
-    (switch-to-buffer (current-buffer))
-    (insert toot-string)
-    (goto-char (point-min))
-    ;; handle URLs
-    (while (search-forward-regexp mastodon-toot-url-regex nil t)
-                                        ; "\\w+://[^ \n]*" old regex
-      (replace-match "xxxxxxxxxxxxxxxxxxxxxxx")) ; 23 x's
-    ;; handle @handles
-    (goto-char (point-min))
-    (while (search-forward-regexp mastodon-toot-handle-regex nil t)
-      (replace-match (match-string 2))) ; replace with handle only
+  (let* ((url-replacement (make-string 23 ?x))
+         (count-str (replace-regexp-in-string ; handle @handles
+                     mastodon-toot-handle-regex "\2"
+                     (replace-regexp-in-string ; handle URLs
+                      mastodon-toot-url-regex url-replacement toot-string))))
     (+ (length cw)
-       (length (buffer-substring (point-min) (point-max))))))
+       (length count-str))))
 
 
 ;;; DRAFTS
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 9dac1d1f49..142eced850 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -291,7 +291,7 @@ See `mastodon-toot-display-orig-in-reply-buffer'.")
                               (buffer-list))))) ; catch any other masto buffer
     (mastodon-return-credential-account :force)
     (if buffer
-        (switch-to-buffer buffer)
+        (pop-to-buffer buffer '(display-buffer-same-window))
       (mastodon-tl--get-home-timeline)
       (message "Loading Mastodon account %s on %s..."
                (mastodon-auth--user-acct)
@@ -337,7 +337,7 @@ from the server and load anew."
                   "*mastodon-notifications*")))
     (if (and (not force)
              (get-buffer buffer))
-        (progn (switch-to-buffer buffer)
+        (progn (pop-to-buffer buffer '(display-buffer-same-window))
                (mastodon-tl--update))
       (message "Loading your notifications...")
       (mastodon-tl--init-sync (or buffer-name "notifications")
@@ -435,10 +435,12 @@ Calls `mastodon-tl--get-buffer-type', which see."
 (defun mastodon-switch-to-buffer ()
   "Switch to a live mastodon buffer."
   (interactive)
-  (let* ((bufs (mastodon-live-buffers))
-         (buf-names (mapcar #'buffer-name bufs))
-         (choice (completing-read "Switch to mastodon buffer: "
-                                  buf-names)))
+  (let ((choice (read-buffer
+                 "Switch to mastodon buffer: " nil t
+                 (lambda (cand)
+                   (with-current-buffer
+                       (if (stringp cand) cand (car cand))
+                     (mastodon-tl--get-buffer-type))))))
     (switch-to-buffer choice)))
 
 (defun mastodon-mode-hook-fun ()



reply via email to

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