1

The Title is pretty defining. Repeating here, it reads "What function in Bookmarks+ deals with multiple bookmarks with the same name?" Bookmarks+ is an improvement to bookmark functionality native to Emacs. I have a number of elisp functions saved in files in different directories and I'd like to bookmark them all in a bookmark file. I'd use my tags file (Etags generated) to locate them and I would then bookmark them, with annotation equal to the function documentation. There are duplicate function names, in files in different directories.

I'd repeat this at will & compare to bookmarks from an existing bookmark file. I'd only make a new bookmark if one or more with the same name didn't already exist.

I've looked through all Bookmark+ functions (found by Etags) and haven't found a match for what I'd like. I may have to "roll my own".

1 Answer 1

1

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))
5
  • What's not clear to me yet is how to go to each multiple bookmark with the same name (in lisp code) and test if it is already a bookmark for the lisp function that I've located in code by using my etags file. If the location that I'm at isn't represented by an existing bookmark, then I would like to add a bookmark (via lisp code); otherwise, if it is already represented by an existing bookmark, then I don't want to add a bookmark for that location. I've been studying bookmark+ code as a guide for doing this, but would be thankful for any extra help that comes my way. Apr 26, 2015 at 14:54
  • I would do this repeatedly, and would use tagging to focus attention on lisp functions of mine that are of current interest. Apr 26, 2015 at 14:57
  • Are you asking how to identify the file location of a given bookmark (e.g., so you can tell whether you've already bookmarked that file? If so, the answer is bookmark-get-filename. If not, please clarify.
    – Drew
    Apr 27, 2015 at 4:57
  • My current thoughts are to use bookmark-all-names to generate a list of bookmarks, use 'assoc-string to find a bookmark in that list (and get its record), then use 'memq with that record to produce a truncated list and repeat the search for the same bookmark name (a duplicate) until I find no more duplicates. In each case I would use bookmark-get-filename to test if the file name of the bookmark in the list is the same as my candidate new bookmark. If I exhaust the list of matching bookmarks and don't find a matching file name, I would add the candidate bookmark as appropriate. Apr 28, 2015 at 11:21
  • Don't use assoc-string, memq, and the like. Use existing access functions and predicates from Bookmark+ or bookmark.el - that's what they're for. See updated answer for some code that might help. Your question keeps morphing... This kind of dialog-Q&A is not really what StackOverflow is for. I hope you have an answer to your original question by now. ;-)
    – Drew
    Apr 28, 2015 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .