sb-image.el 3.5 KB

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