From 1af4592911aef8eb55acf4a82ef740888d85fc93 Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Wed, 18 Jun 2014 21:20:31 +0900 Subject: [PATCH] server starts automatically, user can configure port number, and so on. --- editors/emacs/README.md | 36 +++++++++++------ editors/emacs/ac-dcd.el | 88 +++++++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 28 deletions(-) diff --git a/editors/emacs/README.md b/editors/emacs/README.md index 780920b..c1bd556 100644 --- a/editors/emacs/README.md +++ b/editors/emacs/README.md @@ -1,16 +1,28 @@ #EMACS Integration -This is a first cut at emacs support. It is far from complete. - ##Requirements -* 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 is in your path -* Add the following to your .emacs +* You must have the [auto-complete](https://github.com/auto-complete/auto-complete) package. +* 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```. - (require 'ac-dcd) - (add-to-list 'ac-modes 'd-mode) - (defun ac-d-mode-setup () - (setq ac-sources (append '(ac-source-dcd) ac-sources)) - (global-auto-complete-mode t)) - (add-hook 'd-mode-hook 'ac-d-mode-setup) +## 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) +(add-to-list 'ac-modes 'd-mode) +(defun ac-d-mode-setup () + (ac-dcd-maybe-start-server) + (add-to-list 'ac-sources 'ac-source-dcd) + (auto-complete-mode t)) +(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... \ No newline at end of file diff --git a/editors/emacs/ac-dcd.el b/editors/emacs/ac-dcd.el index 3c4f121..4addbb2 100644 --- a/editors/emacs/ac-dcd.el +++ b/editors/emacs/ac-dcd.el @@ -21,19 +21,19 @@ ;;; Code: -(provide 'ac-dcd) (require 'auto-complete) (defcustom ac-dcd-executable - (executable-find "dcd-client") - "*Location of dcd-client executable" + "dcd-client" + "Location of dcd-client executable." :group 'auto-complete :type 'file) ;;; Extra compilation flags to pass to dcd. (defcustom ac-dcd-flags nil - "Extra flags to pass to the Dcd executable. -This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \"-I.\" )." + "Extra flags to pass to the dcd-server. +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 :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*") +(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) (goto-char (point-min)) (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) (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*")) res) (with-current-buffer buf (erase-buffer)) (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 (unless (eq 0 res) (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)))) (defsubst ac-dcd-build-complete-args (pos) - (append '() - '("-c") - (list (format "%s" pos)) - ac-dcd-flags)) + (list + "-c" + (format "%s" pos) + "-p" + (format "%s" ac-dcd-server-port) + )) (defsubst ac-dcd-clean-document (s) @@ -128,9 +180,9 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \ (unless (ac-in-string/comment) (save-restriction (widen) - (apply 'ac-dcd-call-process - ac-prefix - (ac-dcd-build-complete-args (point)))))) + (ac-dcd-call-process + ac-prefix + (ac-dcd-build-complete-args (point)))))) (defvar ac-template-start-point nil) (defvar ac-template-candidates (list "ok" "no" "yes:)")) @@ -172,7 +224,8 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \ (requires . 0) (document . ac-dcd-document) (action . ac-dcd-action) - (cache))) + (cache) + (symbol . "D"))) (defun ac-dcd-same-count-in-string (c1 c2 s) (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 sl)))) + + (defun ac-template-candidate () ac-template-candidates) @@ -226,4 +281,5 @@ This variable will typically contain include paths, e.g., ( \"-I~/MyProject\", \ (cache) (symbol . "t"))) -;;; auto-complete-dcd.el ends here +(provide 'ac-dcd) +;;; ac-dcd.el ends here