Here's the snippet in init.el
(use-package ac-html
:ensure t
:init
(progn
(ac-config-default)
(auto-complete-mode t))
I installed the package and it still won't auto complete
Related
I am trying to set up the emacs to have auto-Indentation for clojure code.
Until now unsuccessful. What is the command to set into the config file for that?
Here is a sample emacs config for what i consider the "minimal" usable emacs config for Clojure. I say minimal in that I'm not willing to work without good code completion, jump to definition, project aware file handling etc:
from this example which you can clone to ~/.emacs.d:
This is just a hilight, see the init file in the example project for the context, look at the project for recent versions, etc. don't just copy these:
(use-package clojure-mode
:ensure t
:config
(add-hook 'clojure-mode-hook 'yas-minor-mode))
(use-package cider
:ensure t
:config (progn (add-hook 'clojure-mode-hook 'cider-mode)
(add-hook 'clojure-mode-hook 'cider-turn-on-eldoc-mode)
(add-hook 'cider-repl-mode-hook 'subword-mode)
(setq cider-annotate-completion-candidates t
cider-prompt-for-symbol nil)))
;; clojure refactor library
;; https://github.com/clojure-emacs/clj-refactor.el
(use-package clj-refactor
:ensure t
:config (progn (setq cljr-suppress-middleware-warnings t)
(add-hook 'clojure-mode-hook (lambda ()
(clj-refactor-mode 1)
(cljr-add-keybindings-with-prefix "C-c C-m")))))
there is also some code to add to ~/.lein/profiles.clj:
{:user {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]
[refactor-nrepl "1.1.0"]]
:dependencies [[acyclic/squiggly-clojure "0.1.3-SNAPSHOT"]]}}
I added
(global-set-key (kbd "RET") 'newline-and-indent)
to the init file and this worked. I am not sure if this was the best solutaion, but it did the trick.
I'm brand-new to both Emacs and Clojure and would like to set up hinting and syntax highlighting somehow similar to the video here. I have installed:
Emacs 24.x
Leiningen 2.x
Marmalade
...Then within Emacs and via Marmalade, installed the following packages:
Evil
clojure-mode
nrepl
My big-idea question is how do these major/minor modes interact and is there a "right" way to set these things up?
My smaller-idea question is how do I get the pretty syntax highlighting and code-hinting?
Thanks!
Check out Emacs Live, its a full emacs configuration created by Sam Aaron. He codes allot of Clojure so this "battery included" setup works great for Clojure coding.
https://github.com/overtone/emacs-live
Once you have cloned this and follow the instructions you are up and running with
Clojure, nrepl, git and much more.
I list my setup. Some of the stuff is redundant, since I haven't
written in Clojure for a while, but I checked and it still works.
Use clojure to start nrepl.
You might have some issue with project.clj being in the appropriate directory,
but you should figure this out.
Open a source file e.g. foo.clj.
Use C-c C-l to call nrepl-load-file
By the way, it's the canonical shortcut to load the file into inferior process.
It will work for Common Lisp, Python etc.
Use C-c C-z to switch to repl.
This again is the canonical shortcut that works for many languages.
Here's the setup code:
(require 'clojure-mode)
(defun set-syntax-parens ()
"highlight []{} etc."
(interactive)
(modify-syntax-entry ?[ "(]")
(modify-syntax-entry ?] ")[")
(modify-syntax-entry ?{ "(}")
(modify-syntax-entry ?} "){"))
(defvar clojure.jars '("clojure-1.3.0.jar"
"swank-clojure-1.4.2.jar"
"clojure-contrib-1.2.0.jar"))
(defvar clojure.jars.d (concat dropbox.d "source/clojure/lib/"))
(defvar clojure.classpath
(apply #'concat
(mapcar (lambda (jar) (concat clojure.jars.d jar path-separator))
clojure.jars)))
(setq clojure.classpath
(concat clojure.classpath
dropbox.d "source/clojure/include/"
path-separator))
;;;###autoload
(defun clojure ()
(interactive)
(nrepl-jack-in))
(defvar clojure-server-cmd
(concat "java -Xss4096k -cp " clojure.classpath " clojure.main &"))
(add-hook 'clojure-mode-hook
(lambda()
(set-syntax-parens)))
(require 'nrepl)
(add-hook 'nrepl-mode-hook
(lambda()
(define-key nrepl-mode-map (kbd "C-l") 'nrepl-clear-buffer)))
here is the operative section from my favorite emacs config:
(when (not package-archive-contents)
(package-refresh-contents))
;; Add in your own as you wish:
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings clojure-mode
nrepl auto-complete ac-nrepl org rainbow-delimiters)
"A list of packages to ensure are installed at launch.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
(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 'nrepl-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)
(define-key nrepl-interaction-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc)
(add-hook 'prog-mode-hook 'auto-complete-mode)
(add-hook 'nrepl-interaction-mode-hook
'nrepl-turn-on-eldoc-mode)
(add-hook 'nrepl-mode-hook 'paredit-mode)
This turns on paredit-mode everywhere, which takes a bit of getting used to though it's entirely worth it because paredit and makes using Clojure much more fun. At least once you get a handle on slurping and barfing
I want to make the yasnippet as the backend of the auto-complete. However, it doesn't work. what I do after searched the internet is as follows:
get the auto-complete-yasnippet.el, add some elisp in the .emacs like this:
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
(yas-minor-mode nil)
(global-set-key (kbd "M-/") 'yas/expand)
;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
;;setup for auto-complete-yasnippet
(require 'auto-complete-yasnippet)
(setq-default ac-sources
'(
;; ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
;; ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename
)
)
I look at the content in the ac-sources in *scratch* with C-h v, and it does have the ac-source-yasnippet. someone said that there may be something wrong with the version and upgrade of auto-complete as well as yasnippet. How can it be fixed?
My emacs version is 23.3.1 my auto-complete version is 1.3.1 and my yasnippet version is 0.8.0(beta) which is just downloaded from the github. any help?
you can easily do it by (require 'auto-complete-yasnippet)
and then you can change your auto-complete like follows:
(defun my-ac-config ()
(setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
;; (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
(add-hook 'css-mode-hook 'ac-css-mode-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
(add-hook 'octave-mode-hook 'ac-octave-mode-setup)
(global-auto-complete-mode t))
(defun my-ac-cc-mode-setup ()
(setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; ac-source-gtags
(my-ac-config)
It works fine on my machine.
there maybe something wrong with the auto-complete-config.el when acquire the ac-yasnippet-candidates in the auto-complete-1.3.1 version:
(defun ac-yasnippet-candidates ()
(with-no-warnings
(if (fboundp 'yas/get-snippet-tables)
;; >0.6.0
(apply 'append (mapcar 'ac-yasnippet-candidate-1 (yas/get-snippet-tables major-mode)))
(let ((table
(if (fboundp 'yas/snippet-table)
;; <0.6.0
(yas/snippet-table major-mode)
;; 0.6.0
(yas/current-snippet-table))))
(if table
(ac-yasnippet-candidate-1 table))))))
the code snippet above somewhat must be changed to be compatible with the yasnippet-0.8.0version. I download the newest version of auto-complete-1.4.0 from github and it solved the problem judge the version of yasnippet and take measures accordingly. Like this:
(defun ac-yasnippet-candidates ()
(with-no-warnings
(cond (;; 0.8 onwards
(fboundp 'yas-active-keys)
(all-completions ac-prefix (yas-active-keys)))
(;; >0.6.0
(fboundp 'yas/get-snippet-tables)
(apply 'append (mapcar 'ac-yasnippet-candidate-1
(condition-case nil
(yas/get-snippet-tables major-mode)
(wrong-number-of-arguments
(yas/get-snippet-tables))))))
(t
(let ((table
(if (fboundp 'yas/snippet-table)
;; <0.6.0
(yas/snippet-table major-mode)
;; 0.6.0
(yas/current-snippet-table))))
(if table
(ac-yasnippet-candidate-1 table)))))))
I copied the auto-complete-config.el from the auto-complete-1.4.0version, byte compiled it, and replaced the same files(both auto-complete-config.el and auto-complete-config.elc) in auto-complete-1.3.1version. it just worked! I think may the config file of auto-complete should not included in the distro and maybe it should maintained separately to make it easy to compatible with its backends.
I reconfigured the yasnippet and the auto-complete like this:
;; setup for yasnippet
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
;; Extension and configuration of yasnippet.
(require 'yasnippet-config)
;; If you use yasnippet from 'auto-complete', add
(yas/set-ac-modes)
(yas/enable-emacs-lisp-paren-hack)
;; before 'auto-complete' settings.
;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
New with emacs. I'm not able to implement auto-completion for Gtk+3. I'm using CEDET and Auto Complete Mode as UI. Semantic is unable to find include files ( ), but it can parse the tags of the code in the open buffers.
Here my .emacs conf
;;----------------------------------------------------------------------------------
(load-file "~/.emacs.d/cedet-1.0/common/cedet.el")
(global-ede-mode 1)
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)
;; ede customization
(require 'semantic-lex-spp)
(ede-enable-generic-projects)
(setq senator-minor-mode-name "SN")
(setq semantic-imenu-auto-rebuild-directory-indexes nil)
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)
(require 'semantic-decorate-include)
;; gcc setup
(require 'semantic-gcc)
;; smart completions
(require 'semantic-ia)
(setq-mode-local c-mode semanticdb-find-default-throttle
'(project unloaded system recursive))
(setq-mode-local c++-mode semanticdb-find-default-throttle
'(project unloaded system recursive))
(setq-mode-local erlang-mode semanticdb-find-default-throttle
'(project unloaded system recursive))
(require 'eassist)
(require 'semanticdb)
(global-semanticdb-minor-mode 1)
;; gnu global support
(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)
;; ctags
(require 'semanticdb-ectag)
;;(semantic-load-enable-primary-exuberent-ctags-support)
(global-semantic-tag-folding-mode)
(defun my-cedet-hook ()
(local-set-key [(control return)] 'semantic-ia-complete-symbol)
(local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
(local-set-key "\C-c>" 'semantic-complete-analyze-inline)
(local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
;;semantic gtk gdk
(defun my-semantic-hook ()
(semantic-add-system-include "/usr/include/gtk-3.0/gtk/" 'c-mode)
(semantic-add-system-include "/usr/include/gtk-3.0/gdk/" 'c-mode))
(add-hook 'semantic-init-hooks 'my-semantic-hook)
;; END CEDET
;;----------------------------------------------------------------------------
Any suggestions? Thanks.
Your setup looks OK to me; I wonder if the extra "gtk/" and "gdk/" in your add-system-includes might be the problem. I just got this working with gtk-3.0 using:
(semantic-add-system-include "/usr/include/gtk-3.0" 'c-mode)
Then in your source file,
#include <gtk/gtk.h>
Followed by:
gtk_[C-c ?]
spends a minute or so processing all the header files, but it does return the completion menu as expected.
If this doesn't work for you, I notice you might be using an older version of CEDET. I use the latest dev version from the bazaar repository; I highly recommend you do the same.
I use Emacs 24 from scratch with the latest yasnippet and auto-complete installed and nominally working. Now, as a emacs user and an android developer, I'd like to use my favorite editor and automate some tasks fr android development.
I know almost nothing about elisp.
My first task is to use custom snippets to add the uses-sdk tag in AndroidManifest.xml. That's ok with yasnippet but I'd like to use auto-complete to interactively propose and auto-complete android specific tags. The problem is that the major mode for AndroidManifest.xml is nxml and I don't want to propose android specifics to all nxml-mode related buffers. As a consequence, I use a condition on the buffer name in the snippet definition. Now, I'd like to add a custom hook to nxml-mode-hook but I failed to enable the auto-complete mode.
My snippet:
#contributor : Me, Myself and I
#name : <uses-sdk ... />
#condition : (string= (buffer-name) "AndroidManifest.xml")
# --
<uses-sdk android:minSdkVersion="$0" />
The .emacs part that miserably failed:
;; yasnippet
(add-to-list 'load-path "~/.emacs.d/yasnippet")
(require 'yasnippet)
(setq yas/trigger-key (kbd "C-c <kp-multiply>"))
(yas/initialize)
;; Develop in ~/emacs.d/mysnippets, but also
;; try out snippets in ~/Downloads/interesting-snippets
(setq yas/root-directory '("~/.emacs.d/snippets"
"~/.emacs.d/external-snippets"))
;; Map `yas/load-directory' to every element
(mapc 'yas/load-directory yas/root-directory)
;; auto-complete
(add-to-list 'load-path "~/.emacs.d/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/ac-dict")
(setq-default ac-sources '(ac-source-yasnippet ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
(add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
(add-hook 'css-mode-hook 'ac-css-mode-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
(global-auto-complete-mode t)
;; android specific settings
;; AndroidManifest.xml
(defun ac-android-manifest-nxml-setup()
""
(when (string= (buffer-name) "AndroidManifest.xml")
(setq ac-sources '(ac-source-yasnippet ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))))
(add-hook 'nxml-mode-hook 'ac-android-manifest-nxml-setup)
The snippet works as intended but the completion don't though the auto-completion works if I enable auto-complete using M-x auto-complete-mode.
Any help will be greatly appreciated.
Works well with
;; auto-complete
(add-to-list 'load-path "~/.emacs.d/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/ac-dict")
(ac-config-default)
;; android specific settings
;; AndroidManifest.xml
(defun ac-android-manifest-nxml-setup()
(when (string= (buffer-name) "AndroidManifest.xml")
(setq ac-sources '(ac-source-yasnippet
ac-source-abbrev
ac-source-dictionary
ac-source-words-in-same-mode-buffers))
((lambda () (auto-complete-mode 1)))))
(add-hook 'nxml-mode-hook 'ac-android-manifest-nxml-setup)