Function: eww-read-alternate-url

eww-read-alternate-url is a byte-compiled function defined in eww.el.gz.

Signature

(eww-read-alternate-url)

Documentation

Get the URL of an alternate link of this page.

If there is just one alternate link, return its URL. If there are multiple alternate links, prompt for one in the minibuffer with completion. If there are none, return nil.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eww.el.gz
(defun eww-read-alternate-url ()
  "Get the URL of an alternate link of this page.

If there is just one alternate link, return its URL.  If there
are multiple alternate links, prompt for one in the minibuffer
with completion.  If there are none, return nil."
  (when-let* ((alternates (eww--alternate-urls
                           (plist-get eww-data :dom)
                           (plist-get eww-data :url))))
    (let ((url-max-width
           (seq-max (mapcar #'string-pixel-width
                            (mapcar #'car alternates))))
          (title-max-width
           (seq-max (mapcar #'string-pixel-width
                            (mapcar #'caddr alternates))))
          (sep-width (string-pixel-width " ")))
      (if (cdr alternates)
            (completing-read
             "Alternate URL: "
             (completion-table-with-metadata
              alternates
              `((annotation-function
                 . ,(lambda (feed)
                      (let* ((attrs (alist-get feed
                                               alternates
                                               nil
                                               nil
                                               #'string=))
                             (type (car attrs))
                             (title (cadr attrs)))
                        (concat
                         (propertize " " 'display
                                     `(space :align-to
                                             (,(+ sep-width
                                                  url-max-width))))
                         title
                         (when type
                           (concat
                            (propertize " " 'display
                                        `(space :align-to
                                                (,(+ (* 2 sep-width)
                                                     url-max-width
                                                     title-max-width))))
                            "[" type "]"))))))))
             nil t)
        (caar alternates)))))