(goto-char 1) vs. (goto-char (point-min))

Here’s a short tip for all you Elispers that clears up an obscure point about moving around in buffers. For a long time I’ve been dimly aware that the preferred way to move to the start of a buffer is

(goto-char (point-min))

instead of the simpler

(goto-char 1)

The reason for that is obvious once it’s pointed out: if the buffer is narrowed, the first point in the buffer may not be 1. Still, it never seemed to make a difference in practice. Xah Lee comes to the rescue with a concise post that explains what’s really going on. Take a look at Lee’s post to see why either form works but it is best to use (point-min).

As a final exercise, suppose that like Lee, you decide to replace every (goto-char 1) with (goto-char (point-min)) in all the .el files in, say, your ~/src directory. How would you do that?

This entry was posted in General and tagged , . Bookmark the permalink.