+(defun smiley-toggle-buffer (&optional arg buffer st nd)
+ "Toggle displaying smiley faces.
+With arg, turn displaying on if and only if arg is positive."
+ (interactive "P")
+ (let (on off)
+ (map-extents
+ (lambda (e void)
+ (let (ant)
+ (if (annotationp (setq ant (extent-property e 'smiley-annotation)))
+ (if (eq (extent-property e 'invisible) nil)
+ (setq off (cons (cons ant e) off))
+ (setq on (cons (cons ant e) on)))))
+ nil)
+ buffer st nd)
+ (if (and (not (and (numberp arg) (< arg 0)))
+ (or (and (numberp arg) (> arg 0))
+ (null on)))
+ (if off
+ (while off
+ (reveal-annotation (caar off))
+ (set-extent-property (cdar off) 'invisible t)
+ (setq off (cdr off)))
+ (smiley-buffer))
+ (while on
+ (hide-annotation (caar on))
+ (set-extent-property (cdar on) 'invisible nil)
+ (setq on (cdr on))))))
+
+;; Simply removing all smiley if existing.
+;; FIXME: make it work as the one in XEmacs.
+(defun smiley-toggle-buffer-ems (&optional arg buffer st nd)
+ "Toggle displaying smiley faces.
+With arg, turn displaying on if and only if arg is positive."
+ (interactive "P")
+ (save-excursion
+ (when buffer
+ (set-buffer buffer))
+ (let (found)
+ (dolist (overlay (overlays-in (or st (point-min))
+ (or nd (point-max))))
+ (when (overlay-get overlay 'smiley)
+ (remove-text-properties (overlay-start overlay)
+ (overlay-end overlay) '(display))
+ (setq found t)))
+ (unless found
+ (smiley-buffer buffer st nd)))))
+
+(unless (featurep 'xemacs)
+ (defalias 'smiley-create-glyph 'smiley-create-glyph-ems)
+ (defalias 'smiley-toggle-extent 'smiley-toggle-extent-ems)
+ (defalias 'smiley-toggle-extents 'smiley-toggle-extents-ems)
+ (defalias 'smiley-buffer 'smiley-buffer-ems)
+ (defalias 'smiley-toggle-buffer 'smiley-toggle-buffer-ems))
+