]> code.delx.au - gnu-emacs-elpa/blob - company-xcode.el
Changed wrong Xcode types.
[gnu-emacs-elpa] / company-xcode.el
1 ;;; company-xcode.el --- a company-mode completion back-end for Xcode projects
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.3.1.
6 ;;
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 2
10 ;; of the License, or (at your option) any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 (require 'company)
21 (eval-when-compile (require 'cl))
22
23 (defcustom company-xcode-xcodeindex-executable (executable-find "xcodeindex")
24 "*Location of xcodeindex executable"
25 :group 'company-xcode
26 :type 'file)
27
28 (defvar company-xcode-tags nil)
29
30 (defun company-xcode-reset ()
31 "Reset the cached tags."
32 (interactive)
33 (setq company-xcode-tags nil))
34
35 (defcustom company-xcode-types
36 '("Class" "Constant" "Enum" "Macro" "Modeled Class" "Structure"
37 "Type" "Union" "Function")
38 "*The types of symbols offered by `company-xcode'
39 No context-enabled completion is available. Types like methods will be
40 offered regardless of whether the class supports them. The defaults should be
41 valid in most contexts."
42 :set (lambda (variable value)
43 (set variable value)
44 (company-xcode-reset))
45 :group 'company-xcode
46 :type '(set (const "Category") (const "Class") (const "Class Method")
47 (const "Constant") (const "Enum") (const "Field")
48 (const "Instance Method") (const "Instance Variable")
49 (const "Macro") (const "Modeled Class") (const "Modeled Method")
50 (const "Property") (const "Protocol") (const "Structure")
51 (const "Type") (const "Union") (const "Variable")
52 (const "Function")))
53
54 (defvar company-xcode-project 'unknown)
55 (make-variable-buffer-local 'company-xcode-project)
56
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
59 (defun company-xcode-fetch (project-bundle)
60 (setq project-bundle (directory-file-name project-bundle))
61 (message "Retrieving dump from %s..." project-bundle)
62 (with-temp-buffer
63 (let ((default-directory (file-name-directory project-bundle)))
64 (call-process company-xcode-xcodeindex-executable nil (current-buffer)
65 nil "dump" "-project"
66 (file-name-nondirectory project-bundle) "-quiet")
67 (goto-char (point-min))
68 (let ((regexp (concat "^\\([^\t\n]*\\)\t[^\t\n]*\t"
69 (regexp-opt company-xcode-types)
70 "\t[^\t\n]*\t[^\t\n]*"))
71 candidates)
72 (while (re-search-forward regexp nil t)
73 (add-to-list 'candidates (match-string 1)))
74 (message "Retrieving dump from %s...done" project-bundle)
75 candidates))))
76
77 (defun company-xcode-find-project ()
78 (let ((dir (if buffer-file-name
79 (file-name-directory buffer-file-name)
80 (expand-file-name default-directory)))
81 file)
82 (while (not (or file (equal dir "/")))
83 (setq file (car (directory-files dir t ".xcodeproj\\'" t))
84 dir (file-name-directory (directory-file-name dir))))
85 file))
86
87 (defun company-xcode-tags ()
88 (when (eq company-xcode-project 'unknown)
89 (setq company-xcode-project (company-xcode-find-project)))
90 (when company-xcode-project
91 (cdr (or (assoc company-xcode-project company-xcode-tags)
92 (car (push (cons company-xcode-project
93 (company-xcode-fetch company-xcode-project))
94 company-xcode-tags))))))
95 ;;;###autoload
96 (defun company-xcode (command &optional arg &rest ignored)
97 "A `company-mode' completion back-end for Xcode projects."
98 (interactive (list 'interactive))
99 (case command
100 ('interactive (company-begin-backend 'company-xcode))
101 ('prefix (and company-xcode-xcodeindex-executable
102 (not (company-in-string-or-comment))
103 (or (company-grab-symbol) 'stop)))
104 ('candidates (let ((completion-ignore-case nil))
105 (company-xcode-tags)
106 (all-completions arg (company-xcode-tags))))))
107
108
109 (provide 'company-xcode)
110 ;;; company-xcode.el ends here