[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: beginning-of-buffer computations
From: |
Barry Margolin |
Subject: |
Re: beginning-of-buffer computations |
Date: |
Thu, 29 Jan 2015 17:17:16 -0500 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.18932.1422563201.1147.help-gnu-emacs@gnu.org>,
Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
> Hello people,
>
> I'm continuing my journey through simple.el, and I've just found
> something strange. Apparently, a PhD in maths is not enough to grok the
> arithmetic operations in beginning-of-buffer...;-)
>
> (goto-char (if (and arg (not (consp arg)))
> (+ (point-min)
> (if (> size 10000)
> ;; Avoid overflow for large buffer sizes!
> (* (prefix-numeric-value arg)
> (/ size 10))
> (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
> (point-min)))
>
> Now I pretty much see what is going on for "large buffers". For smaller
> ones, I'm wondering what is the rationale behind the `+ 10' part? It
> approximately adds one to the result (of course, the result is truncated
> to the next-lower-integer, so it's not that, ekhm, simple) - but why?
Good question. I don't think there's any difference between that and
(+ 1 (/ (* size (prefix-numeric-value arg)) 10))
It would make more sense if it were adding 5, which would be the way to
round up.
>
> (Not to mention the next line - not shown here - which `forward-line's
> by 1. Why not just (beginning-of-line) instead?)
forward-line ignores field boundaries, beginning-of-line doesn't.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***