Emacs + Cider(Clojure)+自动完成:如何获取文档字符串?

时间:2014-05-20 17:39:25

标签: emacs autocomplete clojure cider

我正在尝试正确配置emacs来编写我的Clojure代码。我将此Emacs配置基于此good blog post

但是,我确实更改了一些设置,比如他正在使用的主题等等。我一直在检查自动完成(Eldoc?我不确定)在Clojure中显示函数的文档字符串,以及我自己代码。

我希望看到截图中的文档:

eldoc

然而,我无法得到"黄色"文档框出现。我不确定这是由于我的.emacs文件中的配置错误,还是我必须使用的命令或...

这是我的.emacs文件:

(add-to-list 'custom-theme-load-path "~/.emacs.d/lib/noctilux-theme")

(require 'package):
  (add-to-list 'package-archives
    '("marmalade" . "http://marmalade-repo.org/packages/")
    '("melpa" . "http://melpa.milkbox.net/packages/"))

;; Initialize all the ELPA packages (what is installed using the packages commands)    
(package-initialize)  

;; Set bigger fonts
(set-default-font "Courier New-13")  

;; Setup to have a french keyboard layout working   
(require 'iso-transl)  

;; Show parenthesis mode
(show-paren-mode 1)  

;; rainbow delimiters
(global-rainbow-delimiters-mode)

;; paredit
(add-hook 'clojure-mode-hook 'paredit-mode)
(add-hook 'nrepl-mode-hook 'paredit-mode)
(global-set-key [f7] 'paredit-mode)

;; theme
(load-theme 'noctilux t)

;; clojure-mode
(global-set-key [f9] 'cider-jack-in)
(add-hook 'clojure-mode-hook 'turn-on-eldoc-mode)

;; nrepl
(add-hook 'nrepl-interaction-mode-hook 'nrepl-turn-on-eldoc-mode)
(setq nrepl-popup-stacktraces nil)
(add-to-list 'same-window-buffer-names "*nrepl*")
(add-hook 'nrepl-mode-hook 'paredit-mode)

;; Auto complete
(require 'auto-complete-config)
;(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(setq ac-delay 0.0)
;(setq ac-use-quick-help t)
(setq ac-quick-help-delay 0.0)
;(setq ac-use-fuzzy 1)
;(setq ac-auto-start 1)
;(setq ac-auto-show-menu 1)
(ac-config-default)

;; ac-nrepl
(require 'ac-nrepl)
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)
(eval-after-load "auto-complete" '(add-to-list 'ac-modes 'nrepl-mode))


(defun set-auto-complete-as-completion-at-point-function ()
  (setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)

(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)


;; scroll one line at a time (less "jumpy" than defaults)

(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time

(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling

(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse

(setq scroll-step 1) ;; keyboard scroll one line at a time

根据@ syohex的评论更新

以下是我在CLJ缓冲区中看到的内容:

CLJ buffer popup

在NREPL中,我确实看到了" v"而不是" d" (顺便说一下,这些字母意味着什么?)。正如我在评论中所说,在NREPL中,我确实看到黄色框出现,然后当弹出窗口出现时,然后文档黄色框消失。在CLJ代码缓冲区中,黄色框永远不会打开。

最终更新

经过一些更多的测试,一切都按预期工作。当弹出窗口首次显示时,黄色框消失。但是,当我开始选择不同的选择时,它会重新出现在正确的位置。

此外,它开始在CLJ缓冲区工作,我看到了字母" v"而不是" d"正如上面的sreenshot中所见。也许我忘了启动NREPL,必须重新测试。

无论如何,一切都按预期工作。

4 个答案:

答案 0 :(得分:3)

实际上不推荐使用此配置和前ac-nrepl,请参阅新包ac-cider

(require 'ac-cider)
(add-hook 'cider-mode-hook 'ac-flyspell-workaround)
(add-hook 'cider-mode-hook 'ac-cider-setup)
(add-hook 'cider-repl-mode-hook 'ac-cider-setup)
(eval-after-load "auto-complete"
    '(add-to-list 'ac-modes 'cider-mode))

答案 1 :(得分:2)

nrepl-mode-hooknrepl-interaction-mode-hooknrepl-mode已废弃。您应该分别使用cider-mode-hookcider-repl-mode-hookcider-mode代替它们。

您应该将ac-quick-help-delay设置为超过0的值(例如0.5)。 补丁在下面。

--- nconf-orig.el   2014-05-21 16:51:40.056185465 +0900
+++ conf-new.el 2014-05-21 16:53:11.936182181 +0900
@@ -43,7 +43,7 @@
 ;(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
 (setq ac-delay 0.0)
 ;(setq ac-use-quick-help t)
-(setq ac-quick-help-delay 0.0)
+(setq ac-quick-help-delay 0.5)
 ;(setq ac-use-fuzzy 1)
 ;(setq ac-auto-start 1)
 ;(setq ac-auto-show-menu 1)
@@ -51,9 +51,10 @@

 ;; ac-nrepl
 (require 'ac-nrepl)
-(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)
-(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)
-(eval-after-load "auto-complete" '(add-to-list 'ac-modes 'nrepl-mode))
+(add-hook 'cider-mode-hook 'ac-nrepl-setup)
+(add-hook 'cider-repl-mode-hook 'ac-nrepl-setup)
+(add-to-list 'ac-modes 'cider-mode)
+(add-to-list 'ac-modes 'cider-repl-mode)


 (defun set-auto-complete-as-completion-at-point-function ()

答案 2 :(得分:0)

  

首先出现黄色框,然后弹出自动完成时   出现了,黄色的方框文件消失了。

此行为是由(setq ac-quick-help-delay 0.5)引起的,因为0.5秒太快

将0.5更改为更大的数字(我的计算机上工作的最小值为0.9,但这可能取决于计算机的性能)或 删除(setq ac-quick-help-delay 0.5)由于这将使用默认值:大约2.5秒,它可以解决问题。

答案 3 :(得分:0)

我正在2020年查看此内容,ac-cider已过时,但您可以改用company-mode

使用M-x package-install company安装并按照cider docs对其进行配置,以用于cider-repl-modecider-mode