comparison lisp/gnus/smiley-ems.el @ 31818:1e15c63f0711

(smiley-region): Test if display-graphic-p bound (for Emacs 20). Tidy somewhat.
author Dave Love <fx@gnu.org>
date Thu, 21 Sep 2000 16:28:06 +0000
parents ff5eb810214a
children 6ee543d2c641
comparison
equal deleted inserted replaced
31817:e23774b771e1 31818:1e15c63f0711
46 :type 'directory 46 :type 'directory
47 :group 'smiley) 47 :group 'smiley)
48 48
49 ;; The XEmacs version has a baroque, if not rococo, set of these. 49 ;; The XEmacs version has a baroque, if not rococo, set of these.
50 (defcustom smiley-regexp-alist 50 (defcustom smiley-regexp-alist
51 ;; Perhaps :-) should be distinct -- it does appear in the Jargon File.
51 '(("\\([:;]-?)\\)\\W" 1 "smile.xbm") 52 '(("\\([:;]-?)\\)\\W" 1 "smile.xbm")
52 ("\\(:-[/\\]\\)\\W" 1 "wry.xbm") 53 ("\\(:-[/\\]\\)\\W" 1 "wry.xbm")
53 ("\\(:-[({]\\)\\W" 1 "frown.xbm")) 54 ("\\(:-[({]\\)\\W" 1 "frown.xbm"))
54 "*A list of regexps to map smilies to images. 55 "*A list of regexps to map smilies to images.
55 The elements are (REGEXP MATCH FILE), where MATCH is the submatch in 56 The elements are (REGEXP MATCH FILE), where MATCH is the submatch in
89 90
90 ;;;###autoload 91 ;;;###autoload
91 (defun smiley-region (start end) 92 (defun smiley-region (start end)
92 "Replace in the region `smiley-regexp-alist' matches with corresponding images." 93 "Replace in the region `smiley-regexp-alist' matches with corresponding images."
93 (interactive "r") 94 (interactive "r")
94 (when (display-graphic-p) 95 (when (and (fboundp 'display-graphic-p)
96 (display-graphic-p))
95 (mapc (lambda (o) 97 (mapc (lambda (o)
96 (if (eq 'smiley (overlay-get o 'smiley)) 98 (if (eq 'smiley (overlay-get o 'smiley))
97 (delete-overlay o))) 99 (delete-overlay o)))
98 (overlays-in start end)) 100 (overlays-in start end))
99 (unless smiley-cached-regexp-alist 101 (unless smiley-cached-regexp-alist
100 (smiley-update-cache)) 102 (smiley-update-cache))
101 (save-excursion 103 (save-excursion
102 (let ((beg (or start (point-min))) 104 (let ((beg (or start (point-min)))
103 buffer-read-only entry beg group overlay image) 105 group overlay image)
104 (dolist (entry smiley-cached-regexp-alist) 106 (dolist (entry smiley-cached-regexp-alist)
105 (setq group (nth 1 entry)) 107 (setq group (nth 1 entry)
108 image (nth 2 entry))
106 (goto-char beg) 109 (goto-char beg)
107 (while (re-search-forward (car entry) end t) 110 (while (re-search-forward (car entry) end t)
108 (when image 111 (when image
109 (setq overlay (make-overlay (match-beginning group) 112 (setq overlay (make-overlay (match-beginning group)
110 (match-end group))) 113 (match-end group)))
111 (overlay-put overlay 114 (overlay-put overlay
112 'display `(when smiley-active ,@(nth 2 entry))) 115 'display `(when smiley-active ,@image))
113 (overlay-put overlay 'mouse-face 'highlight) 116 (overlay-put overlay 'mouse-face 'highlight)
114 (overlay-put overlay 'smiley t) 117 (overlay-put overlay 'smiley t)
115 (overlay-put overlay 118 (overlay-put overlay
116 'help-echo "mouse-2: toggle smilies in buffer") 119 'help-echo "mouse-2: toggle smilies in buffer")
117 (overlay-put overlay 'keymap smiley-mouse-map)))))) 120 (overlay-put overlay 'keymap smiley-mouse-map))))))