Next: , Previous: , Up: beginning-of-buffer opt arg   [Contents][Index]

#### 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 computation of `size` that comes from the let expression.

In the old days, the function `buffer-size` was used. Not only was that function called several times, it gave the size of the whole buffer, not the accessible part. The computation makes much more sense when it handles just the accessible part. (See Narrowing and Widening, for more information on focusing attention to an ‘accessible’ part.)

The line looks like this:

```(if (> 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)
(/ 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 `(/ size 10)`. This expression divides the numeric value by ten—the numeric value of the size of the accessible portion of the buffer. 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-accessible-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 result of all this is that if the accessible portion of the buffer is large, the `goto-char` expression reads like this:

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

This puts the cursor where we want it.

Next: , Previous: , Up: beginning-of-buffer opt arg   [Contents][Index]