I have the following code to set a custom.el file and load Bookmark+:

(setq custom-file  (concat elf-emacs-lib-home-directory "emacs-config/" "custom.el"))
(when (file-exists-p custom-file) (load custom-file :noerror))

(setq bookmark-default-file  (substitute-in-file-name "$HOME/.emacs.d/.bookmarks"))

(use-package bookmark+              ;;; Bookmark+: extensions to standard library `bookmark.el'.
  (defvar bmkp-last-as-first-bookmark-file)
  (defvar bmkp-bmenu-state-file)
  (setq bmkp-last-as-first-bookmark-file bookmark-default-file) ;; load the the last-used bookmark file first
  (setq bmkp-bmenu-state-file            (substitute-in-file-name "$HOME/.emacs.d/.bmk-bmenu-state.el")))

My problem is that I keep getting this in my custom-set-variables:

 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(bmkp-last-as-first-bookmark-file "/users/name/.emacs.d/.bookmarks")

How do I prevent this variable from being placed in custom-set-variables?

1 Answer 1

  1. Please explain why you do not want that user option to be saved in your custom-file. That's the logical place for it. User options are saved in custom-file if it exists, or in your init file otherwise.

  2. If you really do not want it to be saved there , and you do not want it to be customizable (using Customize), you can do this:

    (put 'bmkp-last-as-first-bookmark-file 'standard-value nil)

    You can still set it using, say, setq. And you can still save it in some other way.

Update after comments -

I see what's happening. The point of this option is to let you choose to use start a new Emacs session using the last bookmark file that was used in your last Emacs session. If you want that then that value needs to be saved. It is saved in your custom-file.

You are anyway not saving that information in any way -- use-package and your use of use-package do not do anything like that.

All you are doing is setting that option value to the value of bookmark-default-file each time you start an Emacs session.

If you want to use the value of bookmark-default-file each time you start an Emacs session then option bmkp-last-as-first-bookmark-file should be nil. Customize the value to be nil and your problem should go away. The behavior you will get will be to use the same bookmark file each time you start Emacs (more precisely, the value of bookmark-default-file, which you could of course change from one session to another in some way).

Here is the doc of option bmkp-last-as-first-bookmark-file. Please pay special attention to what I've put in bold. Let me know, if you still have a question.

bmkp-last-as-first-bookmark-file is a variable defined in bookmark+-1.el().

Its value is "..."


Whether to use the last-used bookmark file as the first used.

If nil then Emacs always uses the value of bookmark-default-file as the initial bookmark file, in any given session.

If non-nil, Emacs uses the last bookmark file you used, in the last Emacs session. If none was recorded then it uses bookmark-default-file. The particular non-nil value must be an absolute file name (possibly containing ~) - it is not expanded).

NOTE: A non-nil option value is overwritten by Bookmark+, so that it becomes the last-used bookmark file. A nil value is never overwritten.

You can customize this variable.

  • I don't want it there because I explicitly set it in the use-package command which is called from my init.el file. Variables being set in multiple places is confusing at best. I set the variable explicitly so I don't want to see it in custom-set-variables. I version control all my emacs files including custom.el. The real problem is when I change systems the substitute-in-file-name gets expanded to properly point to the correct file. And the value in custom doesn't update the way I'd like it to. So the easiest thing for me is just remove it. Jul 5, 2017 at 13:15
  • I'm still getting it in custom.el but now I get '(bmkp-last-as-first-bookmark-file "/users/my_name/.emacs.d/.bookmarks" t) Jul 5, 2017 at 13:26
  • If you don't use Customize (or its functions) to change and save the value then it shouldn't be saved in your custom-file. But of course if you did ever use Customize to do that then it is still in your custom-file. Did you try editing your custom-file to remove it? Or did you try using Customize to reset the value to the standard value (so you can then set it in some other way, such as use-package)? It's not clear to me just what you are doing, but a guess is that its presence in your custom-file is just vestigial - try removing it.
    – Drew
    Jul 5, 2017 at 13:35
  • I'm constantly deleting it out of my custom.el and it keeps getting placed back in there. I have never used customize for this, only set it through my init.el. This is the only variable I have problems with and I have at least 30 packages and I set all kinds of custom things. I think it might do this when emacs closes. I see it says saving bookmarks... Jul 5, 2017 at 14:16
  • Thank you so much Drew! I see it in the documentation now. My apologies, I should have read the documentation once I saw the behavior. Jul 5, 2017 at 21:32

Your Answer

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

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