I'm trying to implement «effective append» for log buffer, e.g. if a point
is at point-max
position then insert text and move point
to new point-max
, otherwise append text and preserve point
position.
I though this will be very trivial code:
(with-current-buffer
(get-buffer-create "*scratch*")
(if (eq (point) (point-max))
(insert "\n;; ===\n")
(save-excursion
(goto-char (point-max))
(insert "\n;; ===\n"))))
However, this works as expected only if invoked in *scratch*
buffer:
- having point somewhere in the middle => text appended, point not moved
- having point at the end of buffer => text appended, point at the end
Now if I change buffer and invoke this command again, point never goes to new point-max and always stays where it was.
Simple tests showed that if
statement gives correct results always, thus it is correct branch selected. I also tried explicitly move point or do scroll in true
-branch, but nothing helped:
(if (eq (point) (point-max))
(progn
(insert "\n;; ===\n")
(View-scroll-to-buffer-end) ;; not works
(goto-char (point-max))) ;; so does it too
(…))
Am I missing something?
*scratch*
buffer is not visible in any window I have same behaviour: point does not move to the end of buffer even if it should. Maybe I misunderstood you?M-:
your code with*scratch*
as current buffer it works as expected. If I have other buffer as current with/without visible scratch buffer point does not moves all the time. There is alsowindow-point-insertion-type
but I need to learn about it and make some tests.