Emacs + clojure. Autocomplete data from all source files in the project

I have been developing C # applications for a long time. Commercial IDEs and tools provide extremely good code completion features. Now I am learning clojure and I am really missing a familiar workflow.

So, about emacs. I installed nrepl, ac-nrepl and clojure -mode. Auto completion works fine in repl. It also works for characters in the current buffer. But not for:

  • characters from other project files
  • external libraries (managed by leiningen).

Is there any existing package that fully covers cases 1 and 2?

My clojure related config:

;;;;;;;;;;;;;;; ;;; clojure ;;; ;;;;;;;;;;;;;;; (require 'nrepl) ;; Configure nrepl.el (setq nrepl-hide-special-buffers t) (setq nrepl-popup-stacktraces-in-repl t) (setq nrepl-history-file "~/.emacs.d/nrepl-history") ;; Some default eldoc facilities (add-hook 'nrepl-connected-hook (defun pnh-clojure-mode-eldoc-hook () (add-hook 'clojure-mode-hook 'turn-on-eldoc-mode) (add-hook 'nrepl-interaction-mode-hook 'nrepl-turn-on-eldoc-mode) (nrepl-enable-on-existing-clojure-buffers))) ;; Repl mode hook (add-hook 'nrepl-mode-hook 'subword-mode) ;; Auto completion for NREPL (require 'ac-nrepl) (eval-after-load "auto-complete" '(add-to-list 'ac-modes 'nrepl-mode)) (add-hook 'nrepl-mode-hook 'ac-nrepl-setup) (add-hook 'clojure-nrepl-mode-hook 'ac-nrepl-setup) (define-key clojure-mode-map (kbd "C-<ret>") 'nrepl-eval-expression-at-point) ;(global-set-key (kbd "C-<ret>") 'nrepl-eval-expression-at-point) ;;;;;;;;;;;;;;;;;;;;; ;;; 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.05) (setq ac-use-fuzzy 1) (setq ac-auto-start 1) (setq ac-auto-show-menu 1) (ac-config-default) (define-key ac-mode-map (kbd "C-SPC") 'auto-complete) 
+4
source share
3 answers

After installing the new nrepl and ac-nrepl, this is what I put into .emacs

 (package-initialize) (require 'auto-complete) (global-auto-complete-mode) (add-hook 'nrepl-mode-hook 'ac-nrepl-setup) (add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup) (add-hook 'clojure-nrepl-mode-hook 'ac-nrepl-setup) 

When I now nrepl-jack-in into a test project and open its file, I have tab completion in each namespace that is currently being loaded into the project. Looks like you forgot 'ac-nrepl-setup on 'nrepl-interaction-mode-hook .

+8
source

autocomplete should be available for all open clojure files, but now I can’t say that this can be done from the project and libraries. This could potentially be done using Semantic (from CEDET), but right now there is no parsing for clojure code.

I started working on Leiningen support in EDE (part related to the CEDET project). Some code exists in the CEDET repository, or you can look at my CEDET repository at https://github.com/alexott/cedet/tree/devel (I plan to merge it back into CEDET after a while)

+2
source
 (require 'auto-complete-config) (require 'clojure-mode) (require 'cider-mode) (require 'ac-cider) (ac-config-default) ;(add-hook 'cider-repl-mode-hook 'ac-cider-setup) (add-hook 'cider-mode-hook 'ac-cider-setup) (eval-after-load "auto-complete" '(add-to-list 'ac-modes 'cider-repl-mode)) (add-hook 'clojure-mode-hook 'paredit-mode) ;(add-hook 'clojurescript-mode-hook 'paredit-mode) (add-hook 'clojure-mode-hook 'rainbow-delimiters-mode) (setq cider-repl-pop-to-buffer-on-connect nil) (require 'highlight-parentheses) (add-hook 'clojure-mode-hook (lambda () (highlight-parentheses-mode t))) (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) (eval-after-load "cider" '(define-key cider-mode-map (kbd "Cc Cd") 'ac-cider-popup-doc)) 

This is my init.el file. The list of my packages contains: clojure -mode cider paredit autofill auto-indent mode highlight brackets as-cider pop-up

You may need at least ac-cider, cider, clojure mod, autocomplete, pop-up for autocomplete function!

** After installing and installing the init.el file, Create a Clojure project using Lein. (It does not work only with the .clj file, it works only with the Leiningen project.) Add

 :plugins [[cider/cider-nrepl "0.8.2"]] 

to the project.clj file, then open the source file and run: **

 Mx cider-jack-in 

Then you should be able to use autocomplete using an ac-sider.

+1
source

Source: https://habr.com/ru/post/1497300/


All Articles