我想在 emacs 中开发 java。我安装了 ecb、jde 和自动完成扩展。每一个都运行良好,而无需启动其他。但是当我想一起使用它们时,发生了一些问题。

  • 自动完成模式不使用 jde 自动启动,我需要通过 M-x 自动完成模式启动它。如果没有 jde,自动完成模式将自动启动
  • 当我在 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
    

    最佳答案

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

    (push 'jde-mode ac-modes)
    

    然后您需要向 ac-sources 添加一个 JDEE 特定的源代码。我不确定 JDEE 与 Semantic 的集成程度,您可以使用预定义的源代码:
    (add-hook 'jde-mode-hook (lambda () (push 'ac-source-semantic ac-sources)))
    

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

    关于emacs 自动完成功能不适用于 jde,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11715296/

    10-17 02:30