aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-tl.el
diff options
context:
space:
mode:
authorTassilo Horn <tsdh@gnu.org>2022-12-09 20:40:06 +0100
committerTassilo Horn <tsdh@gnu.org>2022-12-28 09:43:21 +0100
commit294bbb378a2f21c7d5b32a853567505b8128dbee (patch)
treebb9357c2c7260cd8c45a6293937ad35c270690dd /lisp/mastodon-tl.el
parentf4d8a0719e370d85e7b1b8c11d4a706770b799b8 (diff)
Keep current position of point after updates (fixes #349)
Set a marker (mastodon-tl--before-update-marker) before updating the buffer and reset point's position there afterwards.
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el36
1 files changed, 35 insertions, 1 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 156675a..899377a 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -149,11 +149,24 @@ font settings do not support it."
:type '(alist :key-type symbol :value-type string)
:group 'mastodon-tl)
+(defcustom mastodon-tl-position-after-update nil
+ "Defines where `point' should be located after a timeline update.
+Valid values are:
+- nil Top/bottom depending on timeline type
+- keep-point Keep original position of point
+- last-old-toot The last toot before the new ones"
+ :type '(choice (const :tag "Top/bottom depending on timeline type" nil)
+ (const :tag "Keep original position of point" keep-point)
+ (const :tag "The last toot before the new ones" last-old-toot)))
+
(defvar-local mastodon-tl--update-point nil
"When updating a mastodon buffer this is where new toots will be inserted.
If nil `(point-min)' is used instead.")
+(defvar-local mastodon-tl--after-update-marker nil
+ "Marker defining the position of point after the update is done.")
+
(defvar mastodon-tl--display-media-p t
"A boolean value stating whether to show media in timelines.")
@@ -2756,6 +2769,24 @@ from the start if it is nil."
#'mastodon-tl--update-timestamps-callback
buffer nil))))))))
+(defun mastodon-tl--set-after-update-marker ()
+ (if mastodon-tl-position-after-update
+ (let ((marker (make-marker)))
+ (set-marker marker
+ (cond
+ ((eq 'keep-point mastodon-tl-position-after-update)
+ (point))
+ ((eq 'last-old-toot mastodon-tl-position-after-update)
+ (next-single-property-change
+ (or mastodon-tl--update-point (point-min))
+ 'byline))
+ (error "Unknown mastodon-tl-position-after-update value %S"
+ mastodon-tl-position-after-update)))
+ ;; Make the marker advance if text gets inserted there.
+ (set-marker-insertion-type marker t)
+ (setq mastodon-tl--after-update-marker marker))
+ (setq mastodon-tl--after-update-marker nil)))
+
(defun mastodon-tl--update ()
"Update timeline with new toots."
(interactive)
@@ -2765,8 +2796,11 @@ from the start if it is nil."
(json (mastodon-tl--updated-json endpoint id)))
(if json
(let ((inhibit-read-only t))
+ (mastodon-tl--set-after-update-marker)
(goto-char (or mastodon-tl--update-point (point-min)))
- (funcall update-function json))
+ (funcall update-function json)
+ (when mastodon-tl--after-update-marker
+ (goto-char mastodon-tl--after-update-marker)))
(message "nothing to update"))))
(defun mastodon-tl--get-link-header-from-response (headers)