emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 7f0b69e: Make `C-u w' in the Gnus Summary buffer op


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 7f0b69e: Make `C-u w' in the Gnus Summary buffer open externally
Date: Thu, 25 Jul 2019 14:11:42 -0400 (EDT)

branch: master
commit 7f0b69e8ed4ea0fd03ac779d8c6af809f991d357
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Make `C-u w' in the Gnus Summary buffer open externally
    
    * doc/misc/gnus.texi (Article Commands): Document new behaviour.
    
    * lisp/gnus/gnus-sum.el (gnus-shorten-url): New function.
    (gnus-summary-browse-url): Change function to make `C-u' use the
    external browser (as Gnus does when you hit URLs manually).  Don't
    use an initial input.
---
 doc/misc/gnus.texi    |  4 ++--
 lisp/gnus/gnus-sum.el | 44 +++++++++++++++++++++++++++++++-------------
 2 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index f688e84..cc6873c 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10163,8 +10163,8 @@ do so.
 @cindex url
 @findex gnus-summary-browse-url
 Scan the article buffer for links, and offer them to the user for
-browsing with @code{browse-url}.  By default, only scan the article
-body; with a prefix arg, also scan the article headers.
+browsing with @code{browse-url}.  With a prefix argument, browse with
+@code{shr-external-browser} instead.
 
 @end table
 
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 06d3db8..ec807bd 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -67,6 +67,8 @@
 (require 'gnus-util)
 (require 'gmm-utils)
 (require 'mm-decode)
+(require 'shr)
+(require 'url)
 (require 'nnoo)
 (eval-when-compile
   (require 'subr-x))
@@ -9461,32 +9463,48 @@ The 1st element is the widget named by 
`gnus-collect-urls-primary-text'."
       (push primary urls))
     (delete-dups urls)))
 
-(defun gnus-summary-browse-url (arg)
+(defun gnus-shorten-url (url max)
+  "Return an excerpt from URL."
+  (if (<= (length url) max)
+      url
+    (let ((parsed (url-generic-parse-url url)))
+      (concat (url-host parsed)
+             "..."
+             (substring (url-filename parsed)
+                        (- (length (url-filename parsed))
+                           (max (- max (length (url-host parsed))) 0)))))))
+
+(defun gnus-summary-browse-url (&optional external)
   "Scan the current article body for links, and offer to browse them.
-With prefix ARG, also collect links from message headers.
 
-Links are opened using `browse-url'.  If only one link is found,
-browse that directly, otherwise use completion to select a link.
-The first link marked in the article text with
-`gnus-collect-urls-primary-text' is the default."
+Links are opened using `browse-url' unless a prefix argument is
+given: Then `shr-external-browser' is used instead.
+
+If only one link is found, browse that directly, otherwise use
+completion to select a link.  The first link marked in the
+article text with `gnus-collect-urls-primary-text' is the
+default."
   (interactive "P")
   (let (urls target)
     (gnus-summary-select-article)
     (gnus-configure-windows 'article)
     (gnus-with-article-buffer
-      (if arg
-         (goto-char (point-min))
-       (article-goto-body)
-       ;; Back up a char, in case body starts with a widget.
-       (backward-char))
+      (article-goto-body)
+      ;; Back up a char, in case body starts with a widget.
+      (backward-char)
       (setq urls (gnus-collect-urls))
       (setq target
            (cond ((= (length urls) 1)
                   (car urls))
                  ((> (length urls) 1)
-                  (completing-read "URL to browse: " urls nil t (car urls)))))
+                  (completing-read (format "URL to browse (default %s): "
+                                           (gnus-shorten-url (car urls) 40))
+                                   urls nil t nil nil
+                                   (car urls)))))
       (if target
-         (browse-url target)
+         (if external
+             (funcall shr-external-browser target)
+           (browse-url target))
        (message "No URLs found.")))))
 
 (defun gnus-summary-isearch-article (&optional regexp-p)



reply via email to

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