You can match a desired region by a regexp, and since a given region is substituted by compose-region as described below you can do darn near whatever you want. For example, emacs allows for inlined base-64 encoded images, you could have it display Miss June if you'd like and it would still compile.
(defun compose-region (start end &optional components modification-func)
"Compose characters in the current region.
Characters are composed relatively, i.e. composed by overstricking or
stacking depending on ascent, descent and other properties.
When called from a program, expects these four arguments.
First two arguments START and END are positions (integers or markers)
specifying the region.
Optional 3rd argument COMPONENTS, if non-nil, is a character, a string
or a vector or list of integers and rules.
If it is a character, it is an alternate character to display instead
of the text in the region.
If it is a string, the elements are alternate characters. In
this case, TAB element has a special meaning. If the first
characer is TAB, the glyphs are displayed with left padding space
so that no pixel overlaps with the previous column. If the last
character is TAB, the glyphs are displayed with rigth padding
space so that no pixel overlaps with the following column.
If it is a vector or list, it is a sequence of alternate characters and
composition rules, where (2N)th elements are characters and (2N+1)th
elements are composition rules to specify how to compose (2N+2)th
elements with previously composed N glyphs.
A composition rule is a cons of global and new glyph reference point
symbols. See the documentation of `reference-point-alist' for more
detail.
Optional 4th argument MODIFICATION-FUNC is a function to call to
adjust the composition when it gets invalid because of a change of
text in the composition."
(interactive "r")
On Wed, Jun 10, 2009 at 11:45 AM, Ricky Clarkson
<ricky.clarkson@...> wrote:
Can you use this to do more advanced things like make new F<String,
Integer>() { public Integer f(String s) { return s.length(); } } look
like s => s.length() ?
2009/6/10 Ray Racine <ray.racine@...>:
> For what its worth you can do this with emacs using compose region. You
> tell emacs to display a substitute for a string in a buffer.
>
> For example, lets say you want to display ≤ where ever the scala source code
> contains '<' followed by '=', ie. <=.
>
> (defconst scala-less-equal-char (decode-char 'ucs #x2264))
>
> (defconst scala-key-words
> '("\\(<=\\)"
> 1
>
> (progn (compose-region (match-beginning 1)
> (match-end 1)
> scala-less-equal-char)
> nil)))
>
> (font-lock-add-keywords nil scala-key-words)
>
> One can do a number of interesting things. All 'var' keywords are in red,
> scala-dangerous-face.
>
> ⊤⊥ for Any and Unit.
> ¬ for 'not'
> ∧ ∨ for &&, ||
>
> Underneath the source file doesn't change an iota, its only in how it is
> displayed in the emacs editor, so the file compiles clean.
>
> Ray
>
> P.S. Unable to currently test the above, but its the right idea. I don't
> have access to my system at the moment.
>
> On Tue, Jun 9, 2009 at 5:59 PM, Alex Cruise <
alex@...> wrote:
>>
>> Ray Racine wrote:
>>>
>>> Interesting if some of Scala's reserved symbols were legally aliasable
>>> with their equivalent unicode character.
>>
>> Yes, that would be interesting indeed. :)
>>
>> def f(n: ⇒ Int) = for (x ← 1 to n) yield Map(x → ("*" * x))
>>
>> -0xe1a
>
>