Lines Matching full:clang

1 ;;; Clang Code-Completion minor mode, for use with C/Objective-C/C++.
5 ;; This minor mode uses Clang's command line interface for code
7 ;; and C++ source files. When enabled, Clang will provide
10 ;; space), Clang will provide the names of all structs visible from
12 ;; Clang will provide the names of all of the members of whatever
15 ;; completion based on Clang. It needs your help to make it better!
17 ;; To use the Clang code completion mode, first make sure that the
18 ;; "clang" variable below refers to the "clang" executable,
20 ;; clang-completion-mode.el somewhere in your Emacs load path. You can
33 ;; (load-library "clang-completion-mode")
37 ;; M-x customize-group RET clang-completion-mode RET
39 ;; Finally, to try Clang-based code completion in a particular buffer,
40 ;; use M-x clang-completion-mode. When "Clang" shows up in the mode
41 ;; line, Clang's code-completion is enabled.
43 ;; Clang's code completion is based on parsing the complete source
44 ;; file up to the point where the cursor is located. Therefore, Clang
47 ;; need to be placed into the clang-flags variable in a format
48 ;; acceptable to clang. This is a hack: patches are welcome to
49 ;; improve the interface between this Emacs mode and Clang!
53 ;;; The clang executable
54 (defcustom clang "clang" unknown
55 "The location of the Clang compiler executable"
57 :group 'clang-completion-mode)
59 ;;; Extra compilation flags to pass to clang.
60 (defcustom clang-flags nil
61 "Extra flags to pass to the Clang executable.
64 :group 'clang-completion-mode)
66 ;;; The prefix header to use with Clang code completion.
67 (setq clang-completion-prefix-header "")
70 (setq clang-completion-substring "")
73 (setq clang-completion-buffer nil)
75 (setq clang-result-string "")
84 ;;; Set the Clang prefix header
85 (defun clang-prefix-header ()
87 (setq clang-completion-prefix-header
88 (read-string "Clang prefix header> " "" clang-completion-prefix-header
94 (defun clang-completion-stash-filter (proc string)
95 (setq clang-result-string (concat clang-result-string string)))
105 (string-match (concat "COMPLETION: " clang-completion-substring) line)))
109 (defun clang-completion-display (buffer)
113 (let* ((all-lines (split-string clang-result-string "\n"))
135 (defun clang-completion-sentinel (proc event)
138 (defun clang-complete ()
144 (cc-pch (if (equal clang-completion-prefix-header "") nil
146 (concat clang-completion-prefix-header ".pch"))))
147 (cc-flags (if (listp clang-flags) clang-flags nil))
148 (cc-command (append `(,clang "-cc1" "-fsyntax-only")
153 (cc-buffer-name (concat "*Clang Completion for " (buffer-name) "*")))
158 (let ((cc-proc (get-process "Clang Code-Completion")))
162 (setq clang-completion-substring "")
163 (setq clang-result-string "")
164 (setq clang-completion-buffer cc-buffer-name)
167 (append (list "Clang Code-Completion" cc-buffer-name)
169 (set-process-filter cc-proc 'clang-completion-stash-filter)
170 (set-process-sentinel cc-proc 'clang-completion-sentinel)
175 (defun clang-complete-self-insert (arg)
179 (clang-complete))
183 (defun clang-update-filter ()
184 (setq clang-completion-substring (thing-at-point 'symbol))
185 (if (get-process "Clang Code-Completion")
187 (clang-completion-display clang-completion-buffer)
192 (defun clang-filter-self-insert (arg)
195 (clang-update-filter)
200 (defun clang-backspace ()
203 (clang-update-filter))
207 (defun clang-delete ()
210 (clang-update-filter))
212 ;; Set up the keymap for the Clang minor mode.
213 (defvar clang-completion-mode-map nil
214 "Keymap for Clang Completion Mode.")
216 (if (null clang-completion-mode-map)
217 (fset 'clang-completion-mode-map
218 (setq clang-completion-mode-map (make-sparse-keymap))))
220 (if (not (assq 'clang-completion-mode minor-mode-map-alist))
222 (cons (cons 'clang-completion-mode clang-completion-mode-map)
227 (define-key clang-completion-mode-map char 'clang-complete-self-insert))
236 (define-key clang-completion-mode-map char 'clang-filter-self-insert))
240 (define-key clang-completion-mode-map [(backspace)] 'clang-backspace)
241 (define-key clang-completion-mode-map [(delete)] 'clang-delete)
243 ;; Set up the Clang minor mode.
244 (define-minor-mode clang-completion-mode
245 "Clang code-completion mode"
247 " Clang"
248 clang-completion-mode-map)