eacl icon indicating copy to clipboard operation
eacl copied to clipboard

eacl - Emacs auto complete lines by grepping project

  • eacl - Emacs auto complete lines

[[https://github.com/redguardtoo/eacl/actions/workflows/test.yml][https://github.com/redguardtoo/eacl/actions/workflows/test.yml/badge.svg]] [[http://melpa.org/#/eacl][file:http://melpa.org/packages/eacl-badge.svg]] [[http://stable.melpa.org/#/eacl][file:http://stable.melpa.org/packages/eacl-badge.svg]]

Auto complete lines by grepping the project.

Screenshot:

[[https://raw.githubusercontent.com/redguardtoo/eacl/master/eacl-demo.gif]]

For example, a web developer need create a new component instance.

Suppose the component is used in current project before: #+begin_src html <MyComponent attr1="v1" attr2="v2" attr3="v3" attr4="v4" /> <Toolbar> <Button onClick={ e => console.log(e) }> <i className="fa fa-circle" /> </Button> </Toolbar> </MyComponent> #+end_src

The developer only need input =<MyComponent= and run =M-x eacl-complete-multiline=.

  • Install Place =eacl.el= under your [[https://www.emacswiki.org/emacs/LoadPath][Load Path]]. Then add =(require 'eacl)= to your configuration.

It's also possible to use [[http://melpa.org][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.

  • Usage =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=, #+begin_src elisp (setq eacl-project-root "~/projs/PROJECT_DIR") #+end_src

=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.

  • Tips ** Directories and files to ignore Modify =grep-find-ignored-directories= and =grep-find-ignored-files= to setup directories and files grep should ignore: #+begin_src elisp (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))) #+end_src

Or you can setup above ignore options in [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html][.dir-locals.el]].

Sample of =.dir-locals.el=, #+begin_src elisp ((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))))))) #+end_src

=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.

  • Bug Report Check [[https://github.com/redguardtoo/eacl]].