Skip to content

baohaojun/bbyac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bit Bang! Yet Another Completion

Say you have a very-very-long-emacs-lisp-variable-name, you need only type vvn and press a shortcut key (M-s <return>), it will be completed into that long name. Or you can type vln if you like that better.

You can type the bit that you like better, or is easier to remember, or is easier to type.

Usage

  1. Install browse-kill-ring.
  2. (require 'bbyac)
  3. (bbyac-global-mode 1)
  4. Type a little bit and press M-g <return> to complete a word or M-s <return> to complete an arbitrary string.

For more detailed discussion, see this github page (bbyac used to be name skeleton-complete.el, but I have renamed it to avoid confusion with skeleton.el).

The Gory Details

Bbyac has several flavors of completion: the most usefull two being single word completion and arbitrary string completion, which is like hippie-expand’s try-expand-dabbrev and try-expand-line.

To taste the single word flavor, say in an emacs-lisp buffer, you have a long variable name, this-is-a-very-long-var-name, and a long function name, this-is-a-very-long-function-name, to reproduce the first name, you can simply type tvv, and press M-g <return>; or tvf and M-g <return> for the second. You don’t need selecte from the 2 names. Compare this to try-expand-dabbrev, where you will need type this-is-, i.e., you MUST start typing from the start without skipping any characters. And then you hit M-/, but you may NEED select from the 2 names by pressing M-/ again (and again if there is this-is-a-second-very-long-name 😁). When you do need to select from multiple completions, bbyac will sort them according to their distance to the point approximately, and use ecomplete or browse-kill-ring to let you select them:

http://baohaojun.github.io/images/bbyac-completion-select.png

For the arbitrary string flavor, in the buffer I’m editting this readme, I can type (') and M-s <return> to reproduce the following expression (compare this to try-expand-line) :

(require 'bbyac)

You can consider it as abbrev-mode or yasnippet on the go, with no need to prepare the long completion with a template.

The Algorithm

You can take a look at the source code. But here’s a simplified explanation:

  1. You type vvn
  2. Bbyac rewrite it as a regexp: v.*?v.*?n or \bv.*?v.*?n according to the flavor.
  3. Bbyac search the regexp in the current buffer (and some other buffers, which you are referred to the code) according to the flavor you are using.
  4. All matching words/strings are collected into a list
  5. The list is sorted
  6. If only one match in the list, complete it; or else display them for selection.

Bugs/Limitations

If there are very long strings in the buffer, the regexp may become too complex to search and take a long time. You need press C-g😭.

To wordly complete HelloWorld, you can type eW. But to stringly complete HelloWorld, eW won’t match it, because it will be rewritten as \be.*?W. This is to reduce the number of arbitrary string matches. You must start the bit with h or H to string complete HelloWorld.

Thanks

Thank wuhaochi from NewSmth BBS’s Emacs board (best Chinese Emacs forum) for suggesting the very useful arbitrary string flavor when I posted about the single word flavor there.

Thank Matus Goljer (author of smartparens) for teaching me a lot on emacs lisp programming (see the issues of skeleton-complete).

Thank the browse-kill-ring project for providing me a much better way for selecting from multiple completions.

About

For when 'M-/ M-/ M-/ C-/' gets you down

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •