I am using Emacsclient to open files in a Emacs server. The server configuration depends on the content of a JSON configuration file. A Perl script can read the config file and write a suitable Emacs Lisp hashtable load file, which the server can read to update its configuration.
I would like to avoid running the Perl script when there has been no modification to the JSON file. So I am thinking about setting a global variable
my-config-last-mod in the server, and check that against the current last-modification time of the JSON file. If there is a difference, the Perl script should run to update the server config.
How to compare file modification timestamps in Emacs?
Here is what I have in mind:
(defvar my-config-last-mod nil) (defun my-update-config () (let* ((config-fn "myconfig.json") (last-mod (shell-command-to-string (concat "stat -c %y " config-fn))) (fixed-case t) (literal t) (reload-config t)) ;; trim space at end (when (string-match "\\([[:space:]]\\|\n\\)*\\'" last-mod) (setq last-mod (replace-match "" fixed-case literal last-mod))) (when my-config-last-mod (when (my-compare-time-stamps my-config-last-mod last-mod) (setq reload-config nil))) (when reload-config (setq my-config-last-mod last-mod) (shell-command-to-string "my_update_config"))))
Is it possible to write
my-compare-time-stamps in pure Lisp, or would I have to use an external program?