-(defun company-cmake--parse-output (prefix cmd)
- "Analyze the temp buffer and collect lines."
- (goto-char (point-min))
- (let ((pattern (format company-cmake--completion-pattern
+(defun company-cmake--replace-tags (rlt)
+ (setq rlt (replace-regexp-in-string
+ "\\(.*?\\(IS_GNU\\)?\\)<LANG>\\(.*\\)"
+ (lambda (_match)
+ (mapconcat 'identity
+ (if (match-beginning 2)
+ '("\\1CXX\\3" "\\1C\\3" "\\1G77\\3")
+ '("\\1CXX\\3" "\\1C\\3" "\\1Fortran\\3"))
+ "\n"))
+ rlt t))
+ (setq rlt (replace-regexp-in-string
+ "\\(.*\\)<CONFIG>\\(.*\\)"
+ (mapconcat 'identity '("\\1DEBUG\\2" "\\1RELEASE\\2"
+ "\\1RELWITHDEBINFO\\2" "\\1MINSIZEREL\\2")
+ "\n")
+ rlt))
+ rlt)
+
+(defun company-cmake--fill-candidates-cache (arg)
+ "Fill candidates cache if needed."
+ (let (rlt)
+ (unless company-cmake--candidates-cache
+ (setq company-cmake--candidates-cache (make-hash-table :test 'equal)))
+
+ ;; If hash is empty, fill it.
+ (unless (gethash arg company-cmake--candidates-cache)
+ (with-temp-buffer
+ (let ((res (call-process company-cmake-executable nil t nil arg)))
+ (unless (zerop res)
+ (message "cmake executable exited with error=%d" res)))
+ (setq rlt (buffer-string)))
+ (setq rlt (company-cmake--replace-tags rlt))
+ (puthash arg rlt company-cmake--candidates-cache))
+ ))
+
+(defun company-cmake--parse (prefix content cmd)
+ (let ((start 0)
+ (pattern (format company-cmake--completion-pattern