all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* cl-delete-if vs list of overlays
@ 2020-12-09  9:53 Omar Polo
  2020-12-09 10:17 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Omar Polo @ 2020-12-09  9:53 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-09 18:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-09  9:53 cl-delete-if vs list of overlays Omar Polo
2020-12-09 10:17 ` Thien-Thi Nguyen
2020-12-09 11:05   ` Omar Polo
2020-12-09 16:14     ` Drew Adams
2020-12-09 18:16     ` Thien-Thi Nguyen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.