From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Are abbrevs for this? Date: Wed, 10 Jun 2009 16:53:26 -0700 (PDT) Organization: http://groups.google.com Message-ID: <183b9113-69f1-45a2-8bec-a3fbdae5e92f@d38g2000prn.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1244709269 31132 80.91.229.12 (11 Jun 2009 08:34:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Jun 2009 08:34:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 11 10:34:26 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MEfjq-0000Xo-GG for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Jun 2009 10:34:22 +0200 Original-Received: from localhost ([127.0.0.1]:33360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MEfjp-00034P-Rk for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Jun 2009 04:34:21 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!d38g2000prn.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 101 Original-NNTP-Posting-Host: 76.102.12.87 Original-X-Trace: posting.google.com 1244678006 2824 127.0.0.1 (10 Jun 2009 23:53:26 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 10 Jun 2009 23:53:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d38g2000prn.googlegroups.com; posting-host=76.102.12.87; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.30 Safari/530.5, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:169908 comp.emacs:98235 X-Mailman-Approved-At: Thu, 11 Jun 2009 04:23:14 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65151 Archived-At: On Jun 10, 6:53 am, "Paulo J. Matos" 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" "=CE=B1" nil 0) ("beta" "=CE=B2" nil 0) ("gamma" "=CE=B3" nil 0) ("theta" "=CE=B8" nil 0) ("Infinity" "=E2=88=9E" nil 0) ("ar1" "=E2=86=92" nil 0) ("ar2" "=E2=87=92" nil 0) )) (abbrev-mode t) ; turn on abbrev mode Then, when you type =E2=80=9Calpha =E2=80=9D, it will become =E2=80=9C=CE= =B1=E2=80=9D. =E2=80=A2 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 =E2=80=9C&=E2=80=9D by =E2=80=9C&=E2=80=9D in a regio= n? 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 =E2=80=9C<=E2=80=9D by =E2=80=9C<=E2=80=9D and other similar = HTML chars that needs to be encoded." (interactive "r") (replace-string-pairs-region start end '( ("&" "&") ("<" "<") (">" ">") ) ) ) With the above code, you can select a region, then press =E2=80=9CAlt+x replace-html-chars=E2=80=9D, and have all =E2=80=9C&=E2=80=9D, =E2=80=9C>= =E2=80=9D, =E2=80=9C<=E2=80=9D 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: “ =E2=86=92 =E2=80=9C ” =E2=86=92 =E2=80=9D é =E2=86=92 =C3=A9 © =E2=86=92 =C2=A9 -> =E2=86=92 =E2=86=92 =3D> =E2=86=92 =E2=87=92 Pi =E2=86=92 =CF=80 Infinity =E2=86=92 =E2=88=9E 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) =E2=80=A2 Emacs and HTML Tips http://xahlee.org/emacs/emacs_html.html Xah =E2=88=91 http://xahlee.org/ =E2=98=84