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

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

Re: Are abbrevs for this?


From: Xah Lee
Subject: Re: Are abbrevs for this?
Date: Wed, 10 Jun 2009 16:53:26 -0700 (PDT)
User-agent: G2/1.0

On Jun 10, 6:53 am, "Paulo J. Matos" <pocma...@gmail.com> wrote:
> Hi all,
>
> I am developing  a new major mode for a new specification language
> which uses a lot of unicode symbols but it also has an ascii notation.
> Like some scheme modes convert the lambda keyword into the greek
> lambda letter, I have a table of keywords that would like them to be
> changed into unicode symbols.
>
> Can I use abbrevs for this?

you can use abbrev, like this:

Q: How to use abbrev to input unicode chars?

Put the following in your emacs init file:

(define-abbrev-table 'global-abbrev-table '(
    ("alpha" "α" nil 0)
    ("beta" "β" nil 0)
    ("gamma" "γ" nil 0)
    ("theta" "θ" nil 0)
    ("Infinity" "∞" nil 0)

    ("ar1" "→" nil 0)
    ("ar2" "⇒" nil 0)
    ))

(abbrev-mode t) ; turn on abbrev mode

Then, when you type “alpha ”, it will become “α”.

• Emacs and Unicode Tips
  http://xahlee.org/emacs/emacs_n_unicode.html


if you already have typed text and want to replace them to unicode,
you can also do so. See:

Q: How to replace “&” by “&amp;” in a region?

Place the following in your emacs init file:

(defun replace-string-pairs-region (start end mylist)
  "Replace string pairs in region."
  (save-restriction
    (narrow-to-region start end)
    (mapc
      (lambda (arg)
        (goto-char (point-min))
        (while (search-forward (car arg) nil t) (replace-match (cadr
arg)) )
      ) mylist
    )
  )
)

(defun replace-html-chars (start end)
  "Replace “<” by “&lt;” and other similar HTML chars that needs to be
encoded."
  (interactive "r")
(replace-string-pairs-region start end '(
("&" "&amp;")
("<" "&lt;")
(">" "&gt;")
    )
  )
)

With the above code, you can select a region, then press “Alt+x
replace-html-chars”, and have all “&”, “>”, “<” replaced by their
encoded entity. You can define a keyboard shortcut for easy operation.

You can also use the code to replace some HTML entities by their
actual unicode characters. For example:

&ldquo;    →    “
&rdquo;    →    ”
&eacute;   →    é
&copy;     →    ©

->         →    →
=>         →    ⇒
Pi         →    π
Infinity   →    ∞

This makes the HTML source code more elegant and readible. (You need
to declare your charset as one of unicode encodings. See Character
Sets and Encoding in HTML)

• Emacs and HTML Tips
  http://xahlee.org/emacs/emacs_html.html

  Xah
∑ http://xahlee.org/

reply via email to

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