branch: externals/ebdb commit 7c6d15abd51299b81ba5fe389cfd9e1682154080 Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
Be smarter about displaying appended records * ebdb-com.el (ebdb-display-records): When records are appended to an existing buffer, we almost certainly want point to end up on them. Record the uuid of the first additional record, and try to move to its marker after redisplay. Additionally, use `recenter' instead of `set-window-start', as that's less likely to cause surprising scrolling behavior. --- ebdb-com.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ebdb-com.el b/ebdb-com.el index 8945668..6f4941f 100644 --- a/ebdb-com.el +++ b/ebdb-com.el @@ -756,7 +756,12 @@ name based on the current major mode." (setq fmt ebdb-default-multiline-formatter)) ;; `ebdb-make-buffer-name' is a generic function that ;; dispatches on the current major mode. - (let ((target-buffer (or buf (ebdb-make-buffer-name)))) + (let ((target-buffer (or buf (ebdb-make-buffer-name))) + ;; When appending, we want point to end up on the first of the + ;; appended records. Save the uuid, and later point a marker + ;; at it. Mostly useful for `follow-related'. + (target-record-uuid (ebdb-record-uuid (car records))) + target-record-marker) (with-current-buffer (get-buffer-create target-buffer) ;; If we are appending RECORDS to the ones already displayed, @@ -772,7 +777,11 @@ name based on the current major mode." (setq ebdb-records (mapcar (lambda (r) - (list r fmt (make-marker) nil)) + (let ((m (make-marker))) + (when (string= target-record-uuid + (ebdb-record-uuid r)) + (setq target-record-marker m)) + (list r fmt m nil))) records)) (ebdb-pop-up-window target-buffer select pop) @@ -795,8 +804,10 @@ name based on the current major mode." (message "Formatting EBDB...done.")) (set-buffer-modified-p nil) - (goto-char (point-min)) - (set-window-start (get-buffer-window (current-buffer)) (point))))) + (goto-char (or target-record-marker (point-min))) + (when (window-live-p (get-buffer-window)) + (with-selected-window (get-buffer-window) + (recenter)))))) (defun ebdb-undisplay-records (&optional buffer) "Undisplay records in *EBDB* BUFFER, leaving the buffer empty.