-(defun company-clang--call-process (prefix &rest args)
- (with-temp-buffer
- (let ((res (apply 'call-process company-clang-executable nil t nil args)))
- (unless (eq 0 res)
- (company-clang--handle-error res args))
- ;; Still try to get any useful input.
- (company-clang--parse-output prefix))))
+(defun company-clang--start-process (prefix callback &rest args)
+ (let ((objc (derived-mode-p 'objc-mode))
+ (buf (get-buffer-create "*clang-output*")))
+ (with-current-buffer buf (erase-buffer))
+ (if (get-buffer-process buf)
+ (funcall callback nil)
+ (let ((process (apply #'start-process "company-clang" buf
+ company-clang-executable args)))
+ (set-process-sentinel
+ process
+ (lambda (proc status)
+ (unless (string-match-p "hangup" status)
+ (funcall
+ callback
+ (let ((res (process-exit-status proc)))
+ (with-current-buffer buf
+ (unless (eq 0 res)
+ (company-clang--handle-error res args))
+ ;; Still try to get any useful input.
+ (company-clang--parse-output prefix objc)))))))
+ (unless (company-clang--auto-save-p)
+ (send-region process (point-min) (point-max))
+ (send-string process "\n")
+ (process-send-eof process))))))