eacl - Emacs auto complete line(s) v1.0.3
Auto complete line(s) by grepping the project.
Screenshot:
For example, a web developer need create a new component instance.
Suppose the component has been used in current project before:
<MyComponent
attr1="v1"
attr2="v2"
attr3="v3"
attr4="v4"
/>
<Toolbar>
<Button onClick={ e => console.log(e) }>
<i className="fa fa-circle" />
</Button>
</Toolbar>
</MyComponent>The developer only need input <MyComponent and run M-x eacl-complete-tag. Then Magic happens!*
Install
Place eacl.el under your Load Path. Then add (require 'eacl) to your configuration.
GNU Grep, Emacs v24.3, and Ivy are required.
Linux
GNU Grep should be pre-installed.
macOS
Please use HomeBrew to install GNU Grep on macOS.
Then insert (setq eacl-grep-program "ggrep") into ~/.emacs. The bundled BSD Grep on macOS is too outdated to use.
Windows
You can use Cygwin/MSYS2 to install grep program. Don’t forget to add the location of grep into environment variable PATH.
Usage
Multiple commands are provided to grep files in the project to get auto complete candidates.
The keyword to grep is the text from line beginning to current cursor.
Project is automatically detected if Git/Mercurial/Subversion is used.
You can override the default root directory by setting eacl-project-root,
(setq eacl-project-root "~/projs/PROJECT_DIR")Here are the commands you can use.
M-x eacl-complete-line
Complete the line. You could assign key binding C-x C-l to it.
M-x eacl-complete-statement
Complete the statement which ends with “;”.
For example, input text import and run this command.
M-x eacl-complete-snippet
Complete the snippet which ends with “}”.
For example, input text if and run this command.
M-x eacl-complete-tag
Complete the HTML tag which ends with “>”.
For example, input text <div and run this command.
Tips
Directories and files grep should ignore
Modify grep-find-ignored-directories and grep-find-ignored-files to setup directories and files grep should ignore:
(eval-after-load 'grep
'(progn
(dolist (v '("node_modules"
"bower_components"
".sass_cache"
".cache"
".npm"))
(add-to-list 'grep-find-ignored-directories v))
(dolist (v '("*.min.js"
"*.bundle.js"
"*.min.css"
"*.json"
"*.log"))
(add-to-list 'grep-find-ignored-files v))))Or you can setup above ignore options in .dir-locals.el.
The content of “.dir-locals.el”,
((nil . ((eval . (progn
(dolist (v '("node_modules"
"bower_components"
".sass_cache"
".cache"
".npm"))
(add-to-list 'grep-find-ignored-directories v))
(dolist (v '("*.min.js"
"*.bundle.js"
"*.min.css"
"*.json"
"*.log"))
(add-to-list 'grep-find-ignored-files v)))))))