[comp.emacs] How to move point to end of buffer?

lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) (04/09/89)

(Running Gnu 18.52)

I'm having trouble moving the point to the end of a buffer, which may or not'
be displayed. If it's OK to display it, I can use set-window-point and all
is well, but If I can't I'm not so happy.

select-buffer appears to do an implicit save-excursion, in that I can
select my buffer, go tot eh end and insert a string, but point isn't moved.

I guess I want a set-buffer-point, but I can't find one.

Any ideas?

			Robert

		(lupton@uhccux.uhcc.hawaii.edu)

lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) (04/10/89)

Here's a solution that works:

> From: Julian Cowley  <julian>
> To: lupton@uhccux.uhcc.hawaii.edu
> Organization: University of Hawaii at Manoa
> 
> Well, I tried to find a way to do this, but it looks like there
> is no "real" way to do it except to write an ugly looking Lisp
> function.  I hope someone comes up with a more elegent solution!
> 
> (let* ((buf (get-buffer "test"))
>        (bufwin (get-buffer-window buf)))
>   (set-buffer buf)
>   (if (get-buffer-window buf)
>       (set-window-point bufwin (point-max))
>     (goto-char (point-max))))
> 
> Substitute the string "test" with the buffer variable you are
> using.
>

Here's a piece of code:

(defun tst ()
  (set-buffer (get-buffer "hello"))
  (goto-char (point-max))
  (insert-string "Hello World\n")
  (goto-char (point-max)))

(You'll have to create the buffer "hello" first).

  If you (tst) in buffer hello you'll end up at the end.
  If you (tst) when buffer hello is NOT displayed, then switch to it, you'll
end up at the end.
  If you have buffer hello displayed in a different window, then
(tst), you'll end up with dot unchanged.

			Robert

reingold@m.cs.uiuc.edu (04/10/89)

Use

        (goto-char (point-max))

assuming there is no clipping restriction in effect.  If there is, use

        (goto-char (1+ (buffer-size)))

which will work in any case.