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)
          (let ((completion-extra-properties
                 (list :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 "]"))))))))
            (completing-read "Alternate URL: " alternates nil t))
        (caar alternates)))))