X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/ea5c4fde97706cd680b01324fe8638e8b183af77..900ae0d7a2270ea1d2ea00567e80a619333fd4e5:/company-cmake.el diff --git a/company-cmake.el b/company-cmake.el index 5e3b003e7..010df32e4 100644 --- a/company-cmake.el +++ b/company-cmake.el @@ -1,6 +1,6 @@ -;;; company-cmake.el --- company-mode completion back-end for CMake +;;; company-cmake.el --- company-mode completion backend for CMake -;; Copyright (C) 2013 Free Software Foundation, Inc. +;; Copyright (C) 2013-2014 Free Software Foundation, Inc. ;; Author: Chen Bin ;; Version: 0.2 @@ -29,7 +29,7 @@ (require 'cl-lib) (defgroup company-cmake nil - "Completion back-end for CMake." + "Completion backend for CMake." :group 'company) (defcustom company-cmake-executable @@ -59,9 +59,14 @@ They affect which types of symbols we get completion candidates for.") (defun company-cmake--replace-tags (rlt) (setq rlt (replace-regexp-in-string - "\\(.*\\)\\(.*\\)" - (mapconcat 'identity '("\\1CXX\\2" "\\1C\\2" "\\1G77\\2") "\n") - rlt)) + "\\(.*?\\(IS_GNU\\)?\\)\\(.*\\)" + (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 "\\(.*\\)\\(.*\\)" (mapconcat 'identity '("\\1DEBUG\\2" "\\1RELEASE\\2" @@ -79,23 +84,14 @@ They affect which types of symbols we get completion candidates for.") ;; If hash is empty, fill it. (unless (gethash arg company-cmake--candidates-cache) (with-temp-buffer - (let ((res 0)) - (setq res (call-process company-cmake-executable nil t nil arg)) - (unless (eq 0 res) + (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--find-match (pattern line cmd) - (let (match) - ;; General Flags - (if (string-match pattern line) - (if (setq match (match-string 1 line)) - (puthash match cmd company-cmake--meta-command-cache))) - match)) - (defun company-cmake--parse (prefix content cmd) (let ((start 0) (pattern (format company-cmake--completion-pattern @@ -105,8 +101,11 @@ They affect which types of symbols we get completion candidates for.") match rlt) (dolist (line lines) - (if (setq match (company-cmake--find-match pattern line cmd)) - (push match rlt))) + (when (string-match pattern line) + (let ((match (match-string 1 line))) + (when match + (puthash match cmd company-cmake--meta-command-cache) + (push match rlt))))) rlt)) (defun company-cmake--candidates (prefix) @@ -129,15 +128,15 @@ They affect which types of symbols we get completion candidates for.") (defun company-cmake--unexpand-candidate (candidate) (cond - ((string-match "^CMAKE_\\(C\\|CXX\\|G77\\)\\(_.*\\)$" candidate) - (setq candidate (concat "CMAKE__" (match-string 2 candidate)))) + ((string-match "^CMAKE_\\(C\\|CXX\\|Fortran\\)\\(_.*\\)$" candidate) + (setq candidate (concat "CMAKE_" (match-string 2 candidate)))) ;; C flags ((string-match "^\\(.*_\\)IS_GNU\\(C\\|CXX\\|G77\\)$" candidate) (setq candidate (concat (match-string 1 candidate) "IS_GNU"))) ;; C flags - ((string-match "^\\(.*_\\)OVERRIDE_\\(C\\|CXX\\|G77\\)$" candidate) + ((string-match "^\\(.*_\\)OVERRIDE_\\(C\\|CXX\\|Fortran\\)$" candidate) (setq candidate (concat (match-string 1 candidate) "OVERRIDE_"))) ((string-match "^\\(.*\\)\\(_DEBUG\\|_RELEASE\\|_RELWITHDEBINFO\\|_MINSIZEREL\\)\\(.*\\)$" candidate) @@ -179,7 +178,7 @@ They affect which types of symbols we get completion candidates for.") (point-max)))))) (defun company-cmake (command &optional arg &rest ignored) - "`company-mode' completion back-end for CMake. + "`company-mode' completion backend for CMake. CMake is a cross-platform, open-source make system." (interactive (list 'interactive)) (cl-case command