Merge branch 'master' of https://github.com/Hackerpilot/DCD
This commit is contained in:
commit
4f99f1746b
|
@ -1,16 +1,28 @@
|
||||||
#EMACS Integration
|
#EMACS Integration
|
||||||
|
|
||||||
This is a first cut at emacs support. It is far from complete.
|
|
||||||
|
|
||||||
##Requirements
|
##Requirements
|
||||||
* You must have the [auto-complete](https://github.com/auto-complete/auto-complete) package
|
* You must have the [auto-complete](https://github.com/auto-complete/auto-complete) package.
|
||||||
* This integration will not automatically start dcd-server, so you'll have to do that yourself.
|
* Make sure dcd-client and dcd-server is in your exec-path. Otherwise, please set the variable ```dcd-exectutable``` and ```dcd-server-executable``` using ```M-x customize```.
|
||||||
* Make sure dcd-client is in your path
|
|
||||||
* Add the following to your .emacs
|
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
* First, follow the Setup section in the root README.
|
||||||
|
* Second, add the following to your .emacs. With this setting, dcd-server starts automatically when you open file in d-mode.
|
||||||
|
```
|
||||||
|
(add-to-list 'load-path "path_to_ac-dcd.el")
|
||||||
(require 'ac-dcd)
|
(require 'ac-dcd)
|
||||||
(add-to-list 'ac-modes 'd-mode)
|
(add-to-list 'ac-modes 'd-mode)
|
||||||
(defun ac-d-mode-setup ()
|
(defun ac-d-mode-setup ()
|
||||||
(setq ac-sources (append '(ac-source-dcd) ac-sources))
|
(ac-dcd-maybe-start-server)
|
||||||
(global-auto-complete-mode t))
|
(add-to-list 'ac-sources 'ac-source-dcd)
|
||||||
|
(auto-complete-mode t))
|
||||||
(add-hook 'd-mode-hook 'ac-d-mode-setup)
|
(add-hook 'd-mode-hook 'ac-d-mode-setup)
|
||||||
|
```
|
||||||
|
* Third, set import path using ```M-x customize-variable RET ac-dcd-flags```.
|
||||||
|
* When something is wrong, please check variables with ```M-x customize-apropos RET ac-dcd``` and restart server with ```M-x ac-dcd-init-server```.
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
* better error detection
|
||||||
|
* detailed ac-source symbol
|
||||||
|
* goto definition
|
||||||
|
* show doc
|
||||||
|
* and so on...
|
||||||
|
|
|
@ -21,19 +21,19 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(provide 'ac-dcd)
|
|
||||||
(require 'auto-complete)
|
(require 'auto-complete)
|
||||||
|
|
||||||
(defcustom ac-dcd-executable
|
(defcustom ac-dcd-executable
|
||||||
(executable-find "dcd-client")
|
"dcd-client"
|
||||||
"*Location of dcd-client executable"
|
"Location of dcd-client executable."
|
||||||
:group 'auto-complete
|
:group 'auto-complete
|
||||||
:type 'file)
|
:type 'file)
|
||||||
|
|
||||||
;;; Extra compilation flags to pass to dcd.
|
;;; Extra compilation flags to pass to dcd.
|
||||||
(defcustom ac-dcd-flags nil
|
(defcustom ac-dcd-flags nil
|
||||||
"Extra flags to pass to the Dcd executable.
|
"Extra flags to pass to the dcd-server.
|
||||||
This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \"-I.\" )."
|
This variable will typically contain include paths, e.g., (\"-I~/MyProject\", \"-I.\").
|
||||||
|
You can't put port number flag here. Set `ac-dcd-server-port' instead."
|
||||||
:group 'auto-complete
|
:group 'auto-complete
|
||||||
:type '(repeat (string :tag "Argument" "")))
|
:type '(repeat (string :tag "Argument" "")))
|
||||||
|
|
||||||
|
@ -42,6 +42,52 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
|
|
||||||
(defconst ac-dcd-error-buffer-name "*dcd error*")
|
(defconst ac-dcd-error-buffer-name "*dcd error*")
|
||||||
|
|
||||||
|
(defcustom ac-dcd-server-executable
|
||||||
|
"dcd-server"
|
||||||
|
"Location of dcd-server executable."
|
||||||
|
:group 'auto-complete
|
||||||
|
:type 'file)
|
||||||
|
|
||||||
|
(defcustom ac-dcd-server-port 9166
|
||||||
|
"Port number of dcd-server. default is 9166."
|
||||||
|
:group 'auto-complete)
|
||||||
|
|
||||||
|
(defvar ac-dcd-delay-after-kill-process 200
|
||||||
|
"Duration after killing server process in milli second.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defun ac-dcd-stop-server ()
|
||||||
|
"Stop dcd-server manually. Ordinary, you don't have to call it.
|
||||||
|
If you want to restart server, use `ac-dcd-init-server' instead."
|
||||||
|
(interactive)
|
||||||
|
(interrupt-process "dcd-server"))
|
||||||
|
|
||||||
|
(defsubst ac-dcd-start-server ()
|
||||||
|
"Start dcd-server."
|
||||||
|
(let ((buf (get-buffer-create "*dcd-server*")))
|
||||||
|
(with-current-buffer buf (start-process "dcd-server" (current-buffer)
|
||||||
|
ac-dcd-server-executable
|
||||||
|
(mapconcat 'identity ac-dcd-flags " ")
|
||||||
|
"-p"
|
||||||
|
(format "%s" ac-dcd-server-port)
|
||||||
|
))))
|
||||||
|
|
||||||
|
(defun ac-dcd-maybe-start-server ()
|
||||||
|
"Start dcd-server. When the server process is already running, do nothing."
|
||||||
|
(unless (get-process "dcd-server")
|
||||||
|
(ac-dcd-start-server)))
|
||||||
|
|
||||||
|
(defun ac-dcd-init-server ()
|
||||||
|
"Start dcd-server. When the server process is already running, restart it."
|
||||||
|
(interactive)
|
||||||
|
(when (get-process "dcd-server")
|
||||||
|
(ac-dcd-stop-server)
|
||||||
|
(sleep-for 0 ac-dcd-delay-after-kill-process))
|
||||||
|
(ac-dcd-start-server))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun ac-dcd-parse-output (prefix)
|
(defun ac-dcd-parse-output (prefix)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((pattern (format ac-dcd-completion-pattern
|
(let ((pattern (format ac-dcd-completion-pattern
|
||||||
|
@ -89,12 +135,16 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(setq buffer-read-only t)
|
(setq buffer-read-only t)
|
||||||
(goto-char (point-min))))))
|
(goto-char (point-min))))))
|
||||||
|
|
||||||
(defun ac-dcd-call-process (prefix &rest args)
|
|
||||||
|
|
||||||
|
(defun ac-dcd-call-process (prefix args)
|
||||||
(let ((buf (get-buffer-create "*dcd-output*"))
|
(let ((buf (get-buffer-create "*dcd-output*"))
|
||||||
res)
|
res)
|
||||||
(with-current-buffer buf (erase-buffer))
|
(with-current-buffer buf (erase-buffer))
|
||||||
(setq res (apply 'call-process-region (point-min) (point-max)
|
(setq res (apply 'call-process-region (point-min) (point-max)
|
||||||
ac-dcd-executable nil buf nil args))
|
ac-dcd-executable nil buf nil
|
||||||
|
args
|
||||||
|
))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(unless (eq 0 res)
|
(unless (eq 0 res)
|
||||||
(ac-dcd-handle-error res args))
|
(ac-dcd-handle-error res args))
|
||||||
|
@ -102,10 +152,12 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(ac-dcd-parse-output prefix))))
|
(ac-dcd-parse-output prefix))))
|
||||||
|
|
||||||
(defsubst ac-dcd-build-complete-args (pos)
|
(defsubst ac-dcd-build-complete-args (pos)
|
||||||
(append '()
|
(list
|
||||||
'("-c")
|
"-c"
|
||||||
(list (format "%s" pos))
|
(format "%s" pos)
|
||||||
ac-dcd-flags))
|
"-p"
|
||||||
|
(format "%s" ac-dcd-server-port)
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
(defsubst ac-dcd-clean-document (s)
|
(defsubst ac-dcd-clean-document (s)
|
||||||
|
@ -128,7 +180,7 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(unless (ac-in-string/comment)
|
(unless (ac-in-string/comment)
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
(apply 'ac-dcd-call-process
|
(ac-dcd-call-process
|
||||||
ac-prefix
|
ac-prefix
|
||||||
(ac-dcd-build-complete-args (point))))))
|
(ac-dcd-build-complete-args (point))))))
|
||||||
|
|
||||||
|
@ -172,7 +224,8 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(requires . 0)
|
(requires . 0)
|
||||||
(document . ac-dcd-document)
|
(document . ac-dcd-document)
|
||||||
(action . ac-dcd-action)
|
(action . ac-dcd-action)
|
||||||
(cache)))
|
(cache)
|
||||||
|
(symbol . "D")))
|
||||||
|
|
||||||
(defun ac-dcd-same-count-in-string (c1 c2 s)
|
(defun ac-dcd-same-count-in-string (c1 c2 s)
|
||||||
(let ((count 0) (cur 0) (end (length s)) c)
|
(let ((count 0) (cur 0) (end (length s)) c)
|
||||||
|
@ -203,6 +256,8 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(t
|
(t
|
||||||
sl))))
|
sl))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun ac-template-candidate ()
|
(defun ac-template-candidate ()
|
||||||
ac-template-candidates)
|
ac-template-candidates)
|
||||||
|
|
||||||
|
@ -226,4 +281,5 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \
|
||||||
(cache)
|
(cache)
|
||||||
(symbol . "t")))
|
(symbol . "t")))
|
||||||
|
|
||||||
;;; auto-complete-dcd.el ends here
|
(provide 'ac-dcd)
|
||||||
|
;;; ac-dcd.el ends here
|
||||||
|
|
Loading…
Reference in New Issue