unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Writing source code with Unicode characters
@ 2014-02-06 18:26 Óscar Fuentes
  2014-02-06 18:45 ` Eli Zaretskii
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Óscar Fuentes @ 2014-02-06 18:26 UTC (permalink / raw)
  To: help-gnu-emacs

I'll like to experiment with using Unicode on source code (λ instead of
lambda, etc) but it seems quite inconvenient to insert those chars with
C-x 8 RET. Org-mode has the capability of displaying λ when you type
\lambda, but that's just a display replacement, the raw text still is
\lambda.

What can I use to make more convenient the insertion of Unicode chars?
(I'm mostly interested on Greek letters and other math-related symbols)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
  2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
@ 2014-02-06 18:45 ` Eli Zaretskii
  2014-02-06 18:48 ` Drew Adams
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2014-02-06 18:45 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Óscar Fuentes <ofv@wanadoo.es>
> Date: Thu, 06 Feb 2014 19:26:45 +0100
> 
> I'll like to experiment with using Unicode on source code (λ instead of
> lambda, etc) but it seems quite inconvenient to insert those chars with
> C-x 8 RET. Org-mode has the capability of displaying λ when you type
> \lambda, but that's just a display replacement, the raw text still is
> \lambda.
> 
> What can I use to make more convenient the insertion of Unicode chars?
> (I'm mostly interested on Greek letters and other math-related symbols)

The TeX input method?  You type "\lambda", literally, and get what you
want.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Writing source code with Unicode characters
  2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
  2014-02-06 18:45 ` Eli Zaretskii
@ 2014-02-06 18:48 ` Drew Adams
  2014-02-06 19:23 ` Göktuğ Kayaalp
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2014-02-06 18:48 UTC (permalink / raw)
  To: Óscar Fuentes, help-gnu-emacs

> I'll like to experiment with using Unicode on source code (λ instead
> of lambda, etc) but it seems quite inconvenient to insert those chars
> with C-x 8 RET. Org-mode has the capability of displaying λ when you type
> \lambda, but that's just a display replacement, the raw text still
> is \lambda.
> 
> What can I use to make more convenient the insertion of Unicode
> chars? (I'm mostly interested on Greek letters and other math-related
> symbols)

`C-x 8 RET' is extremely general, since it tries to handle all Unicode
chars.

Try library `ucs-cmds.el', here:
http://www.emacswiki.org/emacs-en/download/ucs-cmds.el (code)
http://www.emacswiki.org/emacs-en/UnicodeEncoding#ucs-cmds.el (description)

Use it to define commands that insert particular Unicode chars that
you use most of the time.  Then bind those commands to keys if you
want.

These examples from the Commentary in `ucs-cmds.el' should be relevant
for your particular use cases:

(ucsc-make-commands "^greek [a-z]+ letter") ; Greek characters
(ucsc-make-commands "^math")                ; Math symbols

Those define individual commands that insert the Greek chars and the
Unicode math symbols.

For example, one of those commands that gets defined is
`greek-small-letter-lambda', which inserts a lowercase lambda character.

Another command so defined is `mathematical-bold-fraktur-capital-r'.
Here is its doc string:

,----
| mathematical-bold-fraktur-capital-r is an interactive Lisp function.
| 
| (mathematical-bold-fraktur-capital-r ARG)
|  
| Insert Unicode character `MATHEMATICAL BOLD FRAKTUR CAPITAL R'.
| This character has code point 120189.
`----



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
  2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
  2014-02-06 18:45 ` Eli Zaretskii
  2014-02-06 18:48 ` Drew Adams
@ 2014-02-06 19:23 ` Göktuğ Kayaalp
  2014-02-06 20:38 ` Óscar Fuentes
  2014-02-07  0:32 ` Florian Beck
  4 siblings, 0 replies; 10+ messages in thread
From: Göktuğ Kayaalp @ 2014-02-06 19:23 UTC (permalink / raw)
  To: help-gnu-emacs

I just came up with a solution for this: Have an alist from two characters
to unicode symbols, and have a function, when called, takes the two
characters to the left of the point, then lookup the alist and replace
them with the cdr of matching pair:

    (defvar unicode-pair-alist '((".\\" . "λ")
                                 ("->" . "→")
                                 ("=>" . "⇒")))

    (defun unicode-replace-previous-two-chars ()
      (interactive)
      (if (or (not (boundp 'unicode-pair-alist))
              (null unicode-pair-alist))
          (error "Please set ``unicode-pair-alist'' in order to use this function."))
      (let* ((pair (string (get-byte (- (point) 2))
                           (get-byte (- (point) 1))))
             (usym-pair (assoc pair unicode-pair-alist)))
        (if (null usym-pair)
            (error (concat "Pair not in ``unicode-pair-alist'': " pair)))
        (delete-backward-char 2)
        (insert (cdr usym-pair))))

    (global-set-key (kbd "C-'") 'unicode-replace-previous-two-chars)

One can map `->' to `→' directly, but then they can't insert `->'
easily, can they?  What do you think of this?  I have just came up with
this after I read your post, so I did not evaluate it's merits and perils.

Óscar Fuentes <ofv@wanadoo.es> writes:

> I'll like to experiment with using Unicode on source code (λ instead of
> lambda, etc) but it seems quite inconvenient to insert those chars with
> C-x 8 RET. Org-mode has the capability of displaying λ when you type
> \lambda, but that's just a display replacement, the raw text still is
> \lambda.
>
> What can I use to make more convenient the insertion of Unicode chars?
> (I'm mostly interested on Greek letters and other math-related symbols)
>
>
>

GK




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
       [not found] <mailman.13962.1391711236.10748.help-gnu-emacs@gnu.org>
@ 2014-02-06 20:36 ` Eric Wolf
  2014-02-07  2:52 ` Rusi
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Wolf @ 2014-02-06 20:36 UTC (permalink / raw)
  To: help-gnu-emacs

You could use a different keyboard layout.

Look at this for example: http://www.neo-layout.org/

It might not be that attractive to you, as it is
meant for typing german texts mostly, but the
idea of several different layers is useful and the
xkb-files are easily changed.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
  2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
                   ` (2 preceding siblings ...)
  2014-02-06 19:23 ` Göktuğ Kayaalp
@ 2014-02-06 20:38 ` Óscar Fuentes
  2014-02-06 22:59   ` Drew Adams
  2014-02-07  0:32 ` Florian Beck
  4 siblings, 1 reply; 10+ messages in thread
From: Óscar Fuentes @ 2014-02-06 20:38 UTC (permalink / raw)
  To: help-gnu-emacs

Óscar Fuentes <ofv@wanadoo.es> writes:

> I'll like to experiment with using Unicode on source code (λ instead of
> lambda, etc) but it seems quite inconvenient to insert those chars with
> C-x 8 RET. Org-mode has the capability of displaying λ when you type
> \lambda, but that's just a display replacement, the raw text still is
> \lambda.
>
> What can I use to make more convenient the insertion of Unicode chars?
> (I'm mostly interested on Greek letters and other math-related symbols)

Drew:

Thanks but that's not quite the thing I'm looking for. It is good when
you need to write a few unicode chars and wish to save a few keystrokes
by not invoking C-x 8 RET <name>, but not so convenient when you are
interested on quickly typing unicode chars on a similar way you type
ordinary text, which would require setting quite a few keybindings and
it would not be an advantage over binding the key sequences to
(insert-char <the-char-itself>).

Eli:

That's very nice and something I'll would use if there is not something
better.

Göktuğ Kayaalp:

That's the best approach so far, IMHO. Just before reading your
responses, I discovered on the net a commercial Emacs package that does
exactly that. As you demonstrated, the functionality is quite easy to
implement. Instead of using just the two last chars, we can use
(thing-at-point 'symbol) and then we can map (a -> \alpha), (and ->
logical symbol and), etc

Thanks so much to all.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Writing source code with Unicode characters
  2014-02-06 20:38 ` Óscar Fuentes
@ 2014-02-06 22:59   ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2014-02-06 22:59 UTC (permalink / raw)
  To: Óscar Fuentes, help-gnu-emacs

> Drew:
> Thanks but that's not quite the thing I'm looking for. It is good
> when you need to write a few unicode chars

Why a few?  It's precisely when you want to define *lots* of such
chars that the macro is the most helpful.

> and wish to save a few keystrokes by not invoking C-x 8 RET
> <name>, but not so convenient when you are interested on quickly
> typing unicode chars on a similar way you type ordinary text,
> which would require setting quite a few keybindings

Suit yourself.  But your "quickly typing unicode chars on a
similar way you type ordinary text" sounds to me a *lot* like
having keys that insert the chars you want - in effect, another
(soft) keyboard or keyboard range.

And that essentially means "setting quite a few keybindings".
But you define those keys only once.  And you can do it in a
systematic way.

You use the Shift key now to reach certain chars using your
keyboard.  You could just as easily use another key (as a prefix
key) to "shift" any of your keys so they directly type Greek
chars or math symbols.

Why wouldn't you want a `lambda' key on your keyboard?
And `alpha' ... `omega' keys if you use Greek letters a lot, as
you say.  

E.g., you now have `l' and `Shift l' (for `L').  Why not also,
say, `<lwindow> l' for lowercase lambda and `Shift <lwindow> l'
for uppercase lambda?  Likewise for other Greek letters you use.

And for any such commands (e.g. some of the math symbols)
that you do *not* want to bind to keys, it is trivial to use
*completion* against the command name - which is also the
Unicode char name.

If by "quickly typing unicode chars on a similar way you type
ordinary text" you really meant (as per Eli's suggestion) typing
not a single key for the char but a bunch of keys that spell out
the *name* of the char (e.g. `l a m b d a'), then that is what
you already get with completion - except that you need not type
the whole name.

So in that sense too of "quickly typing...ordinary text",
I would think that macro `ucsc-make-commands' would help you.

> and it would not be an advantage over binding the key
> sequences to (insert-char <the-char-itself>).

Sure, you could write your own:

(defun my-THE-CHAR-command ()
  (interactive)
  (insert-char <the-char-itself>))

But I suspect maybe you are missing the point.  You would need
to create such code (including the inserted <the-char-itself>)
for *each character* you  use - either by hand or by program.

Writing such code is exactly what macro `ucsc-make-commands'
does for you.  And it does it in one fell swoop for a whole
range of chars.

But again, suit yourself, of course.  Just thought perhaps
it was not clear what I was suggesting for your use case.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
  2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
                   ` (3 preceding siblings ...)
  2014-02-06 20:38 ` Óscar Fuentes
@ 2014-02-07  0:32 ` Florian Beck
  4 siblings, 0 replies; 10+ messages in thread
From: Florian Beck @ 2014-02-07  0:32 UTC (permalink / raw)
  To: help-gnu-emacs

On 06.02.2014 19:26, Óscar Fuentes wrote:
> What can I use to make more convenient the insertion of Unicode chars?
> (I'm mostly interested on Greek letters and other math-related symbols

How about abbrev-mode? It's convenient and works on the fly.

Whenever I find something tedious to type, I make an abbreviation (C-x a 
g) for it.

Then I have this in my .emacs:

   ;; allow § in abbrevs
   (modify-syntax-entry ?§ "w" text-mode-syntax-table)
   (modify-syntax-entry ?§ "w" prog-mode-syntax-table)
   ;; save and load abbrevs
   (quietly-read-abbrev-file)
   (add-hook 'kill-emacs-hook 'write-abbrev-file)
   ;; activate
   (add-hook 'org-mode-hook 'abbrev-mode)
   (add-hook 'emacs-lisp-mode-hook 'abbrev-mode)

I never use §, so I can use it here. E.g. §l -> λ.
Abbrev mode also takes care of case, so you get the upper case Λ for free.

-- 
Florian Beck



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
       [not found] <mailman.13962.1391711236.10748.help-gnu-emacs@gnu.org>
  2014-02-06 20:36 ` Eric Wolf
@ 2014-02-07  2:52 ` Rusi
  2014-02-07 16:41   ` Rusi
  1 sibling, 1 reply; 10+ messages in thread
From: Rusi @ 2014-02-07  2:52 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, February 6, 2014 11:56:45 PM UTC+5:30, Óscar Fuentes wrote:
> I'll like to experiment with using Unicode on source code (λ instead of
> lambda, etc) but it seems quite inconvenient to insert those chars with
> C-x 8 RET. Org-mode has the capability of displaying λ when you type
> \lambda, but that's just a display replacement, the raw text still is
> \lambda.

> What can I use to make more convenient the insertion of Unicode chars?
> (I'm mostly interested on Greek letters and other math-related symbols)

It really depends on the set size:
- a handful of greek characters?
- a hundred or so greek+math characters?
- full unicode (million) characaters?

In short huffman coding imposes natural limits on how convenient one 
can make the char-entry.

On a recent X, there is an apl keyboard. Start it with
$ setxkbmap -layout "us,apl" -option "grp:ralt_rshift_toggle"

Toggle it with rshift ralt [single char is also possible]

After that typing abcdefgh gives
⍺⊥∩⌊∊_∇∆

Now all that remains, analogous to "define an apl-keyboard"
is to define an Oscar-keyboard :D


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Writing source code with Unicode characters
  2014-02-07  2:52 ` Rusi
@ 2014-02-07 16:41   ` Rusi
  0 siblings, 0 replies; 10+ messages in thread
From: Rusi @ 2014-02-07 16:41 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, February 7, 2014 8:22:23 AM UTC+5:30, Rusi wrote:
> On Thursday, February 6, 2014 11:56:45 PM UTC+5:30, Óscar Fuentes wrote:
> > I'll like to experiment with using Unicode on source code (λ instead of
> > lambda, etc) but it seems quite inconvenient to insert those chars with
> > C-x 8 RET. Org-mode has the capability of displaying λ when you type
> > \lambda, but that's just a display replacement, the raw text still is
> > \lambda.

> > What can I use to make more convenient the insertion of Unicode chars?
> > (I'm mostly interested on Greek letters and other math-related symbols)

> It really depends on the set size:
> - a handful of greek characters?
> - a hundred or so greek+math characters?
> - full unicode (million) characaters?

> In short huffman coding imposes natural limits on how convenient one 
> can make the char-entry.

> On a recent X, there is an apl keyboard. Start it with
> $ setxkbmap -layout "us,apl" -option "grp:ralt_rshift_toggle"

> Toggle it with rshift ralt [single char is also possible]

> After that typing abcdefgh gives
> ⍺⊥∩⌊∊_∇∆

> Now all that remains, analogous to "define an apl-keyboard"
> is to define an Oscar-keyboard :D

$ setxkbmap -layout us,gr -option grp:win_switch -option grp:alt_shift_toggle

And now pressing the win key along with a-z gives

αβψδεφγηιξκλμνοπ;ρστθωςχυζ


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-02-07 16:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-06 18:26 Writing source code with Unicode characters Óscar Fuentes
2014-02-06 18:45 ` Eli Zaretskii
2014-02-06 18:48 ` Drew Adams
2014-02-06 19:23 ` Göktuğ Kayaalp
2014-02-06 20:38 ` Óscar Fuentes
2014-02-06 22:59   ` Drew Adams
2014-02-07  0:32 ` Florian Beck
     [not found] <mailman.13962.1391711236.10748.help-gnu-emacs@gnu.org>
2014-02-06 20:36 ` Eric Wolf
2014-02-07  2:52 ` Rusi
2014-02-07 16:41   ` Rusi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).