Debian Codegraph @

mew-gemacs.el

raw
1 ;;; mew-gemacs.el --- Environment of Graphical Emacs for Mew
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Jun 22, 2000
5
6 ;;; Code:
7
8 (require 'mew)
9
10 (defvar mew-prog-pamscale (or (executable-find "pamscale") "pnmscale"))
11 (defvar mew-prog-pamscale-opt
12 (cond
13 ((string-match "pamscale" mew-prog-pamscale) "-xyfit")
14 ((string-match "pnmscale" mew-prog-pamscale) "-xysize")))
15
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;
18 ;;; Menu setting
19 ;;;
20
21 (easy-menu-define
22 mew-summary-mode-menu
23 mew-summary-mode-map
24 "Menu used in Summary mode."
25 mew-summary-mode-menu-spec)
26
27 (easy-menu-define
28 mew-message-mode-menu
29 mew-message-mode-map
30 "Menu used in Message mode."
31 mew-message-mode-menu-spec)
32
33 (easy-menu-define
34 mew-draft-mode-menu
35 mew-draft-mode-map
36 "Menu used in Draft mode."
37 mew-draft-mode-menu-spec)
38
39 (easy-menu-define
40 mew-header-mode-menu
41 mew-header-mode-map
42 "Menu used in Header mode."
43 mew-header-mode-menu-spec)
44
45 (easy-menu-define
46 mew-draft-header-menu
47 mew-draft-header-map
48 "Menu used in Draft mode."
49 mew-draft-mode-menu-spec)
50
51 (easy-menu-define
52 mew-draft-attach-menu
53 mew-draft-attach-map
54 "Menu used in Draft mode."
55 mew-draft-mode-menu-spec)
56
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 ;;;
59 ;;; Toolbar functions
60 ;;;
61
62 (defvar mew-summary-toolbar nil)
63 (defvar mew-draft-toolbar nil)
64
65 (defun mew-toolbar-make (map alist)
66 (let ((tool-bar-map (make-sparse-keymap)) ;; for tool-bar-add-item-from-menu
67 (data-directory mew-icon-directory))
68 (dolist (a alist)
69 (if (fboundp 'tool-bar-local-item-from-menu)
70 ;; Emacs 21.3.50 or later
71 (tool-bar-local-item-from-menu (car a) (cdr a) tool-bar-map map)
72 ;; Emacs 21.3 or earlier
73 ;; The target map is tool-bar-map
74 (tool-bar-add-item-from-menu (car a) (cdr a) map)))
75 tool-bar-map))
76
77 (defun mew-summary-setup-decoration ()
78 (if mew-icon-p
79 (set (make-local-variable 'tool-bar-map)
80 (mew-toolbar-make mew-summary-mode-map mew-summary-toolbar-spec))))
81
82 (defun mew-message-setup-decoration ()
83 (if mew-icon-p
84 (set (make-local-variable 'tool-bar-map)
85 (mew-toolbar-make mew-message-mode-map mew-message-toolbar-spec))))
86
87 (defun mew-draft-setup-decoration ()
88 (if mew-icon-p
89 (set (make-local-variable 'tool-bar-map)
90 (mew-toolbar-make mew-draft-mode-map mew-draft-toolbar-spec))))
91
92 (defun mew-header-setup-decoration ()
93 (if mew-icon-p
94 (set (make-local-variable 'tool-bar-map)
95 (mew-toolbar-make mew-header-mode-map mew-header-toolbar-spec))))
96
97 (defun mew-summary-toolbar-update ())
98 (defun mew-message-toolbar-update ())
99 (defun mew-draft-toolbar-update ())
100 (defun mew-header-toolbar-update ())
101
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;;;
104 ;;; End of messages
105 ;;;
106
107 (defun mew-message-set-end-of-message ()
108 (overlay-put (mew-minfo-get-eom) 'before-string mew-end-of-message-string))
109
110 (defun mew-message-set-end-of-part ()
111 (overlay-put (mew-minfo-get-eom) 'before-string mew-end-of-part-string))
112
113 (defun mew-message-set-end-of-nil ()
114 (overlay-put (mew-minfo-get-eom) 'before-string nil))
115
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 ;;;
118 ;;; Veil
119 ;;;
120
121 (defun mew-header-veil-make ()
122 (let ((ov (mew-overlay-make 1 1)))
123 (overlay-put ov 'invisible t)
124 (overlay-put ov 'before-string mew-header-veil-string)
125 (delete-overlay ov) ;; detach from the buffer
126 ov))
127
128 (defun mew-toggle-header-veil (ov)
129 (cond
130 ((overlay-get ov 'invisible)
131 (overlay-put ov 'invisible nil)
132 (overlay-put ov 'before-string nil))
133 (t
134 (overlay-put ov 'invisible t)
135 (overlay-put ov 'before-string mew-header-veil-string))))
136
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 ;;;
139 ;;; Image
140 ;;;
141
142 (defcustom mew-image-display-resize t
143 "*If non-nil, image will be displayed with fitting to frame size"
144 :group 'mew-message
145 :type 'boolean)
146
147 (defcustom mew-image-display-resize-always nil
148 "*If nil, only a larger image than frame size will be displayed
149 with fitting to frame size"
150 :group 'mew-message
151 :type 'boolean)
152
153 (defcustom mew-image-display-resize-care-height t
154 "*If nil, image will be displayed with fitting to only frame width"
155 :group 'mew-message
156 :type 'boolean)
157
158 (defcustom mew-image-width-margin 45
159 "*A value for width margin to display image when resizing"
160 :group 'mew-message
161 :type 'integer)
162
163 (defcustom mew-image-height-margin 200
164 "A value for height margin to display image when resizing"
165 :group 'mew-message
166 :type 'integer)
167
168 (defvar mew-image-l-endian ?\x49)
169 (defvar mew-image-b-endian ?\x4d)
170
171 (defun mew-image-inline-p (format)
172 ;; display-graphic-p
173 (or (and window-system (image-type-available-p format))
174 (let* ((ent (mew-image-format-ent format))
175 (prog (mew-image-get-prog ent)))
176 (and prog (mew-which-exec prog) t))))
177
178 (defun mew-img-get-n (op len)
179 (let* ((size 0))
180 (if (eq op ?\x49) ; I(?\x49) or M(?\x4d)
181 (dotimes (n len)
182 (setq size (+ size (* (char-after) (expt ?\x100 n))))
183 (forward-char))
184 (while (< 0 len)
185 (setq len (- len 1))
186 (setq size (+ size (* (char-after) (expt ?\x100 len))))
187 (forward-char)))
188 size))
189
190 (defun mew-jpeg-size ()
191 (let (c size width height)
192 (save-excursion
193 (catch 'loop
194 (while t
195 (setq c (char-after))
196 (forward-char)
197 (unless (eq c ?\xff)
198 (throw 'loop nil))
199 (setq c (char-after))
200 (forward-char)
201 (cond
202 ((or (eq c ?\xd8) ;; SOI
203 (eq c ?\xd9) ;; EOI
204 (and (>= c ?\xd0) (<= c ?\xd7)))) ;; RSTm
205 ((or (eq c ?\xc0) (eq c ?\xc2))
206 (forward-char 3)
207 (setq height (mew-img-get-n mew-image-b-endian 2))
208 (setq width (mew-img-get-n mew-image-b-endian 2))
209 (backward-char)
210 (throw 'loop nil))
211 ((and (>= c ?\xc1) (<= c ?\xfe))
212 (setq size (mew-img-get-n mew-image-b-endian 2))
213 (forward-char (- size 2)))
214 (t
215 (throw 'loop nil))))))
216 (cons width height)))
217
218 (defun mew-png-size ()
219 (let (width height)
220 (save-excursion
221 (forward-char 18)
222 ;; length is four bytes
223 ;; but we takes lower two bytes
224 (setq width (mew-img-get-n mew-image-b-endian 2))
225 (forward-char 2)
226 (setq height (mew-img-get-n mew-image-b-endian 2))
227 (cons width height))))
228
229 (defun mew-gif-size ()
230 (let (width height)
231 (save-excursion
232 (forward-char 6)
233 (setq width (mew-img-get-n mew-image-l-endian 2))
234 (setq height (mew-img-get-n mew-image-l-endian 2))
235 (cons width height))))
236
237 (defun mew-tiff-size ()
238 (let (endian size entry tag width height)
239 (save-excursion
240 (setq endian (char-after))
241 (forward-char 4)
242 (setq size (mew-img-get-n endian 4))
243 (forward-char (- size 8)) ;; jump to IFD
244 ;; IFD
245 (setq entry (mew-img-get-n endian 2))
246 (catch 'loop
247 (while t
248 (setq entry (- entry 1))
249 (setq tag (mew-img-get-n endian 2))
250 (cond
251 ((eq tag 256)
252 (forward-char 6)
253 (setq width (mew-img-get-n endian 2))
254 (forward-char 2))
255 ((eq tag 257)
256 (forward-char 6)
257 (setq height (mew-img-get-n endian 2))
258 (forward-char 2))
259 (t
260 (forward-char 10)))
261 (unless (< 1 entry)
262 (throw 'loop nil)))))
263 (cons width height)))
264
265 (defun mew-bmp-size ()
266 (let (width height)
267 (save-excursion
268 (forward-char 18)
269 ;; length is four bytes
270 ;; but we takes lower two bytes
271 (setq width (mew-img-get-n mew-image-l-endian 2))
272 (forward-char 2)
273 (setq height (mew-img-get-n mew-image-l-endian 2))
274 (cons width height))))
275
276 (defun mew-pbm-size ()
277 (let (width height)
278 (save-excursion
279 (cond ((looking-at "^P[1-6][\t\n\v\f\r ]*\\(#[^\r\n]*[\r\n][\t\n\v\f\r ]*\\)*\\([0-9]+\\)[\t\n\v\f\r ]*\\(#[^\r\n]*[\r\n][\t\n\v\f\r ]*\\)*\\([0-9]+\\)[\t\n\v\f\r #]") ;; PBM, PGM, PPM, PNM
280 (setq width (string-to-number (match-string 2)))
281 (setq height (string-to-number (match-string 4))))
282 ((looking-at "^P7$") ;; PAM
283 (when (re-search-forward "^WIDTH[ \t]+\\([0-9]+\\)[ \t]*$" nil t)
284 (setq width (string-to-number (match-string 1))))
285 (goto-char (point-min))
286 (when (re-search-forward "^HEIGHT[ \t]+\\([0-9]+\\)[ \t]*$" nil t)
287 (setq height (string-to-number (match-string 1))))))
288 (cons width height))))
289
290 (defvar mew-image-alist
291 '((jpeg mew-jpeg-size "jpegtopnm" "pnmtojpeg")
292 (png mew-png-size "pngtopam" "pnmtopng")
293 (gif mew-gif-size "giftopnm" "pamtogif")
294 (tiff mew-tiff-size "tifftopnm" "pamtotiff")
295 (xwd nil "xwdtopnm" "pnmtoxwd")
296 (xbm nil "xbmtopbm" "pbmtoxbm")
297 (xpm nil "xpmtoppm" "ppmtoxpm")
298 (bmp mew-bmp-size "bmptopnm" "ppmtobmp")
299 (PCX nil "pcxtoppm" "ppmtopcx")
300 (TGA nil "tgatoppm" "pamtotga")
301 (ICO nil "winicontoppm" "ppmtowinicon")
302 (pbm mew-pbm-size nil nil)
303 (PAM mew-pbm-size "pamtopnm" "pamtopam")))
304
305 (defun mew-image-format-ent (format)
306 (assoc format mew-image-alist))
307
308 (defun mew-image-get-func (ent)
309 (nth 1 ent))
310
311 (defun mew-image-get-prog (ent)
312 (nth 2 ent))
313
314 (defun mew-image-get-prog2 (ent)
315 (nth 3 ent))
316
317 (defun mew-mime-image (cache begin end format)
318 (message "Loading image...")
319 (set-buffer (mew-buffer-message))
320 (let* ((width (- (frame-pixel-width (selected-frame)) mew-image-width-margin))
321 (height (- (frame-pixel-height (selected-frame)) mew-image-height-margin))
322 (ent (mew-image-format-ent format))
323 (prog (mew-image-get-prog ent))
324 (func-size (mew-image-get-func ent))
325 image-size image-width image-height image)
326 (with-temp-buffer
327 (mew-plet
328 (insert-buffer-substring cache begin end)
329 (mew-set-buffer-multibyte nil)
330 (goto-char (point-min))
331 (cond ((and mew-image-display-resize
332 (not mew-image-display-resize-always)
333 func-size)
334 (setq image-size (funcall func-size))
335 (setq image-width (car image-size))
336 (setq image-height (cdr image-size)))
337 (t
338 (setq image-width nil)
339 (setq image-height nil)))
340 (when (and (not (image-type-available-p format))
341 prog (mew-which-exec prog))
342 (message "Converting image...")
343 (call-process-region (point-min) (point-max) prog
344 t '(t nil) nil)
345 (setq format 'pbm)
346 (unless (or image-width image-height)
347 (goto-char (point-min))
348 (setq image-size (mew-pbm-size))
349 (setq image-width (car image-size))
350 (setq image-height (cdr image-size)))
351 (message "Converting image...done"))
352 (when (and mew-image-display-resize
353 (or mew-image-display-resize-always
354 (and image-width image-height
355 (or (< width image-width)
356 (and mew-image-display-resize-care-height
357 (< height image-height)))))
358 (or (eq format 'pbm) (mew-which-exec prog)))
359 (message "Resizing image...")
360 (unless (eq format 'pbm)
361 (call-process-region (point-min) (point-max) prog
362 t '(t nil) nil)
363 (setq format 'pbm))
364 (if mew-image-display-resize-care-height
365 (call-process-region (point-min) (point-max) mew-prog-pamscale
366 t '(t nil) nil
367 mew-prog-pamscale-opt
368 (format "%d" width)
369 (format "%d" height))
370 (call-process-region (point-min) (point-max) mew-prog-pamscale
371 t '(t nil) nil
372 "-xsize" (format "%d" width)))
373 (message "Resizing image...done"))
374 (setq image (mew-buffer-substring (point-min) (point-max)))))
375 (mew-elet
376 (condition-case nil
377 (insert-image (mew-create-image image format t))
378 (error ()))))
379 (goto-char (point-min))
380 (message "Loading image...done"))
381
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 ;;;
384 ;;; Transient
385 ;;;
386
387 (defun mew-mark-active-p ()
388 (and transient-mark-mode mark-active))
389
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ;;;
392 ;;; X Face
393 ;;;
394
395 (defun mew-x-face-create ()
396 (mew-create-image
397 (string-as-unibyte (mew-buffer-substring (point-min) (point-max)))
398 nil t))
399
400 (defun mew-x-face-display (xface)
401 (save-excursion
402 (goto-char (point-min))
403 (let ((regex2 (concat "^\\(" mew-from: "\\).*")))
404 (when (re-search-forward regex2 nil t)
405 (goto-char (match-end 1))
406 (insert-image xface)))))
407
408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 ;;;
410 ;;; SSL/SSH/TLS notification
411 ;;;
412
413 (defvar mew-secure-format nil)
414
415 ;; Emacs 21.x has a bug that an image cannot be displayed
416 ;; if it is specified in mode-line-process.
417
418 (defvar mew-secure-format2
419 (if (display-graphic-p)
420 (let ((data-directory mew-icon-directory))
421 (concat " " (propertize "Sec" 'display
422 (find-image '((:type xpm :file "mew-lock.xpm" :ascent center))))))
423 " [Sec]"))
424
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 ;;;
427 ;;; Click hack
428 ;;;
429
430 (define-key mew-message-mode-map [mouse-2] 'mew-browse-url-at-mouse)
431 (if (and (featurep 'emacs) ;; preventing XEmacs's byte compiler from hanging
432 (eq system-type 'darwin))
433 ;; for Mac
434 (define-key mew-message-mode-map [M-down-mouse-1] 'mew-browse-url-at-mouse))
435
436 (provide 'mew-gemacs)
437
438 ;;; Copyright Notice:
439
440 ;; Copyright (C) 1997-2015 Mew developing team.
441 ;; All rights reserved.
442
443 ;; Redistribution and use in source and binary forms, with or without
444 ;; modification, are permitted provided that the following conditions
445 ;; are met:
446 ;;
447 ;; 1. Redistributions of source code must retain the above copyright
448 ;; notice, this list of conditions and the following disclaimer.
449 ;; 2. Redistributions in binary form must reproduce the above copyright
450 ;; notice, this list of conditions and the following disclaimer in the
451 ;; documentation and/or other materials provided with the distribution.
452 ;; 3. Neither the name of the team nor the names of its contributors
453 ;; may be used to endorse or promote products derived from this software
454 ;; without specific prior written permission.
455 ;;
456 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
457 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
458 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
459 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
460 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
461 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
462 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
463 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
464 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
465 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
466 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
467
468 ;;; mew-gemacs.el ends here