diff options
| author | Lars Ingebrigtsen | 2021-08-16 15:40:43 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-08-16 15:40:43 +0200 |
| commit | 5d7b1d5fc75752a986ed19d3fd333167ddc29d4e (patch) | |
| tree | 2958f419b095ee6e5f7eada504dfcaf40e5d10a8 | |
| parent | a3b31302dd1b7c1ffd3486b35de06c957785b919 (diff) | |
| download | emacs-5d7b1d5fc75752a986ed19d3fd333167ddc29d4e.tar.gz emacs-5d7b1d5fc75752a986ed19d3fd333167ddc29d4e.zip | |
Make overlays-in treat zero-length overlays at point-max consistently
* doc/lispref/display.texi (Finding Overlays): Adjust documentation.
* src/buffer.c (overlays_in): Treat the end of the buffer and the
end of the narrowed-to buffer the same (bug#19422).
(Foverlays_in): Adjust doc string.
| -rw-r--r-- | doc/lispref/display.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | src/buffer.c | 5 | ||||
| -rw-r--r-- | test/src/buffer-tests.el | 23 |
4 files changed, 35 insertions, 4 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 13d0a1b458d..79fb72a464d 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -1917,7 +1917,8 @@ This function returns a list of the overlays that overlap the region | |||
| 1917 | contains one or more characters in the region; empty overlays | 1917 | contains one or more characters in the region; empty overlays |
| 1918 | (@pxref{Managing Overlays, empty overlay}) overlap if they are at | 1918 | (@pxref{Managing Overlays, empty overlay}) overlap if they are at |
| 1919 | @var{beg}, strictly between @var{beg} and @var{end}, or at @var{end} | 1919 | @var{beg}, strictly between @var{beg} and @var{end}, or at @var{end} |
| 1920 | when @var{end} denotes the position at the end of the buffer. | 1920 | when @var{end} denotes the position at the end of the accessible part |
| 1921 | of the buffer. | ||
| 1921 | @end defun | 1922 | @end defun |
| 1922 | 1923 | ||
| 1923 | @defun next-overlay-change pos | 1924 | @defun next-overlay-change pos |
| @@ -3080,6 +3080,14 @@ This is to keep the same behavior as Eshell. | |||
| 3080 | 3080 | ||
| 3081 | * Incompatible Lisp Changes in Emacs 28.1 | 3081 | * Incompatible Lisp Changes in Emacs 28.1 |
| 3082 | 3082 | ||
| 3083 | +++ | ||
| 3084 | ** 'overlays-in' now handles zero-length overlays slightly differently. | ||
| 3085 | Previosly, zero-length overlays at the end of the buffer were included | ||
| 3086 | in the result (if the region queried for stopped at that position). | ||
| 3087 | The same was not the case if the buffer had been narrowed to exclude | ||
| 3088 | the real end of the buffer. This has now been changed, and | ||
| 3089 | zero-length overlays at `point-max' are always included in the results. | ||
| 3090 | |||
| 3083 | --- | 3091 | --- |
| 3084 | ** 'replace-match' now runs modification hooks slightly later. | 3092 | ** 'replace-match' now runs modification hooks slightly later. |
| 3085 | The function is documented to leave point after the replacement text, | 3093 | The function is documented to leave point after the replacement text, |
diff --git a/src/buffer.c b/src/buffer.c index b177c5eaa7f..7e4c84911bb 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -2995,7 +2995,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, bool extend, | |||
| 2995 | ptrdiff_t next = ZV; | 2995 | ptrdiff_t next = ZV; |
| 2996 | ptrdiff_t prev = BEGV; | 2996 | ptrdiff_t prev = BEGV; |
| 2997 | bool inhibit_storing = 0; | 2997 | bool inhibit_storing = 0; |
| 2998 | bool end_is_Z = end == Z; | 2998 | bool end_is_Z = end == ZV; |
| 2999 | 2999 | ||
| 3000 | for (struct Lisp_Overlay *tail = current_buffer->overlays_before; | 3000 | for (struct Lisp_Overlay *tail = current_buffer->overlays_before; |
| 3001 | tail; tail = tail->next) | 3001 | tail; tail = tail->next) |
| @@ -4268,9 +4268,10 @@ DEFUN ("overlays-in", Foverlays_in, Soverlays_in, 2, 2, 0, | |||
| 4268 | doc: /* Return a list of the overlays that overlap the region BEG ... END. | 4268 | doc: /* Return a list of the overlays that overlap the region BEG ... END. |
| 4269 | Overlap means that at least one character is contained within the overlay | 4269 | Overlap means that at least one character is contained within the overlay |
| 4270 | and also contained within the specified region. | 4270 | and also contained within the specified region. |
| 4271 | |||
| 4271 | Empty overlays are included in the result if they are located at BEG, | 4272 | Empty overlays are included in the result if they are located at BEG, |
| 4272 | between BEG and END, or at END provided END denotes the position at the | 4273 | between BEG and END, or at END provided END denotes the position at the |
| 4273 | end of the buffer. */) | 4274 | end of the accessible part of the buffer. */) |
| 4274 | (Lisp_Object beg, Lisp_Object end) | 4275 | (Lisp_Object beg, Lisp_Object end) |
| 4275 | { | 4276 | { |
| 4276 | ptrdiff_t len, noverlays; | 4277 | ptrdiff_t len, noverlays; |
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 11f842e8fe0..118311c4d26 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el | |||
| @@ -754,7 +754,7 @@ with parameters from the *Messages* buffer modification." | |||
| 754 | (should-length 2 (overlays-in 1 (point-max))) | 754 | (should-length 2 (overlays-in 1 (point-max))) |
| 755 | (should-length 1 (overlays-in (point-max) (point-max))) | 755 | (should-length 1 (overlays-in (point-max) (point-max))) |
| 756 | (narrow-to-region 1 50) | 756 | (narrow-to-region 1 50) |
| 757 | (should-length 0 (overlays-in 1 (point-max))) | 757 | (should-length 1 (overlays-in 1 (point-max))) |
| 758 | (should-length 1 (overlays-in (point-max) (point-max)))))) | 758 | (should-length 1 (overlays-in (point-max) (point-max)))))) |
| 759 | 759 | ||
| 760 | 760 | ||
| @@ -1399,4 +1399,25 @@ with parameters from the *Messages* buffer modification." | |||
| 1399 | (should (memq long-overlay (overlays-in 3 3))) | 1399 | (should (memq long-overlay (overlays-in 3 3))) |
| 1400 | (should (memq zero-overlay (overlays-in 3 3)))))) | 1400 | (should (memq zero-overlay (overlays-in 3 3)))))) |
| 1401 | 1401 | ||
| 1402 | (ert-deftest test-remove-overlays () | ||
| 1403 | (with-temp-buffer | ||
| 1404 | (insert "foo") | ||
| 1405 | (make-overlay (point) (point)) | ||
| 1406 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 1407 | (remove-overlays) | ||
| 1408 | (should (= (length (overlays-in (point-min) (point-max))) 0))) | ||
| 1409 | |||
| 1410 | (with-temp-buffer | ||
| 1411 | (insert "foo") | ||
| 1412 | (goto-char 2) | ||
| 1413 | (make-overlay (point) (point)) | ||
| 1414 | ;; We only count zero-length overlays at the end of the buffer. | ||
| 1415 | (should (= (length (overlays-in 1 2)) 0)) | ||
| 1416 | (narrow-to-region 1 2) | ||
| 1417 | ;; We've now narrowed, so the zero-length overlay is at the end of | ||
| 1418 | ;; the (accessible part of the) buffer. | ||
| 1419 | (should (= (length (overlays-in 1 2)) 1)) | ||
| 1420 | (remove-overlays) | ||
| 1421 | (should (= (length (overlays-in (point-min) (point-max))) 0)))) | ||
| 1422 | |||
| 1402 | ;;; buffer-tests.el ends here | 1423 | ;;; buffer-tests.el ends here |