aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2016-01-13 20:11:52 +0200
committerEli Zaretskii2016-01-13 20:11:52 +0200
commitc8eb45da88e05453e78440fedf09a143c832d5a0 (patch)
tree24ec884f2abe6a5992d8a7bb7ffd90fd7deab33b
parentd3776e9f7c9e6ae3ac4c5afff0c33bff73665759 (diff)
downloademacs-c8eb45da88e05453e78440fedf09a143c832d5a0.tar.gz
emacs-c8eb45da88e05453e78440fedf09a143c832d5a0.zip
Document 'bufferpos-to-filepos' and 'filepos-to-bufferpos'
* doc/lispref/nonascii.texi (Text Representations): Document 'bufferpos-to-filepos' and 'filepos-to-bufferpos'.
-rw-r--r--doc/lispref/nonascii.texi39
-rw-r--r--etc/NEWS3
2 files changed, 42 insertions, 0 deletions
diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi
index 744351e384e..fca40238805 100644
--- a/doc/lispref/nonascii.texi
+++ b/doc/lispref/nonascii.texi
@@ -123,6 +123,45 @@ In other words, the value does not change for all byte positions that
123belong to the same character. 123belong to the same character.
124@end defun 124@end defun
125 125
126@cindex convert file byte to buffer position
127@cindex convert buffer position to file byte
128 The following two functions are useful when a Lisp program needs to
129map buffer positions to byte offsets in a file visited by the buffer.
130
131@defun bufferpos-to-filepos position &optional quality coding-system
132This function is similar to @code{position-bytes}, but instead of byte
133position in the current buffer it returns the offset from the
134beginning of the current buffer's file of the byte that corresponds to
135the given character @var{position} in the buffer. The conversion
136requires to know how the text is encoded in the buffer's file; this is
137what the @var{coding-system} argument is for, defaulting to the value
138of @code{buffer-file-coding-system}. The optional argument
139@var{quality} specifies how accurate the result should be; it should
140be one of the following:
141
142@table @code
143@item exact
144The result must be accurate. The function may need to encode and
145decode a large part of the buffer.
146@item approximate
147The value can be an approximation. The function may avoid expensive
148processing and return an inexact result.
149@item nil
150If the exact result needs expensive processing, the function will
151return @code{nil} rather than an approximation. This is the default
152if the argument is omitted.
153@end table
154@end defun
155
156@defun filepos-to-bufferpos byte &optional quality coding-system
157This function returns the buffer position corresponding to a file
158position specified by @var{byte}, a zero-base byte offset from the
159file's beginning. The function performs the conversion opposite to
160what @code{bufferpos-to-filepos} does. Optional arguments
161@var{quality} and @var{coding-system} have the same meaning and values
162as for @code{bufferpos-to-filepos}.
163@end defun
164
126@defun multibyte-string-p string 165@defun multibyte-string-p string
127Return @code{t} if @var{string} is a multibyte string, @code{nil} 166Return @code{t} if @var{string} is a multibyte string, @code{nil}
128otherwise. This function also returns @code{nil} if @var{string} is 167otherwise. This function also returns @code{nil} if @var{string} is
diff --git a/etc/NEWS b/etc/NEWS
index 5a1adff0920..88d0604cedf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1340,7 +1340,10 @@ parsing functions like `forward-sexp'.
1340`prefix-command-preserve-state-hook' allow the definition of prefix 1340`prefix-command-preserve-state-hook' allow the definition of prefix
1341commands other than the predefined `C-u'. 1341commands other than the predefined `C-u'.
1342 1342
1343+++
1343** New functions `filepos-to-bufferpos' and `bufferpos-to-filepos'. 1344** New functions `filepos-to-bufferpos' and `bufferpos-to-filepos'.
1345These allow to convert between buffer positions and the corresponding
1346file byte offsets, given the file's encoding.
1344 1347
1345** The default value of `load-read-function' is now `read'. 1348** The default value of `load-read-function' is now `read'.
1346 1349