Lines Matching +full:concat +full:- +full:map
1 ;;; Clang Code-Completion minor mode, for use with C/Objective-C/C++.
6 ;; completion to provide code completion results for C, Objective-C,
8 ;; code-completion results in a secondary buffer based on the code
11 ;; the current scope. After typing "p->" (triggered via the ">"),
20 ;; clang-completion-mode.el somewhere in your Emacs load path. You can
24 ;; (setq load-path (cons "~/.emacs.d" load-path))
28 ;; M-x load-library
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.
46 ;; options, etc.) to provide code-completion results. Currently, these
47 ;; need to be placed into the clang-flags variable in a format
57 :group 'clang-completion-mode)
60 (defcustom clang-flags nil
62 This variable will typically contain include paths, e.g., -I~/MyProject."
64 :group 'clang-completion-mode)
67 (setq clang-completion-prefix-header "")
70 (setq clang-completion-substring "")
73 (setq clang-completion-buffer nil)
75 (setq clang-result-string "")
78 (defun current-line ()
80 (+ (count-lines (point-min) (point))
81 (if (= (current-column) 0) 1 0)
82 -1))
85 (defun clang-prefix-header ()
87 (setq clang-completion-prefix-header
88 (read-string "Clang prefix header> " "" clang-completion-prefix-header
91 ;; Process "filter" that keeps track of the code-completion results
94 (defun clang-completion-stash-filter (proc string)
95 (setq clang-result-string (concat clang-result-string string)))
103 (defun is-completion-line (line)
104 (or (string-match "OVERLOAD:" line)
105 (string-match (concat "COMPLETION: " clang-completion-substring) line)))
108 ;; re-process the completions when further input narrows the field
109 (defun clang-completion-display (buffer)
110 (fill-buffer buffer))
112 (defun fill-buffer (buffer)
113 (let* ((all-lines (split-string clang-result-string "\n"))
114 (completion-lines (filter 'is-completion-line all-lines)))
115 (if (consp completion-lines)
118 (let ((cur (current-buffer)))
119 (set-buffer buffer)
120 (goto-char (point-min))
121 (erase-buffer)
122 (set-buffer cur))
125 (display-buffer buffer)
127 ;; Insert the code-completion string into the process buffer.
128 (with-current-buffer buffer
129 (insert (mapconcat 'identity completion-lines "\n")))
133 ;; contents of the code-completion buffer with the new code-completion results
135 (defun clang-completion-sentinel (proc event)
136 (fill-buffer (process-buffer proc)))
138 (defun clang-complete ()
139 (let* ((cc-point (concat (buffer-file-name)
141 (number-to-string (+ 1 (current-line)))
143 (number-to-string (+ 1 (current-column)))))
144 (cc-pch (if (equal clang-completion-prefix-header "") nil
145 (list "-include-pch"
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")
149 cc-flags
150 cc-pch
151 `("-code-completion-at" ,cc-point)
152 (list (buffer-file-name))))
153 (cc-buffer-name (concat "*Clang Completion for " (buffer-name) "*")))
154 ;; Start the code-completion process.
155 (if (buffer-file-name)
157 ;; If there is already a code-completion process, kill it first.
158 (let ((cc-proc (get-process "Clang Code-Completion")))
159 (if cc-proc
160 (delete-process cc-proc)))
162 (setq clang-completion-substring "")
163 (setq clang-result-string "")
164 (setq clang-completion-buffer cc-buffer-name)
166 (let ((cc-proc (apply 'start-process
167 (append (list "Clang Code-Completion" cc-buffer-name)
168 cc-command))))
169 (set-process-filter cc-proc 'clang-completion-stash-filter)
170 (set-process-sentinel cc-proc 'clang-completion-sentinel)
173 ;; Code-completion when one of the trigger characters is typed into
175 (defun clang-complete-self-insert (arg)
177 (self-insert-command arg)
178 (save-buffer)
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)
191 ;; update the filter for the currently-active code completion.
192 (defun clang-filter-self-insert (arg)
194 (self-insert-command arg)
195 (clang-update-filter)
199 ;; for the currently-active code completion.
200 (defun clang-backspace ()
202 (delete-backward-char 1)
203 (clang-update-filter))
206 ;; for the currently-active code completion.
207 (defun clang-delete ()
209 (delete-backward-char 1)
210 (clang-update-filter))
213 (defvar clang-completion-mode-map nil
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))
221 (setq minor-mode-map-alist
222 (cons (cons 'clang-completion-mode clang-completion-mode-map)
223 minor-mode-map-alist)))
227 (define-key clang-completion-mode-map char 'clang-complete-self-insert))
230 ;; currently-active code completion.
236 (define-key clang-completion-mode-map char 'clang-filter-self-insert))
238 ;; Delete and backspace filter the results of the currently-active
240 (define-key clang-completion-mode-map [(backspace)] 'clang-backspace)
241 (define-key clang-completion-mode-map [(delete)] 'clang-delete)
244 (define-minor-mode clang-completion-mode
245 "Clang code-completion mode"
248 clang-completion-mode-map)