- res)
- (with-current-buffer buf (erase-buffer))
- (setq res (if (company-clang--auto-save-p)
- (apply 'call-process company-clang-executable nil buf nil args)
- (apply 'call-process-region (point-min) (point-max)
- company-clang-executable nil buf nil args)))
- (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))))
+ ;; Looks unnecessary in Emacs 25.1 and later.
+ (process-adaptive-read-buffering nil))
+ (if (get-buffer-process buf)
+ (funcall callback nil)
+ (with-current-buffer buf
+ (erase-buffer)
+ (setq buffer-undo-list t))
+ (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))))))