aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-inspect.el2
-rw-r--r--lisp/mastodon-media.el42
-rw-r--r--lisp/mastodon-notifications.el12
-rw-r--r--lisp/mastodon-profile.el6
-rw-r--r--lisp/mastodon-tl.el21
-rw-r--r--test/mastodon-media-tests.el2
6 files changed, 45 insertions, 40 deletions
diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el
index 351c92a..61cb1e3 100644
--- a/lisp/mastodon-inspect.el
+++ b/lisp/mastodon-inspect.el
@@ -75,7 +75,7 @@
(goto-char (point-min))
(while (search-forward "\n\n\n | " nil t)
(replace-match "\n | "))
- (mastodon-media--inline-images)))
+ (mastodon-media--inline-images (point-min) (point-max))))
(switch-to-buffer-other-window buffer)
(mastodon-mode)))
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el
index 2decce4..d06a6eb 100644
--- a/lisp/mastodon-media.el
+++ b/lisp/mastodon-media.el
@@ -193,8 +193,8 @@ MEDIA-TYPE is a symbol and either 'avatar or 'media-link."
'loading-failed)
:loading-failed))))))
-(defun mastodon-media--select-next-media-line ()
- "Find coordinates of the next media to load.
+(defun mastodon-media--select-next-media-line (end-pos)
+ "Find coordinates of the next media to load before END-POS.
Returns the list of (`start' . `end', `media-symbol') points of
that line and string found or nil no more media links were
@@ -206,7 +206,7 @@ found."
(null (get-text-property next-pos 'media-type))))
;; do nothing - the loop will proceed
)
- (when next-pos
+ (when (and next-pos (< next-pos end-pos))
(let ((media-type (get-text-property next-pos 'media-type)))
(cond
;; Avatars are just one character in the buffer
@@ -225,23 +225,25 @@ not been returned."
(or (string= "http://" (substring link 0 7))
(string= "https://" (substring link 0 8)))))
-(defun mastodon-media--inline-images ()
- "Find all `Media_Links:' in the buffer replacing them with the referenced image."
- (interactive)
- (goto-char (point-min))
- (let (line-details)
- (while (setq line-details (mastodon-media--select-next-media-line))
- (let* ((start (car line-details))
- (end (cadr line-details))
- (media-type (cadr (cdr line-details)))
- (image-url (get-text-property start 'media-url)))
- (if (not (mastodon-media--valid-link-p image-url))
- ;; mark it at least as not needing loading any more
- (put-text-property start end 'media-state 'invalid-url)
- ;; proceed to load this image asynchronously
- (put-text-property start end 'media-state 'loading)
- (mastodon-media--load-image-from-url
- image-url media-type start (- end start)))))))
+(defun mastodon-media--inline-images (search-start search-end)
+ "Find all `Media_Links:' in the range from SEARCH-START to SEARCH-END
+replacing them with the referenced image."
+ (save-excursion
+ (goto-char search-start)
+ (let (line-details)
+ (while (setq line-details (mastodon-media--select-next-media-line
+ search-end))
+ (let* ((start (car line-details))
+ (end (cadr line-details))
+ (media-type (cadr (cdr line-details)))
+ (image-url (get-text-property start 'media-url)))
+ (if (not (mastodon-media--valid-link-p image-url))
+ ;; mark it at least as not needing loading any more
+ (put-text-property start end 'media-state 'invalid-url)
+ ;; proceed to load this image asynchronously
+ (put-text-property start end 'media-state 'loading)
+ (mastodon-media--load-image-from-url
+ image-url media-type start (- end start))))))))
(defun mastodon-media--get-avatar-rendering (avatar-url)
"Returns the string to be written that renders the avatar at AVATAR-URL."
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index ddaaaf4..01068cb 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -111,15 +111,17 @@
(defun mastodon-notifications--by-type (note)
"Filters NOTE for those listed in `mastodon-notifications--types-alist'."
(let* ((type (mastodon-tl--field 'type note))
- (fun (cdr (assoc type mastodon-notifications--types-alist))))
- (when fun (funcall fun note))))
+ (fun (cdr (assoc type mastodon-notifications--types-alist)))
+ (start-pos (point)))
+ (when fun
+ (funcall fun note)
+ (when mastodon-tl--display-media-p
+ (mastodon-media--inline-images start-pos (point))))))
(defun mastodon-notifications--timeline (json)
"Format JSON in Emacs buffer."
(mapc #'mastodon-notifications--by-type json)
- (goto-char (point-min))
- (when mastodon-tl--display-media-p
- (mastodon-media--inline-images)))
+ (goto-char (point-min)))
(defun mastodon-notifications--get ()
"Display NOTIFICATIONS in buffer."
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 9dc5a82..fca1bd8 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -76,7 +76,8 @@
" ------------\n")
'success))
(setq mastodon-tl-update-point (point))
- (mastodon-tl--timeline json)))
+ (mastodon-media--inline-images (point-min) (point))
+ (mastodon-tl--timeline json)))
(mastodon-tl--goto-next-toot)))
(defun mastodon-profile--get-toot-author ()
@@ -112,8 +113,7 @@ FIELD is used to identify regions under 'account"
'byline 't
'toot-id (cdr (assoc 'id toot)) 'toot-json toot)
"\n"))
- tootv))
- (mastodon-media--inline-images))
+ tootv)))
(defun mastodon-profile--get-following ()
"Request a list of those who the user under point follows."
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 4d6d0b6..5411d42 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -635,13 +635,16 @@ the byline that takes one variable. By default it is `mastodon-tl--byline-author
ACTION-BYLINE is also an optional function for adding an action, such as boosting
favouriting and following to the byline. It also takes a single function. By default
it is `mastodon-tl--byline-boosted'"
- (insert
- (propertize
- (concat body
- (mastodon-tl--byline toot author-byline action-byline))
- 'toot-id (cdr (assoc 'id toot))
- 'toot-json toot)
- "\n\n"))
+ (let ((start-pos (point)))
+ (insert
+ (propertize
+ (concat body
+ (mastodon-tl--byline toot author-byline action-byline))
+ 'toot-id (cdr (assoc 'id toot))
+ 'toot-json toot)
+ "\n\n")
+ (when mastodon-tl--display-media-p
+ (mastodon-media--inline-images start-pos (point)))))
(defun mastodon-tl--toot(toot)
"Formats TOOT and insertes it into the buffer."
@@ -657,9 +660,7 @@ it is `mastodon-tl--byline-boosted'"
(defun mastodon-tl--timeline (toots)
"Display each toot in TOOTS."
(mapc 'mastodon-tl--toot toots)
- (goto-char (point-min))
- (when mastodon-tl--display-media-p
- (mastodon-media--inline-images)))
+ (goto-char (point-min)))
(defun mastodon-tl--get-update-function (&optional buffer)
"Get the UPDATE-FUNCTION stored in `mastodon-tl--buffer-spec'"
diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el
index 7031e90..a586be9 100644
--- a/test/mastodon-media-tests.el
+++ b/test/mastodon-media-tests.el
@@ -189,7 +189,7 @@
;; stub for the actual test:
(stub mastodon-media--load-image-from-url)
- (mastodon-media--inline-images)
+ (mastodon-media--inline-images (point-min) (point-max))
(should (eq 'loading (get-text-property marker-media-link 'media-state)))
(should (eq 'invalid-url (get-text-property marker-media-link-bad-url 'media-state)))