Function: bookmark-set-internal
bookmark-set-internal is a byte-compiled function defined in
bookmark.el.gz.
Signature
(bookmark-set-internal PROMPT NAME OVERWRITE-OR-PUSH)
Documentation
Set a bookmark using specified NAME or prompting with PROMPT.
The bookmark is set at the current location.
If NAME is non-nil, use it as the name of the new bookmark. In this case, the value of PROMPT is ignored.
Otherwise, prompt the user for the bookmark name. Begin the interactive prompt with PROMPT, followed by a space, a generated default name in parentheses, a colon and a space.
OVERWRITE-OR-PUSH controls what happens if there is already a
bookmark with the same name: nil means signal an error;
overwrite means replace any existing bookmark; push means
push the new bookmark onto the bookmark alist. The push
behavior means that among bookmarks with the same name, this most
recently set one becomes the one in effect, but the others are
still there, in order, if the topmost one is ever deleted.
Source Code
;; Defined in /usr/src/emacs/lisp/bookmark.el.gz
(defun bookmark-set-internal (prompt name overwrite-or-push)
"Set a bookmark using specified NAME or prompting with PROMPT.
The bookmark is set at the current location.
If NAME is non-nil, use it as the name of the new bookmark. In
this case, the value of PROMPT is ignored.
Otherwise, prompt the user for the bookmark name. Begin the
interactive prompt with PROMPT, followed by a space, a generated
default name in parentheses, a colon and a space.
OVERWRITE-OR-PUSH controls what happens if there is already a
bookmark with the same name: nil means signal an error;
`overwrite' means replace any existing bookmark; `push' means
push the new bookmark onto the bookmark alist. The `push'
behavior means that among bookmarks with the same name, this most
recently set one becomes the one in effect, but the others are
still there, in order, if the topmost one is ever deleted."
(unwind-protect
(let* ((record (bookmark-make-record))
;; `defaults' is a transient element of the
;; extensible format described above in the section
;; `File format stuff'. Bookmark record functions
;; can use it to specify a list of default values
;; accessible via M-n while reading a bookmark name.
(defaults (bookmark-prop-get record 'defaults))
(default (if (consp defaults) (car defaults) defaults)))
(if defaults
;; Don't store default values in the record.
(setq record (assq-delete-all 'defaults record))
;; When no defaults in the record, use its first element.
(setq defaults (car record) default defaults))
(bookmark-maybe-load-default-file)
;; Don't set `bookmark-yank-point' and `bookmark-current-buffer'
;; if they have been already set in another buffer. (e.g gnus-art).
(unless (and bookmark-yank-point
bookmark-current-buffer)
(setq bookmark-yank-point (point))
(setq bookmark-current-buffer (current-buffer)))
(let ((str
(or name
(read-from-minibuffer
(format-prompt prompt default)
nil
bookmark-minibuffer-read-name-map
nil nil defaults))))
(and (string-equal str "") (setq str default))
(cond
((eq overwrite-or-push nil)
(if (bookmark-get-bookmark str t)
(error "A bookmark named \"%s\" already exists" str)
(bookmark-store str (cdr record) nil)))
((eq overwrite-or-push 'overwrite)
(bookmark-store str (cdr record) nil))
((eq overwrite-or-push 'push)
(bookmark-store str (cdr record) t))
(t
(error "Unrecognized value for `overwrite-or-push': %S"
overwrite-or-push)))
;; Ask for an annotation buffer for this bookmark
(when bookmark-use-annotations
(bookmark-edit-annotation str))
(when bookmark-fringe-mark
(bookmark--set-fringe-mark))))
(setq bookmark-yank-point nil)
(setq bookmark-current-buffer nil)))