I can think of at least two ways to handle multiple bookmarks
files. Firstly, according to the Introduction bookmarks page on the EmacsWiki
(Bookmark+ makes it easy to have multiple bookmark files – different sets of bookmarks for different uses.)
The second, and more generic option is to just test for your hostname in your init file. This is of course, just one of many ways to do it.
;; set bookmark file location
(cond ((eq (system-name) "work.local")
(setq bookmark-default-file "~/.emacs.d/boomarks-work"))
((eq (system-name) "home.local")
(setq bookmark-default-file "~/.emacs.d/boomarks-home"))
(t (setq bookmark-default-file "~/.emacs.d/bookmarks")))
;; load bookmarks package
(require 'bookmark)
(NB. Prior to Emacs 25.1 you'd test the variable system-name
, not the function system-name
.)
Elisp's cond
is akin to a "case statement" in other languages. In bash
the above would look like:
# set bookmark file location
case "$HOSTNAME" in
"work.local") BOOKMARK-DEFAULT-FILE="~/.emacs.d/bookmarks-work" ;;
"home.local") BOOKMARK-DEFAULT-FILE="~/.emacs.d/bookmarks-home" ;;
*) BOOKMARK-DEFAULT-FILE="~/.emacs.d/bookmarks"
esac
# load bookmarks package
source bookmark.sh
If you have just a simple test, and don't need a bunch of "elses", then maybe try Elisp's when
. Let's pretend you want one bookmark file everywhere except at work, which gets its own bookmark file.
;; when at work use a special bookmark file. use the default everywhere else
(when (eq (system-name) "work.local")
(setq bookmark-default-file (expand-file "~/.emacs.d/bookmarks-work")))
;; load bookmarks package
(require 'bookmark)
Check the Elisp manual page on conditionals for other conditional forms. Remember that your init file isn't "just a config file". It's elisp code, and you can do just about anything with it.