* Byte offset from point
@ 2009-08-12 18:44 senny
2009-08-12 18:57 ` Teemu Likonen
0 siblings, 1 reply; 5+ messages in thread
From: senny @ 2009-08-12 18:44 UTC (permalink / raw)
To: help-gnu-emacs
Hey there
I am looking for a way to get the exact byte-offset from the cursor
position. I need this value to call an external service. Is there a
way to achieve this in emacs?
Thanks in advance.
Regards,
senny
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte offset from point
2009-08-12 18:44 Byte offset from point senny
@ 2009-08-12 18:57 ` Teemu Likonen
2009-08-12 19:06 ` senny
0 siblings, 1 reply; 5+ messages in thread
From: Teemu Likonen @ 2009-08-12 18:57 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-08-12 11:44 (-0700), senny wrote:
> I am looking for a way to get the exact byte-offset from the cursor
> position. I need this value to call an external service. Is there a
> way to achieve this in emacs?
Perhaps this:
(position-bytes (point))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte offset from point
2009-08-12 18:57 ` Teemu Likonen
@ 2009-08-12 19:06 ` senny
2009-08-12 19:18 ` Teemu Likonen
2009-08-12 19:47 ` Eli Zaretskii
0 siblings, 2 replies; 5+ messages in thread
From: senny @ 2009-08-12 19:06 UTC (permalink / raw)
To: help-gnu-emacs
On 12 Aug., 20:57, Teemu Likonen <tliko...@iki.fi> wrote:
> On 2009-08-12 11:44 (-0700), senny wrote:
>
> > I am looking for a way to get the exact byte-offset from the cursor
> > position. I need this value to call an external service. Is there a
> > way to achieve this in emacs?
>
> Perhaps this:
>
> (position-bytes (point))
I tried that but it gave me incorrect results when dealing with
newlines on windows. The lisp function counted them as 1 byte but the
service i was calling counted them as 2 bytes.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte offset from point
2009-08-12 19:06 ` senny
@ 2009-08-12 19:18 ` Teemu Likonen
2009-08-12 19:47 ` Eli Zaretskii
1 sibling, 0 replies; 5+ messages in thread
From: Teemu Likonen @ 2009-08-12 19:18 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-08-12 12:06 (-0700), senny wrote:
> On 12 Aug., 20:57, Teemu Likonen <tliko...@iki.fi> wrote:
>> (position-bytes (point))
>
> I tried that but it gave me incorrect results when dealing with
> newlines on windows. The lisp function counted them as 1 byte but the
> service i was calling counted them as 2 bytes.
Maybe you can do the correction manually. Count newlines twice:
(+ (position-bytes (point))
(how-many "\n" 1 (point)))
Or something like that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte offset from point
2009-08-12 19:06 ` senny
2009-08-12 19:18 ` Teemu Likonen
@ 2009-08-12 19:47 ` Eli Zaretskii
1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2009-08-12 19:47 UTC (permalink / raw)
To: help-gnu-emacs
> From: senny <yves.senn@gmail.com>
> Date: Wed, 12 Aug 2009 12:06:26 -0700 (PDT)
>
> > (position-bytes (point))
>
> I tried that but it gave me incorrect results when dealing with
> newlines on windows. The lisp function counted them as 1 byte but the
> service i was calling counted them as 2 bytes.
If you want Emacs to account for the (potentially stripped) CR
characters, you need to visit the file without any code conversions,
e.g. with `find-file-literally' or with
`insert-file-contents-literally'. Then position-bytes will count
correctly.
Alternatively, you could call count-lines-region and add one character
for each line before point.
If this does not help, perhaps consider telling more about the problem
you are trying to solve.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-12 19:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 18:44 Byte offset from point senny
2009-08-12 18:57 ` Teemu Likonen
2009-08-12 19:06 ` senny
2009-08-12 19:18 ` Teemu Likonen
2009-08-12 19:47 ` Eli Zaretskii
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).