]> code.delx.au - gnu-emacs-elpa/blobdiff - company-clang.el
Removed superfluous quotes.
[gnu-emacs-elpa] / company-clang.el
index 2cb2ce853733ce7feb6f83fceaec0e344de45aa4..5bd55355610e01410f7259bdf3c3a79c02bfe552 100644 (file)
@@ -2,7 +2,7 @@
 ;;
 ;; Copyright (C) 2010 Nikolaj Schumacher
 ;;
-;; This file is part of company 0.4.3.
+;; This file is part of company 0.5.
 ;;
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License
@@ -101,6 +101,7 @@ Prefix files (-include ...) can be selected with
   (goto-char (point-min))
   (let ((pattern (format company-clang--completion-pattern
                          (regexp-quote prefix)))
+        (case-fold-search nil)
         lines match)
     (while (re-search-forward pattern nil t)
       (setq match (match-string-no-properties 1))
@@ -145,7 +146,7 @@ Prefix files (-include ...) can be selected with
             (1+ (current-column)))))
 
 (defsubst company-clang--build-complete-args (pos)
-  (append '("-cc1" "-fsyntax-only")
+  (append '("-cc1" "-fsyntax-only" "-code-completion-macros")
           company-clang-arguments
           (when (stringp company-clang--prefix)
             (list "-include" (expand-file-name company-clang--prefix)))
@@ -176,6 +177,19 @@ Prefix files (-include ...) can be selected with
     (when (re-search-forward "\\`clang version \\([0-9.]+\\)" nil t)
       (match-string-no-properties 1))))
 
+(defun company-clang-objc-templatify (selector)
+  (let* ((end (point))
+         (beg (- (point) (length selector)))
+         (templ (company-template-declare-template beg end)))
+    (save-excursion
+      (goto-char beg)
+      (while (search-forward ":" end t)
+        (replace-match ":  ")
+        (incf end 2)
+        (company-template-add-field templ (1- (match-end 0)) "<arg>"))
+      (delete-char -1))
+    (company-template-move-to-first templ)))
+
 (defun company-clang (command &optional arg &rest ignored)
   "A `company-mode' completion back-end for clang.
 Clang is a parser for C and ObjC.  The unreleased development version of
@@ -190,18 +204,21 @@ Completions only work correctly when the buffer has been saved.
 `company-clang-auto-save' determines whether to do this automatically."
   (interactive (list 'interactive))
   (case command
-        ('interactive (company-begin-backend 'company-clang))
-        ('init (unless company-clang-executable
-                 (error "Company found no clang executable"))
-               (when (version< (company-clang-version)
-                               company-clang-required-version)
-                 (error "Company requires clang version 1.1")))
-        ('prefix (and (memq major-mode company-clang-modes)
-                      buffer-file-name
-                      company-clang-executable
-                      (not (company-in-string-or-comment))
-                      (or (company-grab-symbol) 'stop)))
-        ('candidates (company-clang--candidates arg))))
+    (interactive (company-begin-backend 'company-clang))
+    (init (unless company-clang-executable
+            (error "Company found no clang executable"))
+          (when (version< (company-clang-version)
+                          company-clang-required-version)
+            (error "Company requires clang version 1.1")))
+    (prefix (and (memq major-mode company-clang-modes)
+                 buffer-file-name
+                 company-clang-executable
+                 (not (company-in-string-or-comment))
+                 (or (company-grab-symbol) 'stop)))
+    (candidates (company-clang--candidates arg))
+    (post-completion (and (derived-mode-p 'objc-mode)
+                          (string-match ":" arg)
+                          (company-clang-objc-templatify arg)))))
 
 (provide 'company-clang)
 ;;; company-clang.el ends here