Auto complete lines by grepping the project.
Screenshot:
For example, a web developer need create a new component instance.
Suppose the component is 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-multiline
.
Place eacl.el
under your Load Path. Then add (require 'eacl)
to your configuration.
It’s also possible to use melpa.
git grep
is automatically detected for completion if possible. Or else default grep is used.
To use git grep
, Git should be added into environment variable “PATH”.
The command line program of grep and git need be added into environment variable “PATH”. Or else you need set eacl-grep-program
and eacl-git-program
to specify their path.
M-x eacl-complete-line
completes single line. Line candidates are extracted from the project root.
M-x eacl-complete-multiline
completes multiline code or html tag in project
C-u M-x eacl-complete-line
completes single line from deleted code if current project is tracked by Git.
The keyword to grep is the text from the line beginning to current cursor.
Whitespace in keyword matches any characters.
The project root 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")
M-x eacl-complete-line-from-buffer
to complete single line from the buffers. Set eacl-ignore-buffers
and eacl-include-buffers
to specify ignored&included buffers.
M-x eacl-complete-line-from-buffer-or-project
completes single line by grepping the project root when editing a physical file. Or else, it searches all buffers for line completion.
Modify grep-find-ignored-directories
and grep-find-ignored-files
to setup directories and files grep should ignore:
(with-eval-after-load 'grep
(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.
Sample 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)))))))
git grep
is automatically used for grepping in git repository.
Please note git grep
does NOT use grep-find-ignored-directories
OR grep-find-ignored-files
. You could set eacl-git-grep-untracked
to tell
git whether untracked files should be grepped in the repository.
Check https://github.com/redguardtoo/eacl.