1

I've made a minor change to the existing code in bibtex.el; to be more precise, I've modified the function bibtex-generate-url-list so that it can generate URLs for several more fields (in addition to the DOI and URL fields that the existing code can handle).

I have written the code that I need, that's not a problem. The problem is that I don't know how to make emacs see the changes.

What I tried:

  1. Back up the original files bibtex.el.gz and the byte-compiled version bibtex.elc.
  2. Save my changes in the old location and byte-compile the file. So the versions of bibtex.el.gz and bibtex.elc in the directory /usr/local/share/emacs/24.4/lisp/textmodes now contain my changes.
  3. Restart emacs.

But my changes don't seem to work when I load a bibtex file.

So how can I make emacs use my changes?


For completeness, here is the code I added (everything after the doi entry). I've tested the regular expressions and they do what I want, so that's not the issue, as I explained above.

(defcustom bibtex-generate-url-list
 '((("url" . ".*:.*"))
(("doi" . "10\\.[0-9]+/.+")
 "http://dx.doi.org/%s"
 ("doi" ".*" 0))
(("mrkey" . "\\(mr\\)?[0-9]\\{1,8\\}")
 "http://www.ams.org/mathscinet-getitem?mr=%s"
 ("mrkey" "\\(mr\\)?\\([0-9]\\{1,8\\}\\)" 2))
(("arxiv" . "\\([0-9]\\{4\\}\\.[0-9]\\{4,5\\}\\|[-a-z]+/[0-9]\\{7\\}\\|[-a-z]+\\.[a-z]\\{2\\}/[0-9]\\{7\\}\\)\\(v[0-9]+\\)?")
 "http://arxiv.org/abs/%s"
 ("arxiv" ".*" 0))
(("zblnumber" . "\\([0-9]\\{4\\}\\.[0-9]\\{5\\}\\|[0-9]\\{8\\}\\)")
 "http://zbmath.org/?q=an:%s"
 ("zblnumber" ".*" 0)))

1 Answer 1

7
  1. Never modify the source code in its original location like that. You'll lose (or be forced to merge) your changes whenever you upgrade.

  2. defcustom defines a "user option" variable. Variables are designed to be modified without touching the code, and for user options there's even a UI for that:

    M-x customize-option RET bibtex-generate-url-list RET

    Emacs will save your customisations into your init file (or your custom-file, should that value be set).

    Type C-hr to visit the manual, and then m Customization RET to read about this facility.

  3. If you ever do find yourself needing to redefine some existing code, you can achieve that in your personal init file, without editing the original code.

  4. To set a user option value in code in your init file, use customize-set-variable:

    (customize-set-variable
     'bibtex-generate-url-list
     '((("url" . ".*:.*"))
       (("doi" . "10\\.[0-9]+/.+")
        "http://dx.doi.org/%s"
        ("doi" ".*" 0))
       (("mrkey" . "\\(mr\\)?[0-9]\\{1,8\\}")
        "http://www.ams.org/mathscinet-getitem?mr=%s"
        ("mrkey" "\\(mr\\)?\\([0-9]\\{1,8\\}\\)" 2))
       (("arxiv" . "\\([0-9]\\{4\\}\\.[0-9]\\{4,5\\}\\|[-a-z]+/[0-9]\\{7\\}\\|[-a-z]+\\.[a-z]\\{2\\}/[0-9]\\{7\\}\\)\\(v[0-9]+\\)?")
        "http://arxiv.org/abs/%s"
        ("arxiv" ".*" 0))
       (("zblnumber" . "\\([0-9]\\{4\\}\\.[0-9]\\{5\\}\\|[0-9]\\{8\\}\\)")
        "http://zbmath.org/?q=an:%s"
        ("zblnumber" ".*" 0))))
    

    You might also set it with setq (or just set, for a direct substitution in the above code), and with the majority of variables it won't matter, but there are some user options for which you need to be using customize-set-variable, so it's best to use that.

    If the variable was defined by defvar then you can safely use setq/set to set its value.

4
  • Is there some way to customize it by adding code to my init file rather than using the customization interface?
    – MTS
    Dec 10, 2015 at 0:53
  • 1
    Answer updated.
    – phils
    Dec 10, 2015 at 1:18
  • Minor point: shouldn't it be custom-set-variables? At least, I put the code in custom-set-variables in my init file and that worked.
    – MTS
    Dec 13, 2015 at 2:09
  • 1
    Using your custom-set-variables form will work fine, yes, and that was what my answer originally used. I changed it to customize-set-variable partly because it reduces the level of nesting in the code, but mostly because the init file comments suggest there should only be one call to custom-set-variables, so I didn't want to recommend that people add new ones (not that I know why that warning appears).
    – phils
    Dec 13, 2015 at 7:21

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.