minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
573 stars 20 forks source link

Improving cape-char #90

Closed hedyhli closed 9 months ago

hedyhli commented 10 months ago

Hi @minad, first of all thanks a bunch for this amazing package as well as your other (even more popular) packages for emacs!

TLDR

here are my suggestions

Long description

Background and motivation

The other day I tried to use company-math and company-emoji using the cape adapter, but 1) it didn't really work well and 2) company as a dependency is also installed. I didn't want to have company installed when I'm already using Corfu.

After digging into how company math and company emoji works under the hood, I realized Cape and these two packages have an area of intersection: the input method.

Then, looking at how cape-char extracts translation mappings from input methods, I realized there has to be a better way than parsing help buffer output. So I spent about a day looking into quail internals figuring out how I can get the translation mapping and bypass describe-input-method.

So I found a way to achieve it, but there are a few limitations: only input methods that is from quail can use quail API - on my machine's emacs, all inputs methods use quail except for some variants of Korean Hangul and UCS. (More details like this would be included in the PR after I hear your feedback on the issue) :)

Effects of having a better translation hash function

in #61 you mentioned:

  1. We rewrite the code used here, such that it is more robust. This will mainly involve accessing the input method data in a more robust way. If a more satisfactory solution would be found, making the API public would be okay. Unfortunately I don't know if there is a better way.

So hopefully if my solution is satisfactory, we can then have the user define their own cape Capfs with their own chosen input method!

This would then resolve: #73:

Since math-symbol-lists is used by company math anyway, and on this emacs wiki page adding the list through quail is suggested. So if one wishes to use company math, they can follow the instructions on the wiki page, then use the hypothetical cape char define API to add the cape capf!

cape emoji

It seems like the emoji input method is only added to emacs by default from emacs 29, what are your thoughts on adding a cape-emoji built in for cape, if the user is running emacs 29? Of course, if cape char define is public the user can easily add it themselves.

Questions

off topic for the issue, but do you have any resources on where I can find docs or manual on writing my own CAPFs? Answers on Emacs SE didn't point to any links to manuals

minad commented 10 months ago

Hi, thanks for reaching out! Your suggestions are welcome.

  1. I understand that you don't want to install Company, but if cape-company-to-capf doesn't work well it should be improved. Can you please be more specific about the problems? In my tests the adapter works quite well.
  2. A better more robust translation function is very welcome. Please create a PR and we can discuss there.
  3. As a quick experiment, I've now added an initial version of cape-emoji available only on 29. It is a baseline implementation. Can your implementation do better? Feel free to improve it!
  4. Public API - if the API is robust, why not? I have to look at the patch to decide. There is nothing wrong to keep it private and make it available such that users can take advantage of it in their user configuration.
  5. I cannot suggest good Capf resources except the Emacs/Elisp manual, Emacs source and the Cape source. The Cape source itself is my personal Capf reference.