Merge from gnulib
[emacs.git] / lisp / sb-image.el
blobb94978a8df2974077983d3dea579baaff6d62b01
1 ;;; sb-image --- Image management for speedbar
3 ;; Copyright (C) 1999-2003, 2005-2017 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: file, tags, tools
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Supporting Image display for Emacs 20 and less, Emacs 21, and XEmacs,
26 ;; is a challenging task, which doesn't take kindly to being byte compiled.
27 ;; When sharing speedbar.elc between these three applications, the Image
28 ;; support can get lost.
30 ;; By splitting out that hard part into this file, and avoiding byte
31 ;; compilation, one copy speedbar can support all these platforms together.
33 ;; This file requires the `image' package if it is available.
35 (require 'ezimage)
37 ;;; Code:
38 (defcustom speedbar-use-images ezimage-use-images
39 "Non-nil if speedbar should display icons."
40 :group 'speedbar
41 :version "21.1"
42 :type 'boolean)
44 (defalias 'defimage-speedbar 'defezimage)
46 (defvar speedbar-expand-image-button-alist
47 '(("<+>" . ezimage-directory-plus)
48 ("<->" . ezimage-directory-minus)
49 ("< >" . ezimage-directory)
50 ("[+]" . ezimage-page-plus)
51 ("[-]" . ezimage-page-minus)
52 ("[?]" . ezimage-page)
53 ("[ ]" . ezimage-page)
54 ("{+}" . ezimage-box-plus)
55 ("{-}" . ezimage-box-minus)
56 ("<M>" . ezimage-mail)
57 ("<d>" . ezimage-document-tag)
58 ("<i>" . ezimage-info-tag)
59 (" =>" . ezimage-tag)
60 (" +>" . ezimage-tag-gt)
61 (" ->" . ezimage-tag-v)
62 (">" . ezimage-tag)
63 ("@" . ezimage-tag-type)
64 (" @" . ezimage-tag-type)
65 ("*" . ezimage-checkout)
66 ("#" . ezimage-object)
67 ("!" . ezimage-object-out-of-date)
68 ("//" . ezimage-label)
69 ("%" . ezimage-lock)
71 "List of text and image associations.")
73 (defun speedbar-insert-image-button-maybe (start length)
74 "Insert an image button based on text starting at START for LENGTH chars.
75 If buttontext is unknown, just insert that text.
76 If we have an image associated with it, use that image."
77 (when speedbar-use-images
78 (let ((ezimage-expand-image-button-alist
79 speedbar-expand-image-button-alist))
80 (ezimage-insert-image-button-maybe start length))))
82 (defun speedbar-image-dump ()
83 "Dump out the current state of the Speedbar image alist.
84 See `speedbar-expand-image-button-alist' for details."
85 (interactive)
86 (with-output-to-temp-buffer "*Speedbar Images*"
87 (with-current-buffer "*Speedbar Images*"
88 (goto-char (point-max))
89 (insert "Speedbar image cache.\n\n")
90 (let ((start (point)) (end nil))
91 (insert "Image\tText\tImage Name")
92 (setq end (point))
93 (insert "\n")
94 (put-text-property start end 'face 'underline))
95 (let ((ia speedbar-expand-image-button-alist))
96 (while ia
97 (let ((start (point)))
98 (insert (car (car ia)))
99 (insert "\t")
100 (speedbar-insert-image-button-maybe start
101 (length (car (car ia))))
102 (insert (car (car ia)) "\t" (format "%s" (cdr (car ia))) "\n"))
103 (setq ia (cdr ia)))))))
105 (provide 'sb-image)
107 ;;; sb-image.el ends here