0

I have an installed packages (say mypackage.el) in \.emacs.d\lisp\ directory. In that package there is

(defcustom xyz "path1" "Path to the program"
  :group 'blablabla
  :type 'string)

I would like to change the above as

(defcustom xyz "path2" "Path to the program"
  :group 'blablabla
  :type 'string)

I prefer to do this modification not in the package el file but in my init file. However adding the above in the init file has no effect and for the package the variable xyz is always path1.

1

defcustom (and defvar) are only for the library that defines the variable. You don't want to copy those.

As a user, you can either use the customize interface:

M-x customize-option RET xyz RET

or else you can use setq to set the value in your init file:

(setq xyz "path2")

As you'll have guessed from the names, the customize interface only works on defcustom variables (i.e. "user options").


However adding the above in the init file has no effect and for the package the variable xyz is always path1.

This is intentional. When a variable already has a value, and a defcustom or defvar for that variable is evaluated, the pre-existing value is kept. This means that you can (setq xyz "path2") in your init without needing to first load the library which defines the variable, because if you do subsequently load (or re-load) that library, the default value won't clobber your custom value.

  • 1
    n.b. setq doesn't necessarily work with defcustom variables, as they might have a custom setter function which does more complex things with the value, and using setq would mean that the setter function was not invoked. It will work in most cases, but using the customize interface is the guaranteed safe option. – phils Sep 5 '18 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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