unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Luca Ferrari <fluca1978@infinito.it>
Cc: help-gnu-emacs@gnu.org
Subject: Re: creating a function that works for active region or whole buffer
Date: Fri, 01 Feb 2013 08:55:25 -0500	[thread overview]
Message-ID: <jwva9rorvgg.fsf-monnier+INBOX@gnu.org> (raw)
In-Reply-To: <CAKoxK+7ZnWRra9asH8CtcSCzKEm6Mw_AdFiZ_DWOBnaTiS7Ogw@mail.gmail.com> (Luca Ferrari's message of "Fri, 1 Feb 2013 11:36:49 +0100")

>> goto-line and line-number-at-pos are expensive operations that count
>> (and re-count and re-re-count every time) the number of LF chars from
>> the beginning of the buffer.
> I'm using them only at the beginning of the function, and therefore
> once per function call, that does not sound very expensive to me.
> What do you suggest instead?

Use buffer positions.  I.e. (point) and (goto-char POS).
After (goto-char POS) you may call (beginning-of-line) or (end-of-line)
if you want to make sure you're at a line boundary.


        Stefan



      reply	other threads:[~2013-02-01 13:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 11:20 creating a function that works for active region or whole buffer Luca Ferrari
2013-01-22 14:37 ` Mark Skilbeck
2013-01-22 16:01 ` Le Wang
2013-01-22 17:18   ` Ludwig, Mark
     [not found]   ` <mailman.18089.1358876370.855.help-gnu-emacs@gnu.org>
2013-01-22 19:57     ` Barry Margolin
2013-01-23  7:41       ` Luca Ferrari
2013-01-23  7:43         ` Luca Ferrari
2013-01-28 14:02           ` Stefan Monnier
2013-02-01 10:36             ` Luca Ferrari
2013-02-01 13:55               ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva9rorvgg.fsf-monnier+INBOX@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=fluca1978@infinito.it \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).