Skip to main content
don't spawn multiple new windows
Source Link

The above solution is great and I use it. I also added an additional function for when I don't want to display the images inline in the text, which creates scrolling issues.

(use-package url)
(defun display-online-image-in-new-buffer (&optional url)
  (interactive)
  (unless url (setq url (url-get-url-at-point)))
  (unless url
    (error "Couldn't find URL."))
  (let ((buffer (url-retrieve-synchronously url))
        (image-buffer (generate-new-buffer "*Image*")))
    (unwind-protect
        (with-current-buffer buffer
          (goto-char (point-min))
          (search-forward "\n\n")
          (let ((data (buffer-substring (point) (point-max))))
            (with-current-buffer image-buffer
              (insert-image (create-image data nil t))
              ;; SplitCheck if the current frame is already split
              (if (> (length (window-list)) 1)
                  (set-window-buffer (next-window) image-buffer)  ; Use existing window
                ;; Else, split the window and switch to the image buffer
                (split-window-right)
                (other-window 1)
                (switch-to-buffer image-buffer)
                (other-window -1))))
      (kill-buffer buffer))))

The above solution is great and I use it. I also added an additional function for when I don't want to display the images inline in the text, which creates scrolling issues.

(use-package url)
(defun display-online-image-in-new-buffer (&optional url)
 (interactive)
 (unless url (setq url (url-get-url-at-point)))
 (unless url
  (error "Couldn't find URL."))
 (let ((buffer (url-retrieve-synchronously url))
    (image-buffer (generate-new-buffer "*Image*")))
  (unwind-protect
    (with-current-buffer buffer
     (goto-char (point-min))
     (search-forward "\n\n")
     (let ((data (buffer-substring (point) (point-max))))
      (with-current-buffer image-buffer
       (insert-image (create-image data nil t))
       ;; Split the window and switch to the image buffer
       (split-window-right)
       (other-window 1)
       (switch-to-buffer image-buffer)
       (other-window -1))))
   (kill-buffer buffer))))

The above solution is great and I use it. I also added an additional function for when I don't want to display the images inline in the text, which creates scrolling issues.

(use-package url)
(defun display-online-image-in-new-buffer (&optional url)
  (interactive)
  (unless url (setq url (url-get-url-at-point)))
  (unless url
    (error "Couldn't find URL."))
  (let ((buffer (url-retrieve-synchronously url))
        (image-buffer (generate-new-buffer "*Image*")))
    (unwind-protect
        (with-current-buffer buffer
          (goto-char (point-min))
          (search-forward "\n\n")
          (let ((data (buffer-substring (point) (point-max))))
            (with-current-buffer image-buffer
              (insert-image (create-image data nil t))
              ;; Check if the current frame is already split
              (if (> (length (window-list)) 1)
                  (set-window-buffer (next-window) image-buffer)  ; Use existing window
                ;; Else, split the window and switch to the image buffer
                (split-window-right)
                (other-window 1)
                (switch-to-buffer image-buffer)
                (other-window -1))))
      (kill-buffer buffer))))
Source Link

The above solution is great and I use it. I also added an additional function for when I don't want to display the images inline in the text, which creates scrolling issues.

(use-package url)
(defun display-online-image-in-new-buffer (&optional url)
 (interactive)
 (unless url (setq url (url-get-url-at-point)))
 (unless url
  (error "Couldn't find URL."))
 (let ((buffer (url-retrieve-synchronously url))
    (image-buffer (generate-new-buffer "*Image*")))
  (unwind-protect
    (with-current-buffer buffer
     (goto-char (point-min))
     (search-forward "\n\n")
     (let ((data (buffer-substring (point) (point-max))))
      (with-current-buffer image-buffer
       (insert-image (create-image data nil t))
       ;; Split the window and switch to the image buffer
       (split-window-right)
       (other-window 1)
       (switch-to-buffer image-buffer)
       (other-window -1))))
   (kill-buffer buffer))))