From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#459: Zero-length overlays, overlay keymaps, and `overlays-at' Date: Tue, 20 Jul 2021 13:28:10 +0200 Message-ID: <87czrdi5rp.fsf@gnus.org> References: <485D204B.2@dr-qubit.org> <875yx6mijw.fsf@gnus.org> <83y2a25ktq.fsf@gnu.org> <87y2a2i7kc.fsf@gnus.org> <87k0lmi2ms.fsf@gnus.org> <83pmve5ez3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36023"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 459@debbugs.gnu.org, monnier@iro.umontreal.ca, t.s.cubitt.98@cantab.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jul 20 13:29:25 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5nwC-0009DY-TJ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 20 Jul 2021 13:29:25 +0200 Original-Received: from localhost ([::1]:36064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5nwB-0007fe-V4 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 20 Jul 2021 07:29:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5nvq-0007fT-6F for bug-gnu-emacs@gnu.org; Tue, 20 Jul 2021 07:29:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m5nvp-00028E-QW for bug-gnu-emacs@gnu.org; Tue, 20 Jul 2021 07:29:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m5nvp-0005en-OO for bug-gnu-emacs@gnu.org; Tue, 20 Jul 2021 07:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 20 Jul 2021 11:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 459 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 459-submit@debbugs.gnu.org id=B459.162678050621704 (code B ref 459); Tue, 20 Jul 2021 11:29:01 +0000 Original-Received: (at 459) by debbugs.gnu.org; 20 Jul 2021 11:28:26 +0000 Original-Received: from localhost ([127.0.0.1]:32965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5nvF-0005dx-Td for submit@debbugs.gnu.org; Tue, 20 Jul 2021 07:28:26 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:56112) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5nvE-0005dk-3E for 459@debbugs.gnu.org; Tue, 20 Jul 2021 07:28:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yiHFe3iijic7x7vGB3Xhu/PXnGH4giDBbx6iV5Loh6Q=; b=G8YdsrrkKCuxXEL7/OEqUiRhB4 E8gJTg3OnijJs8Lqf4cNNdqIkXR5B9QLfLhSEZVfZWmubILWqyuTdWW4Izchtmt96+hOKv9IRY5Vf IA4FEPcrmyZ7sBWuqzeUdCR9uyHlTO+j4lD9hr4SWDsB3gEAgczwqfxU14OTYZBm6m6Q=; Original-Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5nv1-0002TH-FE; Tue, 20 Jul 2021 13:28:14 +0200 X-Now-Playing: Four Tet's _Sixteen Oceans_: "Something In The Sadness" In-Reply-To: <83pmve5ez3.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 19 Jul 2021 21:35:28 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210326 Archived-At: Eli Zaretskii writes: > No, please don't make that the default behavior. It makes no sense to > change the default behavior of such a veteran API for the benefit of a > rare use case. The gains are very small, and don't justify the risks. > An optional argument gets us the best of both worlds, so it's a clear > winner. I was just hedging in case somebody came up with a brilliant reason for including them by default. :-) However... after implementing this, I see that `overlays-in' is something that exists? And does include zero-length overlays? *sigh* So `(overlays-in 1 1)' is the answer to this bug report. I've included the patch that won't be applied below for reference. Instead I'll just mention `overlays-in' in the `overlays-at' doc string. diff --git a/src/buffer.c b/src/buffer.c index d3a5ffd149..93f3e3dbb6 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2859,7 +2859,8 @@ DEFUN ("kill-all-local-variables", Fkill_all_local_variables, ptrdiff_t overlays_at (EMACS_INT pos, bool extend, Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, - ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, bool change_req) + ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, bool change_req, + bool include_zero_length) { ptrdiff_t idx = 0; ptrdiff_t len = *len_ptr; @@ -2886,7 +2887,8 @@ overlays_at (EMACS_INT pos, bool extend, Lisp_Object **vec_ptr, so its start counts for PREV_PTR if it's before POS. */ if (prev < startpos && startpos < pos) prev = startpos; - if (endpos == pos) + if (endpos == pos + && (!include_zero_length || endpos != startpos)) continue; if (startpos <= pos) { @@ -2928,7 +2930,8 @@ overlays_at (EMACS_INT pos, bool extend, Lisp_Object **vec_ptr, break; } ptrdiff_t endpos = OVERLAY_POSITION (end); - if (pos < endpos) + if (pos < endpos + || (include_zero_length && pos == endpos && startpos == endpos)) { if (idx == len) { @@ -4220,10 +4223,13 @@ DEFUN ("overlay-properties", Foverlay_properties, Soverlay_properties, 1, 1, 0, } -DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 2, 0, +DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 3, 0, doc: /* Return a list of the overlays that contain the character at POS. -If SORTED is non-nil, then sort them by decreasing priority. */) - (Lisp_Object pos, Lisp_Object sorted) +If SORTED is non-nil, then sort them by decreasing priority. + +If INCLUDE-ZERO-LENGTH is non-nil, also include zero-length overlays +at POS. (These are otherwise excluded.) */) + (Lisp_Object pos, Lisp_Object sorted, Lisp_Object include_zero_length) { ptrdiff_t len, noverlays; Lisp_Object *overlay_vec; @@ -4241,7 +4247,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 2, 0, /* Put all the overlays we want in a vector in overlay_vec. Store the length in len. */ noverlays = overlays_at (XFIXNUM (pos), 1, &overlay_vec, &len, - NULL, NULL, 0); + NULL, NULL, 0, !NILP (include_zero_length)); if (!NILP (sorted)) noverlays = sort_overlays (overlay_vec, noverlays, @@ -4317,7 +4323,7 @@ DEFUN ("next-overlay-change", Fnext_overlay_change, Snext_overlay_change, Store the length in len. endpos gets the position where the next overlay starts. */ noverlays = overlays_at (XFIXNUM (pos), 1, &overlay_vec, &len, - &endpos, 0, 1); + &endpos, 0, 1, false); /* If any of these overlays ends before endpos, use its ending point instead. */ @@ -4364,7 +4370,7 @@ DEFUN ("previous-overlay-change", Fprevious_overlay_change, Store the length in len. prevpos gets the position of the previous change. */ overlays_at (XFIXNUM (pos), 1, &overlay_vec, &len, - 0, &prevpos, 1); + 0, &prevpos, 1, false); xfree (overlay_vec); return make_fixnum (prevpos); diff --git a/src/buffer.h b/src/buffer.h index 24e9c3fcbc..daa666248d 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1145,7 +1145,8 @@ #define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x))) extern void compact_buffer (struct buffer *); extern void evaporate_overlays (ptrdiff_t); extern ptrdiff_t overlays_at (EMACS_INT, bool, Lisp_Object **, - ptrdiff_t *, ptrdiff_t *, ptrdiff_t *, bool); + ptrdiff_t *, ptrdiff_t *, ptrdiff_t *, bool, + bool); extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *); extern void recenter_overlay_lists (struct buffer *, ptrdiff_t); extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **); @@ -1204,13 +1205,13 @@ #define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ ptrdiff_t maxlen = 40; \ SAFE_NALLOCA (overlays, 1, maxlen); \ (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, \ - nextp, NULL, chrq); \ + nextp, NULL, chrq, false); \ if ((noverlays) > maxlen) \ { \ maxlen = noverlays; \ SAFE_NALLOCA (overlays, 1, maxlen); \ (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, \ - nextp, NULL, chrq); \ + nextp, NULL, chrq, false); \ } \ } while (false) diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 2adffc024a..5e83c0beab 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -1386,4 +1386,17 @@ buffer-tests-inhibit-buffer-hooks-indirect (when (buffer-live-p base) (kill-buffer base))))))) +(ert-deftest zero-length-overlays-and-not () + (with-temp-buffer + (insert "hello") + (let ((long-overlay (make-overlay 2 4)) + (zero-overlay (make-overlay 3 3))) + ;; Exclude. + (should (= (length (overlays-at 3)) 1)) + (should (eq (car (overlays-at 3)) long-overlay)) + ;; Include. + (should (= (length (overlays-at 3 nil t)) 2)) + (should (memq long-overlay (overlays-at 3 nil t))) + (should (memq zero-overlay (overlays-at 3 nil t)))))) + ;;; buffer-tests.el ends here -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no