From: Luke Gorrie
Subject: pretty-lambda.el
Date: 
Message-ID: <lhlm79utsh.fsf@bluetail.com>
;;; pretty-lambda.el -- Lambda character syntactic-sugar hack for Common Lisp
;;; Written for Emacs 21 by Luke Gorrie <····@bluetail.com>
;;; $Id: pretty-lambda.el,v 1.2 2002/08/14 19:17:50 luke Exp luke $
;;
;; A simple hack to use pretty lambda characters in Emacs for Common
;; Lisp programming, antisocially implemented by using greek character
;; encoding for Lisp source. Best explained with a screenshot:
;; http://www.bluetail.com/~luke/misc/lambda.jpg
;;
;; Here's how it works:
;;
;; * Emacs already supports entering and displaying fancy
;;   characters. You can enter a lambda symbol either with
;;   set-input-method to "greek" (then press l), or with the
;;   `pretty-lambda-insert' function provided here.
;;
;; * We tell Emacs to load and save lisp files using the
;;   `greek-iso-8bit' character encoding instead of Latin-1. You'll
;;   want to do this differently if you really use Latin-1!
;;
;;   We tell ilisp to do the same conversion when it talks to an
;;   inferior lisp.
;;
;; * We install a reader macro in Common Lisp to expand the character
;;   that represents lambda into the symbol LAMBDA.
;;
;; You'll also need to have a font in your X server that can display
;; greek characters (otherwise you just see a hollow box). On my
;; Redhat 7.1 machine I already had this (though it's a bit ugly). On
;; my Debian woody machine, I apt-get'd all the international fonts
;; packages and then restarted the X server, and found myself with
;; very nice greek characters.
;;
;; Almost forgot! Here's the Common Lisp side:
;;
;;   (defun greek-lambda-reader (stream char)
;;     (declare (ignore stream char))
;;     'lambda)
;;
;;   (set-macro-character (code-char 235) #'greek-lambda-reader)
;;
;; There is probably a much better way to do all this!

(defvar pretty-lambda-coding-system 'greek-iso-8bit)

;; Hopefully this number is portable - I don't know if it's unicode,
;; or what..
(defvar pretty-lambda-character 2923)

(defun pretty-lambda-insert ()
  "Insert a lambda character."
  (interactive)
  (insert pretty-lambda-character))

(defun pretty-lambda-unpretty-region (start end)
  "Replace lambda characters with \"lambda\"."
  (interactive "r")
  (replace-string (string pretty-lambda-character) "lambda" nil start end))

;; Integration (automatically adds hooks - there is no escape!!)

(defun pretty-lambda-ilisp-init-hook ()
  (set-process-coding-system (ilisp-process) pretty-lambda-coding-system))

(add-hook 'ilisp-init-hook 'pretty-lambda-ilisp-init-hook)
(modify-coding-system-alist 'file "\\.lisp$" pretty-lambda-coding-system)

(provide 'pretty-lambda)

From: Oliver Scholz
Subject: Re: pretty-lambda.el
Date: 
Message-ID: <m3n0rory6t.fsf@ID-87814.user.dfncis.de>
Luke Gorrie <····@bluetail.com> writes:

> ;;; pretty-lambda.el -- Lambda character syntactic-sugar hack for Common Lisp
> ;;; Written for Emacs 21 by Luke Gorrie <····@bluetail.com>
> ;;; $Id: pretty-lambda.el,v 1.2 2002/08/14 19:17:50 luke Exp luke $
> ;;
> ;; A simple hack to use pretty lambda characters in Emacs for Common
> ;; Lisp programming, antisocially implemented by using greek character
> ;; encoding for Lisp source. Best explained with a screenshot:
> ;; http://www.bluetail.com/~luke/misc/lambda.jpg

Wonderful! That's exactly the kind of useless stuff I really love. :-)

[...]
> ;; * We tell Emacs to load and save lisp files using the
> ;;   `greek-iso-8bit' character encoding instead of Latin-1. You'll
> ;;   want to do this differently if you really use Latin-1!
[...]

This is -- together with the "antisocially" part -- is rather a
problem.

> ;; There is probably a much better way to do all this!
[...]

How about putting the lambda in an overlay and using the font-lock
mechanism? 

I couldn't resist. The following doesn't change the actual buffer
content. So it will not inflict for example the way how the buffer is
saved -- or evaluated for that matter. When jit-font-lock is
activated, it DTRT when you enter "lambda".

It would be nice, however, to add something that removes the overlays
again, when the user turns font-lock-mode off.

!!! Use at your own risk !!!

(defconst lambda-character "\x513bb") ; I wonder, shouldn't that be
				      ; 0x03bb in Unicode, actually?

(defconst lambda-overlay-properties
  `((before-string ,lambda-character)
    (lambdaed t) (invisible t)))

(defun lambda-jit-function (start limit)
  (mapc 'delete-overlay (delq nil
			      (mapcar (lambda (overl) 
					(if (overlay-get overl 'lambdaed)
					    overl
					  nil))
				      (overlays-in start limit))))
  (save-excursion
    (goto-char start)
    (while (re-search-forward "\\<lambda\\>" limit t)
      (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
	(dolist (prop lambda-overlay-properties)
	  (apply 'overlay-put overlay prop))))))


(defun lambda-register ()
  (jit-lock-register 'lambda-jit-function))

(add-hook 'lisp-mode-hook 'lambda-register)

(add-hook 'emacs-lisp-mode-hook 'lambda-register)

    -- Oliver

-- 
28 Thermidor an 210 de la R�volution
Libert�, Egalit�, Fraternit�!
From: Stefan Monnier
Subject: Re: pretty-lambda.el
Date: 
Message-ID: <5llm78jhr1.fsf@rum.cs.yale.edu>
>>>>> "os" == Oliver Scholz <··········@gmx.de> writes:
> How about putting the lambda in an overlay and using the font-lock
> mechanism? 

I don't like overlays, but I do like font-lock:

(defun sm-elisp-mode-hook ()
  (font-lock-add-keywords
   nil `(("\\<lambda\\>"
	  (0 (progn (compose-region (match-beginning 0) (match-end 0)
				    ,(make-char 'greek-iso8859-7 107))
		    nil))))))
(add-hook 'emacs-lisp-mode-hook 'sm-elisp-mode-hook)

Compared to overlays, this has the advantage of behaving better w.r.t
cursor movement (it behaves as if it really were a single char).  But you
still need to do C-s lambda rather than C-s � :-(


        Stefan
From: Joe Casadonte
Subject: Re: pretty-lambda.el
Date: 
Message-ID: <ufzxgkr1d.fsf@terrapin.northbound-train.com>
On 15 Aug 2002, Stefan Monnier wrote:

> (defun sm-elisp-mode-hook ()
>   (font-lock-add-keywords
>    nil `(("\\<lambda\\>"
> 	  (0 (progn (compose-region (match-beginning 0) (match-end 0)
> 				    ,(make-char 'greek-iso8859-7 107))
> 		    nil))))))

Comes up as a box on my system (emacs 21, NT).  Anyone know what to do
to "fix" this on NT?  I'm nearly clueless when it comes to emacs and
fonts and coding systems.

BTW, I'll echo someone else's sentiments -- I love the frilly
superfluous things like this!!

--
Regards,

joe
Joe Casadonte
··········@northbound-train.com

------------------------------------------------------------------------------
         Llama Fresh Farms => http://www.northbound-train.com
   Gay Media Resource List => http://www.northbound-train.com/gaymedia.html
            Perl for Win32 => http://www.northbound-train.com/perlwin32.html
               Emacs Stuff => http://www.northbound-train.com/emacs.html
          Music CD Trading => http://www.northbound-train.com/cdr.html
------------------------------------------------------------------------------
                       Live Free, that's the message!
------------------------------------------------------------------------------
From: Stefan Monnier
Subject: Re: pretty-lambda.el
Date: 
Message-ID: <5ld6si38o1.fsf@rum.cs.yale.edu>
>> (defun sm-elisp-mode-hook ()
>> (font-lock-add-keywords
>> nil `(("\\<lambda\\>"
>> (0 (progn (compose-region (match-beginning 0) (match-end 0)
>> ,(make-char 'greek-iso8859-7 107))
>> nil))))))
> Comes up as a box on my system (emacs 21, NT).  Anyone know what to do

That's probably because you don't have an iso-8859-7 font.
You can try using a unicode char instead (on my GNU/Linux system the unicode
font does not have the lambda char which is why I used the iso-8859-7
charset instead) by replacing the make-char expression above with

   (make-char 'mule-unicode-e000-ffff 117 61)


-- Stefan
From: Oliver Scholz
Subject: Re: pretty-lambda.el
Date: 
Message-ID: <m3r8h0qbl4.fsf@ID-87814.user.dfncis.de>
"Stefan Monnier <···@acm.com>" <·······························@flint.cs.yale.edu> writes:

>>>>>> "os" == Oliver Scholz <··········@gmx.de> writes:
>> How about putting the lambda in an overlay and using the font-lock
>> mechanism? 
>
> I don't like overlays, but I do like font-lock:

I always wanted to ask this: why actually? Are overlays expensive?

> (defun sm-elisp-mode-hook ()
>   (font-lock-add-keywords
>    nil `(("\\<lambda\\>"
> 	  (0 (progn (compose-region (match-beginning 0) (match-end 0)
> 				    ,(make-char 'greek-iso8859-7 107))
> 		    nil))))))
> (add-hook 'emacs-lisp-mode-hook 'sm-elisp-mode-hook)

Wonderful. This beats it. Thank you very much.
[...]

> But you still need to do C-s lambda rather than C-s � :-(

I think this is rather a feature than a bug. I don't like to mess with
input methods in the mini-buffer.

    -- Oliver

Crossposted and follow-up set to gnu.emacs.help
-- 
28 Thermidor an 210 de la Révolution
Liberté, Egalité, Fraternité!