aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2013-12-13 13:55:08 -0500
committerTed Zlatanov2013-12-13 13:55:08 -0500
commitd43957f334f87446f9ba206e27d362d5cd1d6920 (patch)
tree274ddec80145d9f48294835d4697c2d602ddb221
parent06a4f1102f40c2cb7ffa035b4f16b9039efaf95b (diff)
downloademacs-d43957f334f87446f9ba206e27d362d5cd1d6920.tar.gz
emacs-d43957f334f87446f9ba206e27d362d5cd1d6920.zip
More cfengine.el fixes over previous commit.
* progmodes/cfengine.el (cfengine-mode-syntax-functions-regex): Initialize sensibly. (cfengine3--current-word): Fix parameters. (cfengine3-make-syntax-cache): Simplify further. (cfengine3-completion-function, cfengine3--current-function): Use `assq' for symbols. (cfengine3--current-function): Fix `cfengine3--current-word' call.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/cfengine.el65
2 files changed, 43 insertions, 32 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8dd26cf294e..f5e0b7dbb18 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12013-12-13 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * progmodes/cfengine.el (cfengine-mode-syntax-functions-regex):
4 Initialize sensibly.
5 (cfengine3--current-word): Fix parameters.
6 (cfengine3-make-syntax-cache): Simplify further.
7 (cfengine3-completion-function, cfengine3--current-function): Use
8 `assq' for symbols.
9 (cfengine3--current-function): Fix `cfengine3--current-word' call.
10
12013-12-13 Glenn Morris <rgm@gnu.org> 112013-12-13 Glenn Morris <rgm@gnu.org>
2 12
3 * loadup.el (load-path): Warn if site-load or site-init changes it. 13 * loadup.el (load-path): Warn if site-load or site-init changes it.
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el
index 83eec8bde62..20dfb9dc748 100644
--- a/lisp/progmodes/cfengine.el
+++ b/lisp/progmodes/cfengine.el
@@ -153,8 +153,6 @@ bundle agent rcfiles
153(defvar cfengine-mode-syntax-cache nil 153(defvar cfengine-mode-syntax-cache nil
154 "Cache for `cfengine-mode' syntax trees obtained from 'cf-promises -s json'.") 154 "Cache for `cfengine-mode' syntax trees obtained from 'cf-promises -s json'.")
155 155
156(defvar cfengine-mode-syntax-functions-regex nil)
157
158(defconst cfengine3-fallback-syntax 156(defconst cfengine3-fallback-syntax
159 '((functions 157 '((functions
160 (userexists 158 (userexists
@@ -787,6 +785,12 @@ bundle agent rcfiles
787 (returnType . "context") (status . "normal")))) 785 (returnType . "context") (status . "normal"))))
788 "Fallback CFEngine syntax, containing just function definitions.") 786 "Fallback CFEngine syntax, containing just function definitions.")
789 787
788(defvar cfengine-mode-syntax-functions-regex
789 (regexp-opt (mapcar (lambda (def)
790 (format "%s" (car def)))
791 (cdr (assq 'functions cfengine3-fallback-syntax)))
792 'symbols))
793
790(defcustom cfengine-mode-abbrevs nil 794(defcustom cfengine-mode-abbrevs nil
791 "Abbrevs for CFEngine2 mode." 795 "Abbrevs for CFEngine2 mode."
792 :group 'cfengine 796 :group 'cfengine
@@ -1161,7 +1165,7 @@ Intended as the value of `indent-line-function'."
1161;; CLASS: [.|&!()a-zA-Z0-9_\200-\377]+:: 1165;; CLASS: [.|&!()a-zA-Z0-9_\200-\377]+::
1162;; CATEGORY: [a-zA-Z_]+: 1166;; CATEGORY: [a-zA-Z_]+:
1163 1167
1164(defun cfengine3--current-word (flist &optional bounds) 1168(defun cfengine3--current-word (&optional bounds)
1165 "Propose a word around point in the current CFEngine 3 buffer." 1169 "Propose a word around point in the current CFEngine 3 buffer."
1166 (save-excursion 1170 (save-excursion
1167 (skip-syntax-forward "w_") 1171 (skip-syntax-forward "w_")
@@ -1176,9 +1180,9 @@ Intended as the value of `indent-line-function'."
1176(defun cfengine3--current-function () 1180(defun cfengine3--current-function ()
1177 "Look up current CFEngine 3 function" 1181 "Look up current CFEngine 3 function"
1178 (let* ((syntax (cfengine3-make-syntax-cache)) 1182 (let* ((syntax (cfengine3-make-syntax-cache))
1179 (flist (assoc 'functions syntax))) 1183 (flist (assq 'functions syntax)))
1180 (when flist 1184 (when flist
1181 (let ((w (cfengine3--current-word flist))) 1185 (let ((w (cfengine3--current-word)))
1182 (and w (assq (intern w) flist)))))) 1186 (and w (assq (intern w) flist))))))
1183 1187
1184;; format from "cf-promises -s json", e.g. "sort" function: 1188;; format from "cf-promises -s json", e.g. "sort" function:
@@ -1225,6 +1229,8 @@ Intended as the value of `indent-line-function'."
1225 "")))) 1229 ""))))
1226 1230
1227(defun cfengine3-clear-syntax-cache () 1231(defun cfengine3-clear-syntax-cache ()
1232 "Clear the internal syntax cache.
1233Should not be necessary unless you reinstall CFEngine."
1228 (interactive) 1234 (interactive)
1229 (setq cfengine-mode-syntax-functions-regex nil) 1235 (setq cfengine-mode-syntax-functions-regex nil)
1230 (setq cfengine-mode-syntax-cache nil)) 1236 (setq cfengine-mode-syntax-cache nil))
@@ -1232,32 +1238,27 @@ Intended as the value of `indent-line-function'."
1232(defun cfengine3-make-syntax-cache () 1238(defun cfengine3-make-syntax-cache ()
1233 "Build the CFEngine 3 syntax cache. 1239 "Build the CFEngine 3 syntax cache.
1234Calls `cfengine-cf-promises' with \"-s json\"" 1240Calls `cfengine-cf-promises' with \"-s json\""
1235 (let ((ret (if cfengine-cf-promises 1241 (let ((syntax (cddr (assoc cfengine-cf-promises cfengine-mode-syntax-cache))))
1236 (let ((loaded-json-lib (require 'json nil t)) 1242 (if cfengine-cf-promises
1237 (syntax (cfengine3-make-syntax-cache))) 1243 (or syntax
1238 (if (not loaded-json-lib) 1244 (with-demoted-errors
1239 (message "JSON library could not be loaded!") 1245 (with-temp-buffer
1240 (unless syntax 1246 (call-process-shell-command cfengine-cf-promises
1241 (with-demoted-errors 1247 nil ; no input
1242 (with-temp-buffer 1248 t ; current buffer
1243 (call-process-shell-command cfengine-cf-promises 1249 nil ; no redisplay
1244 nil ; no input 1250 "-s" "json")
1245 t ; current buffer 1251 (goto-char (point-min))
1246 nil ; no redisplay 1252 (setq syntax (json-read))
1247 "-s" "json") 1253 (setq cfengine-mode-syntax-cache
1248 (goto-char (point-min)) 1254 (cons (cons cfengine-cf-promises syntax)
1249 (setq syntax (json-read)) 1255 cfengine-mode-syntax-cache))
1250 (setq cfengine-mode-syntax-cache 1256 (setq cfengine-mode-syntax-functions-regex
1251 (cons (cons cfengine-cf-promises syntax) 1257 (regexp-opt (mapcar (lambda (def)
1252 cfengine-mode-syntax-cache))))))) 1258 (format "%s" (car def)))
1253 cfengine3-fallback-syntax))) 1259 (cdr (assq 'functions syntax)))
1254 (unless cfengine-mode-syntax-functions-regex 1260 'symbols))))))
1255 (setq cfengine-mode-syntax-functions-regex 1261 cfengine3-fallback-syntax))
1256 (regexp-opt (mapcar (lambda (def)
1257 (format "%s" (car def)))
1258 (cdr (assoc 'functions ret)))
1259 'symbols)))
1260 ret))
1261 1262
1262(defun cfengine3-documentation-function () 1263(defun cfengine3-documentation-function ()
1263 "Document CFengine 3 functions around point. 1264 "Document CFengine 3 functions around point.
@@ -1272,7 +1273,7 @@ see. Use it by executing `turn-on-eldoc-mode'."
1272 (cfengine3-make-syntax-cache) 1273 (cfengine3-make-syntax-cache)
1273 (let* ((bounds (cfengine3--current-word t)) 1274 (let* ((bounds (cfengine3--current-word t))
1274 (syntax (cfengine3-make-syntax-cache)) 1275 (syntax (cfengine3-make-syntax-cache))
1275 (flist (assoc 'functions syntax))) 1276 (flist (assq 'functions syntax)))
1276 (when bounds 1277 (when bounds
1277 (append bounds (list (cdr flist)))))) 1278 (append bounds (list (cdr flist))))))
1278 1279