for some programming languages like Ada and Coq it is very common to use unicode symbols such as Γ, α, etc…
Most users input these symbols using variants of emacs
TeX-input-method, which is basically a method that will recognize
\alpha and insert α, providing autocompletion whenever the user presses
I’d like to give this feature a go in CodeMirror, any particular advice?
[update: a first version of such an addon is at:
You should be able to do this by listening to
"inputRead" events and scanning backwards to see if there’s a matching backslash-name there, and then if there is, replacing it with the appropriate character.
@marijn, very interesting. I was thinking however of using
hint/show-hint.js, do you think that is not possible?
Sorry if I wasn’t very clear before, (discuss ate my backslash), in
TeX-input-method, when the user presses
\, this has the effect of activating the TeX completion command, and if they enter a recognized symbol, it is then replaced.
You can see it in action here:
Ah, sure, you can do that too.
Cool thanks! I’ll try the completion route then and see how it goes; from a quick scan the API should work well.
Ok, so I was able to hack something, it seems to work well. Would a PR make sense?
Something I couldn’t figure out was how to make this a general hint for all modes, now I do:
CodeMirror.registerHelper("hint", "coq", TeX_input_hint);
but ideally we’d like this input completion to be available to any mode that wants it. In emacs we would achieve so by using a
This file has been truncated.
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// TeX-style completion, written by Emilio J. Gallego Arias.
// List of open issues before a merge can be considered:
// - Make the unicode table a parameter.
// - Review if the way we capture '\' is comforming to CM coding standards.
// - We register a helper for "hint.coq", but we would like this
// helper to be available to all modes.
if (typeof exports == "object" && typeof module == "object") // CommonJS
else if (typeof define == "function" && define.amd) // AMD
else // Plain browser env
Would a PR make sense?
Nope, I don’t want to further extend the scope of my distribution. But putting it on github and NPM so that others can use it would be a great idea.
Just for reference to future readers, the code lives now at: