2

I need to use a version of prolog.el not older than 1.25, so I defined the function maybe-reload-prolog-el:

(defun maybe-reload-prolog-el ()
  (when (version< prolog-mode-version "1.25")
    (add-to-list
     'load-path
     (file-name-as-directory (concat my-lib-path "prolog-el")))
    (load-library "prolog"))))

...which adds the path to my personal copy of prolog.el to load-path (and then reloads prolog) if it detects that prolog-mode-version is too old 1.

Then I put a call to maybe-reload-prolog-el in a hook I already had for prolog-mode:

(add-hook 'prolog-mode-hook
  (lambda ()
    ;; ;; some keyboard settings, like
    ;; (local-set-key [f10] ...)
    ;; (local-set-key  [f9] ...)
    ;; ;; etc
    (maybe-reload-prolog-el)))

The main problem with this approach is that prolog.el is responsible for more than prolog-mode. For example, it has the code for the autoloaded function run-prolog, which I use to run a Prolog sub-process in an Emacs buffer. AFAICT, prolog-mode-hook does not get triggered when I run run-prolog, so I end up running an outdated version of it.

Is there some way to trigger maybe-reload-prolog-el right after prolog.el is loaded, before any of its code gets executed?


BTW, as currently written, maybe-reload-prolog-el can run only after prolog.el is loaded, because it relies on the variable prolog-mode-version, which is defined in prolog.el, to decide whether to load my local copy of prolog.el. IOW, if I simply put the following code in my init file

(if (version< prolog-mode-version "1.25")
  (add-to-list
   'load-path
   (file-name-as-directory (concat my-lib-path "prolog-el"))))

...it fails with:

Symbol’s value as variable is void: prolog-mode-version

If there were some way to test the version of the default prolog.el's version before loading it (let's call this method PROLOG-OLDER-THAN-1.25-p, then I would just put this in my init file:

(if (PROLOG-OLDER-THAN-1.25-p)
  (add-to-list
   'load-path
   (file-name-as-directory (concat my-lib-path "prolog-el"))))

Please let me know if there's a way to implement a PROLOG-OLDER-THAN-1.25-p that does not require prolog.el to be loaded.


Of course, I know that I can always use my copy of prolog.el, unconditionally. IOW, I can just put this in my init file:

(add-to-list
 'load-path
 (file-name-as-directory (concat my-lib-path "prolog-el"))))

This approach works in the short-term, of course, but it requires more maintenance long-term.


1 Please let me know if what my maybe-reload-prolog-el function does is the best way to conditionally reload prolog.el. I'm not too confident that (load-library "prolog") is the right thing to do here.

  • 1
    "a way to implement PROLOG-OLDER-THAN-1.25-p that does not require prolog.el to be loaded" - the only way would be to search the source code text. – npostavs Feb 27 '17 at 16:06
  • 1
    You could try and inspect the data from the package manager package.el – YoungFrog Feb 27 '17 at 19:01
  • 1
    @YoungFrog prolog.el is not (yet) an package.el package. – npostavs Mar 1 '17 at 14:51
1

Did you try using eval-after-load or with-eval-after-load? E.g. something like this?

(eval-after-load "prolog" '(maybe-reload-prolog-el))

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.