Linux Mint 20.2

Emacs 27.2

I installed Emacs 27.2 on my home and office computer. Both computers on LInux Mint 20.2

I has the same init.el for both computers. And its very convenient. I push my init.el to GitHub. And just use git pull to get the latest version of the SAME init.el for both computers. Nice.

But on my home computer and office computer I has different favorites dirs and files. As result I need to store two versions of file bookmarks. One for home and another for office. I can't push it to Github because the content of this 2 bookmarks's files are different.

So the questions are

  1. Is it possible in Emacs to load different version of bookmarks depend on environment - home or office ?
  2. Maybe has better solution for this kind of problem?

2 Answers 2


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"

# 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.

  • But what about not only bookmarks files. I also has 2 different "project" files. Can I use this approach not only for bookmarks files? Oct 8, 2021 at 16:43
  • 1
    Absolutely! Check the elisp manual page on conditionals for other conditional forms.
    – nega
    Oct 8, 2021 at 16:51

Here my solution:

In init.el file:

;; Load host specific files (e.g bookmarks)
(cond ((string-match "laptop" (system-name))
       (setq bookmark-default-file "~/.emacs.d/bookmarks-laptop"))
      ((string-match "workstation" (system-name))
       (setq bookmark-default-file "~/.emacs.d/bookmarks-workstation"))
      (t (setq bookmark-default-file "~/.emacs.d/bookmarks")))
  • 1
    (minor): string-match-p.
    – Drew
    Oct 8, 2021 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.