Go to the first, previous, next, last section, table of contents.


What happens in a large buffer

In beginning-of-buffer, the inner if expression tests whether the size of the buffer is greater than 10,000 characters. To do this, it uses the > function and the buffer-size function. The line looks like this:

(if (> (buffer-size) 10000)

When the buffer is large, the then-part of the if expression is evaluated. It reads like this (after formatting for easy reading):

(* 
  (prefix-numeric-value arg) 
  (/ (buffer-size) 10))

This expression is a multiplication, with two arguments to the function *.

The first argument is (prefix-numeric-value arg). When "P" is used as the argument for interactive, the value passed to the function as its argument is passed a "raw prefix argument", and not a number. (It is a number in a list.) To perform the arithmetic, a conversion is necessary, and prefix-numeric-value does the job.

The second argument is (/ (buffer-size) 10). This expression divides the numeric value of the buffer by ten. This produces a number that tells how many characters make up one tenth of the buffer size. (In Lisp, / is used for division, just as * is used for multiplication.)

In the multiplication expression as a whole, this amount is multiplied by the value of the prefix argument--the multiplication looks like this:

(* numeric-value-of-prefix-arg
   number-of-characters-in-one-tenth-of-the-buffer)

If, for example, the prefix argument is `7', the one-tenth value will be multiplied by 7 to give a position 70% of the way through the buffer.

The result of all this is that if the buffer is large, the goto-char expression reads like this:

(goto-char (* (prefix-numeric-value arg)
              (/ (buffer-size) 10)))

This puts the cursor where we want it.


Go to the first, previous, next, last section, table of contents.