diff options
Diffstat (limited to 'devdocs/elisp/finding-overlays.html')
| -rw-r--r-- | devdocs/elisp/finding-overlays.html | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/devdocs/elisp/finding-overlays.html b/devdocs/elisp/finding-overlays.html new file mode 100644 index 00000000..0fb6175f --- /dev/null +++ b/devdocs/elisp/finding-overlays.html @@ -0,0 +1,35 @@ + <h4 class="subsection">Searching for Overlays</h4> <dl> <dt id="overlays-at">Function: <strong>overlays-at</strong> <em>pos &optional sorted</em> +</dt> <dd> +<p>This function returns a list of all the overlays that cover the character at position <var>pos</var> in the current buffer. If <var>sorted</var> is non-<code>nil</code>, the list is in decreasing order of priority, otherwise it is in no particular order. An overlay contains position <var>pos</var> if it begins at or before <var>pos</var>, and ends after <var>pos</var>. </p> <p>To illustrate usage, here is a Lisp function that returns a list of the overlays that specify property <var>prop</var> for the character at point: </p> <div class="example"> <pre class="example">(defun find-overlays-specifying (prop) + (let ((overlays (overlays-at (point))) + found) + (while overlays + (let ((overlay (car overlays))) + (if (overlay-get overlay prop) + (setq found (cons overlay found)))) + (setq overlays (cdr overlays))) + found)) +</pre> +</div> </dd> +</dl> <dl> <dt id="overlays-in">Function: <strong>overlays-in</strong> <em>beg end</em> +</dt> <dd><p>This function returns a list of the overlays that overlap the region <var>beg</var> through <var>end</var>. An overlay overlaps with a region if it contains one or more characters in the region; empty overlays (see <a href="managing-overlays">empty overlay</a>) overlap if they are at <var>beg</var>, strictly between <var>beg</var> and <var>end</var>, or at <var>end</var> when <var>end</var> denotes the position at the end of the accessible part of the buffer. </p></dd> +</dl> <dl> <dt id="next-overlay-change">Function: <strong>next-overlay-change</strong> <em>pos</em> +</dt> <dd><p>This function returns the buffer position of the next beginning or end of an overlay, after <var>pos</var>. If there is none, it returns <code>(point-max)</code>. </p></dd> +</dl> <dl> <dt id="previous-overlay-change">Function: <strong>previous-overlay-change</strong> <em>pos</em> +</dt> <dd><p>This function returns the buffer position of the previous beginning or end of an overlay, before <var>pos</var>. If there is none, it returns <code>(point-min)</code>. </p></dd> +</dl> <p>As an example, here’s a simplified (and inefficient) version of the primitive function <code>next-single-char-property-change</code> (see <a href="property-search">Property Search</a>). It searches forward from position <var>pos</var> for the next position where the value of a given property <code>prop</code>, as obtained from either overlays or text properties, changes. </p> <div class="example"> <pre class="example">(defun next-single-char-property-change (position prop) + (save-excursion + (goto-char position) + (let ((propval (get-char-property (point) prop))) + (while (and (not (eobp)) + (eq (get-char-property (point) prop) propval)) + (goto-char (min (next-overlay-change (point)) + (next-single-property-change (point) prop))))) + (point))) +</pre> +</div><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Finding-Overlays.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Finding-Overlays.html</a> + </p> +</div> |
