help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing source code with Unicode characters


From: Göktuğ Kayaalp
Subject: Re: Writing source code with Unicode characters
Date: Thu, 06 Feb 2014 21:23:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]