【问题标题】:emacs auto-complete don't work with jdeemacs 自动完成功能不适用于 jde
【发布时间】:2012-07-27 18:06:57
【问题描述】:

我想用emacs开发java。我安装了 ecb、jde 和自动完成扩展。在不启动其他人的情况下,每个人都可以很好地工作。但是当我想一起使用它们时,发生了一些问题。

  1. auto-complete-mode 不能用 jde 自动启动,我需要用 M-x auto-complete-mode 启动它。如果没有 jde,自动完成模式将自动启动
  2. 当我在 jde 中手动启动自动完成模式时,自动完成无法正常工作。它只是自动完成出现的单词。

这是我的 .emacs 内容:

(global-linum-mode 1)
(setq linum-format "%2d| ")

(setq default-tab-width 4)

(setq debug-on-error t)

;;no backup file
(setq make-backup-files nil)

(setq debug-on-error t)

;;auto complete config
(add-to-list 'load-path "D:/emacs-24.1/custom_el/auto-complete-1.3.1")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "D:/emacs-24.1/custom_el/auto-complete-1.3.1/dict")
(ac-config-default)

(setq stack-trace-on-error t)

(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/jdee-2.4.0.1/lisp"))
(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/cedet-1.1/common"))
(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/elib-1.0"))

(add-to-list 'load-path'  "d:/emacs-24.1/custom_el/ecb-2.40")


;; Initialize CEDET.
(load-file (expand-file-name "D:/emacs-24.1/custom_el/cedet-1.1/common/cedet.el"))
(load-file (expand-file-name "D:/emacs-24.1/custom_el/ecb-2.40/ecb.el"))


(require 'ecb)
(ecb-activate)
(ecb-byte-compile)


;; If you want Emacs to defer loading the JDE until you open a 
;; Java file, edit the following line
(setq defer-loading-jde nil)
;; to read:
;;
;;  (setq defer-loading-jde t)
;;

(if defer-loading-jde
    (progn
      (autoload 'jde-mode "jde" "JDE mode." t)
      (setq auto-mode-alist
        (append
         '(("\\.java\\'" . jde-mode))
         auto-mode-alist)))
 (require 'jde))


;; Sets the basic indentation for Java source files
;; to two spaces.
(defun my-jde-mode-hook ()
  (setq c-basic-offset 2))

(add-hook 'jde-mode-hook 'my-jde-mode-hook)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ecb-options-version "2.40")
 '(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

版本信息是:

emacs : 24.1
auto complete : 1.3.1
ecb : 2.40
cedet : 1.1
elib : 1.0
jdee : 2.4.0.1

【问题讨论】:

  • 例如:如果我先输入'public',自动补全什么也不做,但是当我输入'public'后,它可以自动补全'public'。并且没有 jdee 自动完成工作很好

标签: emacs autocomplete


【解决方案1】:

要使用jde-mode 自动启动auto-complete-mode,您需要将jde-mode 添加到ac-modes

(push 'jde-mode ac-modes)

然后您需要将 JDEE 特定的源添加到 ac-sources。我不确定 JDEE 与 Semantic 集成的程度,您也许可以使用它的预定义源:

(add-hook 'jde-mode-hook (lambda () (push 'ac-source-semantic ac-sources)))

如果没有,您可能需要使用ac-define-source 定义专用源。有关示例,请参阅auto-complete-config.el

【讨论】:

  • 很好,第一个问题解决了。但是第二个还是不行。
  • 第二个问题已经解决了。如果我启动 jde,模式将是 jde-mode。但是自动完成不知道 jde 模式。所以,我只是把java-mode的名字改成jde-mode..^_^
  • 我不明白。你在哪里将java-mode 更改为jde-mode
  • 在 autocomplete/dict 目录下,你会找到一个名为“java-mode”的文件。我只是将其更改为“jde-mode”。当我用jde打开一个java文件时,emcas的主要模式是jde-mode,我猜autocompele会根据主要模式改变dict,所以我试了一下,自动完成效果很好。我不知道真正的原因,所以如果你知道,请告诉我!!
  • 啊,我明白了。您已经启用了基于字典的补全,而这正是实现它的方法。我正在考虑上下文相关的完成,如下所述:jdee.sourceforge.net/jdedoc/html/jde-ug/…
猜你喜欢
  • 2013-03-17
  • 2014-12-04
  • 2018-01-13
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
相关资源
最近更新 更多