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?
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.
I suspect opening the file using find-file-literally
will stop Emacs from auto-detecting line endings and convert CR LF to "line break".
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...
精彩评论