Function: bookmark-load

bookmark-load is an autoloaded, interactive and byte-compiled function defined in bookmark.el.gz.

Signature

(bookmark-load FILE &optional OVERWRITE NO-MSG DEFAULT)

Documentation

Load bookmarks from FILE (which must be in bookmark format).

Appends loaded bookmarks to the front of the list of bookmarks. If argument OVERWRITE is non-nil, existing bookmarks are destroyed. Optional third arg NO-MSG means don't display any messages while loading. If DEFAULT is non-nil make FILE the new bookmark file to watch. Interactively, a prefix arg makes OVERWRITE and DEFAULT non-nil.

If you load a file that doesn't contain a proper bookmark alist, you will corrupt Emacs's bookmark list. Generally, you should only load in files that were created with the bookmark functions in the first place. Your own personal bookmark file, specified by the variable bookmark-default-file, is maintained automatically by Emacs; you shouldn't need to load it explicitly.

If you load a file containing bookmarks with the same names as bookmarks already present in your Emacs, the new bookmarks will get unique numeric suffixes "<2>", "<3>", etc.

View in manual

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/bookmark.el.gz
;;;###autoload
(defun bookmark-load (file &optional overwrite no-msg default)
  "Load bookmarks from FILE (which must be in bookmark format).
Appends loaded bookmarks to the front of the list of bookmarks.
If argument OVERWRITE is non-nil, existing bookmarks are destroyed.
Optional third arg NO-MSG means don't display any messages while loading.
If DEFAULT is non-nil make FILE the new bookmark file to watch.
Interactively, a prefix arg makes OVERWRITE and DEFAULT non-nil.

If you load a file that doesn't contain a proper bookmark alist, you
will corrupt Emacs's bookmark list.  Generally, you should only load
in files that were created with the bookmark functions in the first
place.  Your own personal bookmark file, specified by the variable
`bookmark-default-file', is maintained automatically by Emacs; you
shouldn't need to load it explicitly.

If you load a file containing bookmarks with the same names as
bookmarks already present in your Emacs, the new bookmarks will get
unique numeric suffixes \"<2>\", \"<3>\", etc."
  (interactive
   (let ((default (abbreviate-file-name
		   (or (car bookmark-bookmarks-timestamp)
		       (expand-file-name bookmark-default-file))))
	 (prefix current-prefix-arg))
     (list (read-file-name (format "Load bookmarks from: (%s) " default)
			   (file-name-directory default) default 'confirm)
	   prefix nil prefix)))
  (let* ((file (expand-file-name file))
	 (afile (abbreviate-file-name file)))
    (unless (file-readable-p file)
      (user-error "Cannot read bookmark file %s" afile))
    (let ((reporter
	   (unless no-msg
	     (make-progress-reporter
	      (format "Loading bookmarks from %s..." file)))))
      (with-current-buffer (let (enable-local-variables)
			     (find-file-noselect file))
	(goto-char (point-min))
	(let ((blist (bookmark-alist-from-buffer)))
	  (unless (listp blist)
	    (error "Invalid bookmark list in %s" file))
	  ;; RW: Upon loading the bookmarks, we could add to each bookmark
	  ;; in `bookmark-alist' an extra key `bookmark-file', so that
	  ;; upon reloading the bookmarks with OVERWRITE non-nil,
	  ;; we overwrite only those bookmarks for which the key `bookmark-file'
	  ;; matches FILE.  `bookmark-save' can ignore this key.
	  ;; Would this be a useful option?
	  (if overwrite
	      (setq bookmark-alist blist
		    bookmark-alist-modification-count 0)
	    (bookmark-import-new-list blist)
	    (setq bookmark-alist-modification-count
		  (1+ bookmark-alist-modification-count)))
	  (if (or default
		  (string= file (or (car bookmark-bookmarks-timestamp)
				    (expand-file-name bookmark-default-file))))
	      (setq bookmark-bookmarks-timestamp
		    (cons file (nth 5 (file-attributes file)))))
	  (bookmark-bmenu-surreptitiously-rebuild-list)
	  (setq bookmark-file-coding-system buffer-file-coding-system))
	(kill-buffer (current-buffer)))
      (run-hooks 'bookmark-after-load-file-hook)
      (unless no-msg
	(progress-reporter-done reporter)))))