From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.help Subject: cl-delete-if vs list of overlays Date: Wed, 09 Dec 2020 10:53:26 +0100 Message-ID: <87zh2nfgq1.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23829"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 27.1 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 09 10:56:22 2020 Return-path: Envelope-to: geh-help-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 1kmwCr-00067m-Sd for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Dec 2020 10:56:21 +0100 Original-Received: from localhost ([::1]:44968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmwCq-0004QC-Qh for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Dec 2020 04:56:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmwAd-0002LY-Gn for help-gnu-emacs@gnu.org; Wed, 09 Dec 2020 04:54:06 -0500 Original-Received: from mail.omarpolo.com ([144.91.116.244]:55873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmwAY-0000bg-DF for help-gnu-emacs@gnu.org; Wed, 09 Dec 2020 04:54:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1607507618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=dRpcTE8RTMUiW1Q0UGK2Nd+/HzOGyHTxR0/rCEGJcGk=; b=A7UaW5PFFgLgNJKZWZFDwbeQqCJpCP74N5rD65gt6VoWuoAjVS/mz4lIDe7cajol02EX8S hJl0tnpqjupnZe2bHKqLicVoC/uBN82nA28s6EslDR5+XJ27kH6P8JRgIYhj+FOniivUh3 I9E7bYcmGBu9BhvE0TTN0aGOlXTdUTs= Original-Received: from localhost (host-80-116-112-105.retail.telecomitalia.it [80.116.112.105]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id d7fe7e62 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 9 Dec 2020 10:53:37 +0100 (CET) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 404e2e71 for ; Wed, 9 Dec 2020 10:53:26 +0100 (CET) Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126185 Archived-At: Hello, I was playing with overlays and the fringe, when I found something I couldn't really understand. Hence this help request :) Let me say beforehand that on a second thought what I was doing isn't probably the best way to manage the overlays, that I don't really need to maintain a list, but I'm still asking because I'm curious. I'm adding and removing markers on the fringe, and saving the respective overlays in a list. When I have to remove a marker, I use cl-delete-if to remove the correct overlay from the list (while also doing the side-effect of `delete-overlay'). The thing is, the removed overlays are still present in the list. The following is a proof-of-code to better explain what I mean: (require 'cl-lib) (defvar foo--overlays nil "List of active overlays.") (defun foo--delete-overlay-at (point) "t if an overlay was deleted." (let (delp) (cl-delete-if (lambda (overlay) (when (= point (overlay-start overlay)) (delete-overlay overlay) (setq delp t))) foo--overlays) delp)) (defun foo-toggle-this-line () "Add/remove a marker on the current line." (interactive) (save-excursion (beginning-of-line) (unless (foo--delete-overlay-at (point)) (let ((overlay (make-overlay (point) (point)))) (overlay-put overlay 'before-string (propertize "A" 'display '(left-fringe right-triangle))) (push overlay foo--overlays))))) (provide 'foo) ;;; foo.el ends here Try to add a marker on a line with (foo-toggle-this-line) and then remove it: you'll find that `foo--overlays' is not nil. (You'll actually get an error if you play with it too much, because for deleted overlays `overlay-start' returns nil and that makes = raise an error) Why is cl-delete-if not removing items from the list? (setq delp t) evaluates to t, so it should delete. cl-delete-if a destructive function. This is what I'm not getting. Thanks, Omar Polo