2

I really want to use emacs as a Javascript IDE. I have followed all the directions I can, includings Yasnippets and Autocomplete, but I still have some issues.

If you look at the differences, in Jedi the auto-completion and pop-up window appears almost right away in Python files. In my javascript, the only words that appear for autocorrect are those that previously appear (and they are not in a drop-down window) not even function (see attached). enter image description here

enter image description here

I have loaded external libraries and it looks like everything works, does any body have advice here?

Here is my .emacs

;; js2 mode                                                                                                                                                                     
(add-hook 'js-mode-hook 'js2-minor-mode)                                                                                                                                        
(add-hook 'js-mode-hook 'ac-js2-mode)                                                                                                                                           
(setq js2-highlight-level 3)                                                                                                                                                    
(add-to-list 'auto-mode-alist (cons (rx ".js" eos) 'js2-mode))                                                                                                                  
(add-to-list 'auto-mode-alist '("\\.json$" . js2-mode)) 

;; yasnippit                                                                                                                                                                    
;; load before auto complete                                                                                                                                                    
(require 'yasnippet)                                                                                                                                                            
(setq yas-snippet-dirs                                                                                                                                                          
      '("~/.emacs.d/snippets/javascript-mode"                                                                                                                                   
        "~/.emacs.d/snippets/js-yasnippets"                                                                                                                                     
      ))                                                                                                                                                                        
(yas-global-mode 1)                                                                                                                                                             


;; autocomplete mode                                                                                                                                                            
(require 'auto-complete-config)                                                                                                                                                 
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")                                                                                                                   
(add-to-list 'ac-sources 'ac-source-yasnippet)                                                                                                                                  
(ac-config-default)                                                                                                                                                             
(ac-set-trigger-key "TAB")                                                                                                                                                      
(ac-set-trigger-key "<tab>")                                                                                                                                                    

;; use spaces instead of tabs                                                                                                                                                   
(setq-default indent-tabs-mode nil) 
5

That is because jedi is a Python library that statically analyzes Python code to suggest completion candidates. Installing the jedi.el package enabled its abilities for auto-complete-mode and extended them beyond the suggestion of already used words and predefined ones.

If you wish to have the same experience with Javascript, you will either need to find a similiarly powerful backend like tern.js and install an Emacs package for it or alternatively could check whether your major mode supports completion suggestions (by hitting M-TAB after typing a word partially) and enable these in auto-complete-mode with the ac-capf package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.