tags:

views:

75

answers:

3

Suppose I have a source file that is 18218 bytes.

I open the file in emacs, then do:

 M-x end-of-buffer
 M-x what-cursor-position

Why does the cursor position return 17612 bytes?

I think it's because of CRLF translation, or collapsing CRLF into one character.

How can I get emacs to report the accurate, untranslated character position?

+1  A: 

The behavior you describe is mentioned in the manual. No way of getting the "true" position is mentioned, which leads me to believe that you're out of luck.

You can, however, open the file without any conversions applied like this: C-x RET c no-conversion RET C-x C-f filename. Then all of the character positions should match up correctly.

Sean
A: 

I suspect opening the file using find-file-literally will stop Emacs from auto-detecting line endings and convert CR LF to "line break".

Vatine
A: 

Maybe the non-interactive function (point) is what you need. I haven't noticed such discrepancies about it, but then again - I haven't paid any particular attention to such details...

Bozhidar Batsov