emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : EQ-ness


From: Drew Adams
Subject: RE: [External] : EQ-ness
Date: Fri, 17 Dec 2021 06:15:31 +0000

BTW, Richard, I often have difficulty telling what
message or sender you're replying to.  It would
help me, at least, if you made that clearer somehow.

In this case, you started a new thread (Subject) by
replying to something I wrote.  I almost didn't
notice that, and so I almost passed by your message
(there are so many to scan or read).  Anyway, just
a suggestion...

> > In particular, the bookmark name, which is the
> > car of a bookmark, is a string with a property
> > that holds the entire bookmark.  The bookmark
> > is a list with shared (circular) structure.
> 
> > Emacs has no trouble writing and reading such
> > lists.
> 
> Is print-circle non-nil when you write these values?
> If not, what do they look like when they come back?
> What method is used to make that generate a cyclic list?

Yes, sorry, guess I should have been clear about
that.  I figured it was nothing special and it
would be clear.

I redefine function `bookmark-write-file', to write
bookmarks using `pp', and with these bindings:

 (print-length  nil)
 (print-level   nil)
 (print-circle  t)
 (print-gensym  t)

[The last two are actually bound to an option, not
`t', so you can choose whether to allow for this
kind of writing.  This means choosing whether to
let the same bookmark name (with different property
values) be usable for multiple bookmarks.  E.g.,
bookmarks named with the same non-dir file-name
parts for files of the same name in different dirs.]

I put the full bookmark, which is a list with car
the bookmark name and cdr the bookmark data, onto the
bookmark name, as text property `bmkp-full-record':

 (put-text-property
   0 (length bname) 'bmkp-full-record bmk bname)

where bmk is the full bookmark.  To get back the
full bookmark from the name:

 (get-text-property 0 'bmkp-full-record bname)

The actual function used to get the full record from
the name has some optional-arg behaviors.  Here's
its doc string:
___

 (bmkp-bookmark-record-from-name BOOKMARK-NAME
                                 &optional NOERROR MEMP ALIST)

Return the full bookmark (record) that corresponds to BOOKMARK-NAME.
BOOKMARK-NAME must be a string.  If it has non-nil text property
`bmkp-full-record' then use that.  Otherwise, look for the first
bookmark in ALIST that has the given name.

Non-nil optional arg NOERROR means return nil if BOOKMARK-NAME does
not name a valid bookmark or is valid but is not in ALIST.  If NOERROR
is nil then raise an error in this case.

Non-nil optional arg MEMP means that if property `bmkp-full-record' is
available then look up its value (the full bookmark) in ALIST, testing
with `eq'.  If that record is not in ALIST, return nil.

Optional arg ALIST defaults to `bookmark-alist'.
___

I use the same "trick", BTW, to allow completion
candidates where the "full" candidate (e.g. in an
alist) is a cons whose car is the name used for
`completing-read' matching and display.

That makes it simple to get the full alist element
from the user's choice (the name that's the element's
car).  This makes it possible to have multiple
choices that have the same display name.  Why, and
how to tell which is which when they have the same
name?  By their position in the sort order, for
example (cycling etc.).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]