]> code.delx.au - gnu-emacs/blobdiff - doc/lispref/nonascii.texi
(Common Keywords): Correct what missing :group means
[gnu-emacs] / doc / lispref / nonascii.texi
index fb76de1ca094dbe21e7b73fa261c9fd2104a81ac..9cf3b5750f2a32cfd1d3ebde57eeab0d047b3279 100644 (file)
@@ -1,6 +1,6 @@
 @c -*- mode: texinfo; coding: utf-8 -*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1998-1999, 2001-2015 Free Software Foundation, Inc.
+@c Copyright (C) 1998-1999, 2001-2016 Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @node Non-ASCII Characters
 @chapter Non-@acronym{ASCII} Characters
@@ -123,6 +123,45 @@ In other words, the value does not change for all byte positions that
 belong to the same character.
 @end defun
 
+@cindex convert file byte to buffer position
+@cindex convert buffer position to file byte
+  The following two functions are useful when a Lisp program needs to
+map buffer positions to byte offsets in a file visited by the buffer.
+
+@defun bufferpos-to-filepos position &optional quality coding-system
+This function is similar to @code{position-bytes}, but instead of byte
+position in the current buffer it returns the offset from the
+beginning of the current buffer's file of the byte that corresponds to
+the given character @var{position} in the buffer.  The conversion
+requires to know how the text is encoded in the buffer's file; this is
+what the @var{coding-system} argument is for, defaulting to the value
+of @code{buffer-file-coding-system}.  The optional argument
+@var{quality} specifies how accurate the result should be; it should
+be one of the following:
+
+@table @code
+@item exact
+The result must be accurate.  The function may need to encode and
+decode a large part of the buffer.
+@item approximate
+The value can be an approximation.  The function may avoid expensive
+processing and return an inexact result.
+@item nil
+If the exact result needs expensive processing, the function will
+return @code{nil} rather than an approximation.  This is the default
+if the argument is omitted.
+@end table
+@end defun
+
+@defun filepos-to-bufferpos byte &optional quality coding-system
+This function returns the buffer position corresponding to a file
+position specified by @var{byte}, a zero-base byte offset from the
+file's beginning.  The function performs the conversion opposite to
+what @code{bufferpos-to-filepos} does.  Optional arguments
+@var{quality} and @var{coding-system} have the same meaning and values
+as for @code{bufferpos-to-filepos}.
+@end defun
+
 @defun multibyte-string-p string
 Return @code{t} if @var{string} is a multibyte string, @code{nil}
 otherwise.  This function also returns @code{nil} if @var{string} is
@@ -583,17 +622,17 @@ This function returns the value of @var{char}'s @var{propname} property.
      @result{} Nd
 @end group
 @group
-;; subscript 4
+;; U+2084 SUBSCRIPT FOUR
 (get-char-code-property ?\u2084 'digit-value)
      @result{} 4
 @end group
 @group
-;; one fifth
+;; U+2155 VULGAR FRACTION ONE FIFTH
 (get-char-code-property ?\u2155 'numeric-value)
      @result{} 0.2
 @end group
 @group
-;; Roman IV
+;; U+2163 ROMAN NUMERAL FOUR
 (get-char-code-property ?\u2163 'numeric-value)
      @result{} 4
 @end group
@@ -1299,9 +1338,9 @@ operates on the contents of @var{string} instead of bytes in the buffer.
 @cindex null bytes, and decoding text
 @defvar inhibit-null-byte-detection
 If this variable has a non-@code{nil} value, null bytes are ignored
-when detecting the encoding of a region or a string.  This allows to
-correctly detect the encoding of text that contains null bytes, such
-as Info files with Index nodes.
+when detecting the encoding of a region or a string.  This allows the
+encoding of text that contains null bytes to be correctly detected,
+such as Info files with Index nodes.
 @end defvar
 
 @defvar inhibit-iso-escape-detection