Subject: bug#18620: 25.0.50; cfengine3-make-syntax-cache

From: Leo Liu <[email-masked]>
Date: Tue, 07 Oct 2014 11:22:46 +0800

On 2014-10-06 22:31 -0400, Ted Zlatanov wrote:
> Thanks for catching this, I had not noticed it sooner. Please see the
> patch below; does it work for you? If so I will commit and close the
> bug.

cfengine3-make-syntax-cache may still return a regexp and it won't fall
back on cfengine3-fallback-syntax when `cf-promises -s json' fails; how
about something along these lines?

=== modified file 'lisp/progmodes/cfengine.el'
--- lisp/progmodes/cfengine.el	2014-01-30 07:42:57 +0000
+++ lisp/progmodes/cfengine.el	2014-10-07 03:10:44 +0000
@@ -1231,29 +1231,31 @@
   (setq cfengine-mode-syntax-cache nil))
 
 (defun cfengine3-make-syntax-cache ()
-  "Build the CFEngine 3 syntax cache.
+  "Build the CFEngine 3 syntax cache and return it.
 Calls `cfengine-cf-promises' with \"-s json\""
-  (let ((syntax (cddr (assoc cfengine-cf-promises cfengine-mode-syntax-cache))))
-    (if cfengine-cf-promises
-        (or syntax
-            (with-demoted-errors
-                (with-temp-buffer
-                  (call-process-shell-command cfengine-cf-promises
-                                              nil   ; no input
-                                              t     ; current buffer
-                                              nil   ; no redisplay
-                                              "-s" "json")
-                  (goto-char (point-min))
-                  (setq syntax (json-read))
-                  (setq cfengine-mode-syntax-cache
-                        (cons (cons cfengine-cf-promises syntax)
-                              cfengine-mode-syntax-cache))
-                  (setq cfengine-mode-syntax-functions-regex
-                        (regexp-opt (mapcar (lambda (def)
-                                              (format "%s" (car def)))
-                                            (cdr (assq 'functions syntax)))
-                                    'symbols))))))
-    cfengine3-fallback-syntax))
+  (or (cddr (assoc cfengine-cf-promises cfengine-mode-syntax-cache))
+      (when cfengine-cf-promises
+        (with-demoted-errors "cfengine3-make-syntax-cache: %S"
+          (with-temp-buffer
+            (process-file cfengine-cf-promises
+                          nil           ; no input
+                          t             ; current buffer
+                          nil           ; no redisplay
+                          "-s" "json")
+            (goto-char (point-min))
+            (let ((syntax (json-read)))
+              (when (and (listp syntax)
+                         (assq 'functions syntax))
+                (setq cfengine-mode-syntax-cache
+                      (cons (cons cfengine-cf-promises syntax)
+                            cfengine-mode-syntax-cache))
+                (setq cfengine-mode-syntax-functions-regex
+                      (regexp-opt (mapcar (lambda (def)
+                                            (format "%s" (car def)))
+                                          (cdr (assq 'functions syntax)))
+                                  'symbols))
+                syntax)))))
+      cfengine3-fallback-syntax))
 
 (defun cfengine3-documentation-function ()
   "Document CFengine 3 functions around point.
@@ -1265,7 +1267,6 @@
 
 (defun cfengine3-completion-function ()
   "Return completions for function name around or before point."
-  (cfengine3-make-syntax-cache)
   (let* ((bounds (save-excursion
                    (let ((p (point)))
                      (skip-syntax-backward "w_" (point-at-bol))

>
> LL> 3. cf-promises doesn't have -s option in Centos 6.5 (cfengine 3.3)
>
> I think that's all right, we will default to the fallback syntax. The
> `-s' option was added after 3.3 but IMO the fallback syntax is good
> enough for all 3.x work.
>
> (Unfortunately the Red Hat ecosystem has no CFEngine package maintainers
> so to get the latest you have to install from the official CFEngine
> package repo as directed by their website.)

Agreed. Sad to see this and the cf community seems not very active. BTW,
do you know if CF is still part of GNU? I only see version 2 on GNU¹.

> Thanks
> Ted

Thanks,
Leo

Footnotes: 
¹  http://www.gnu.org/software/cfengine/