diff options
| author | Eli Zaretskii | 2016-01-13 20:11:52 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2016-01-13 20:11:52 +0200 |
| commit | c8eb45da88e05453e78440fedf09a143c832d5a0 (patch) | |
| tree | 24ec884f2abe6a5992d8a7bb7ffd90fd7deab33b | |
| parent | d3776e9f7c9e6ae3ac4c5afff0c33bff73665759 (diff) | |
| download | emacs-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.texi | 39 | ||||
| -rw-r--r-- | etc/NEWS | 3 |
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 | |||
| 123 | belong to the same character. | 123 | belong 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 | ||
| 129 | map buffer positions to byte offsets in a file visited by the buffer. | ||
| 130 | |||
| 131 | @defun bufferpos-to-filepos position &optional quality coding-system | ||
| 132 | This function is similar to @code{position-bytes}, but instead of byte | ||
| 133 | position in the current buffer it returns the offset from the | ||
| 134 | beginning of the current buffer's file of the byte that corresponds to | ||
| 135 | the given character @var{position} in the buffer. The conversion | ||
| 136 | requires to know how the text is encoded in the buffer's file; this is | ||
| 137 | what the @var{coding-system} argument is for, defaulting to the value | ||
| 138 | of @code{buffer-file-coding-system}. The optional argument | ||
| 139 | @var{quality} specifies how accurate the result should be; it should | ||
| 140 | be one of the following: | ||
| 141 | |||
| 142 | @table @code | ||
| 143 | @item exact | ||
| 144 | The result must be accurate. The function may need to encode and | ||
| 145 | decode a large part of the buffer. | ||
| 146 | @item approximate | ||
| 147 | The value can be an approximation. The function may avoid expensive | ||
| 148 | processing and return an inexact result. | ||
| 149 | @item nil | ||
| 150 | If the exact result needs expensive processing, the function will | ||
| 151 | return @code{nil} rather than an approximation. This is the default | ||
| 152 | if the argument is omitted. | ||
| 153 | @end table | ||
| 154 | @end defun | ||
| 155 | |||
| 156 | @defun filepos-to-bufferpos byte &optional quality coding-system | ||
| 157 | This function returns the buffer position corresponding to a file | ||
| 158 | position specified by @var{byte}, a zero-base byte offset from the | ||
| 159 | file's beginning. The function performs the conversion opposite to | ||
| 160 | what @code{bufferpos-to-filepos} does. Optional arguments | ||
| 161 | @var{quality} and @var{coding-system} have the same meaning and values | ||
| 162 | as for @code{bufferpos-to-filepos}. | ||
| 163 | @end defun | ||
| 164 | |||
| 126 | @defun multibyte-string-p string | 165 | @defun multibyte-string-p string |
| 127 | Return @code{t} if @var{string} is a multibyte string, @code{nil} | 166 | Return @code{t} if @var{string} is a multibyte string, @code{nil} |
| 128 | otherwise. This function also returns @code{nil} if @var{string} is | 167 | otherwise. This function also returns @code{nil} if @var{string} is |
| @@ -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 |
| 1341 | commands other than the predefined `C-u'. | 1341 | commands 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'. |
| 1345 | These allow to convert between buffer positions and the corresponding | ||
| 1346 | file 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 | ||