I'm not sure I understand your question. Yes, with Bookmark+ you can have multiple bookmarks with the same bookmark name. (Actually, you can with vanilla Emacs too, but not usefully.)
If you create autofile bookmarks, for instance, the bookmark name is the same as the relative file name, but the recorded file name is absolute, so you can have different bookmarks with the same name, pointing to files of the same name that are in different directories.
In order to take advantage of this, you need to ensure that the value of option bmkp-propertize-bookmark-names-flag
is non-nil
. You can toggle this option in the *Bookmark List*
display using menu Bookmark+
> Toggle
> Allowing Identical Bookmark Names
.
You don't have to do anything special, other than that, to be able to create and use bookmarks that have the same name.
The doc string of bookmark-set
says this:
Plain prefix arg (`C-u'): Do not overwrite a bookmark that has the
same name as NAME, if such a bookmark already exists. Instead,
push the new bookmark onto the bookmark alist.
So for an ordinary (e.g. not an autofile) bookmark, use C-u
with C-x r m
to allow creation of an additional bookmark with the same name.
With Bookmark+, command bmkp-bookmark-set-confirm-overwrite
, not bookmark-set
, is bound to C-x r m
. The doc string says this:
This is the same as `bookmark-set', except that with no prefix arg you
are asked to confirm overwriting an existing bookmark of the same
NAME.
That is, if you use C-x r m
without a prefix arg then, before overwriting an existing bookmark of the same name, you are asked to confirm overwriting. This means that you need not worry about inadvertently overwriting.
Update after your comments
This is not really the place for a discussion. And your question is still not very clear.
Are you asking how to check whether there is an existing bookmark that has a given name and bookmarks a given file? If so:
(defun bookmark-name+filename-exists-p (bookmark file)
"Return a bookmark named BOOKMARK for FILE, or nil if there is none.
BOOKMARK is a bookmark name or a bookmark record."
(when (consp bookmark) (setq bookmark (bookmark-name-from-full-record bookmark)))
(catch 'bookmark-exists-p
(dolist (bmk bookmark-alist)
(when (and (string= bookmark (bookmark-name-from-full-record bmk))
(bmkp-same-file-p file (bookmark-get-filename bmk)))
(throw 'bookmark-exists-p bmk)))
nil))
Are you asking for a list of all bookmarks that have a given name? If so:
(defun bookmarks-with-name (bname)
"Return a list of the bookmarks with name BNAME."
(bmkp-remove-if-not
`(lambda (bmk) (string= ',bname (bookmark-name-from-full-record bmk)))
bookmark-alist))