gnus-ems.el 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
  2. ;; Copyright (C) 1995-2012 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Keywords: news
  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. ;;; Code:
  18. (eval-when-compile
  19. (require 'cl)
  20. (require 'ring))
  21. ;;; Function aliases later to be redefined for XEmacs usage.
  22. (defvar gnus-mouse-2 [mouse-2])
  23. (defvar gnus-down-mouse-3 [down-mouse-3])
  24. (defvar gnus-down-mouse-2 [down-mouse-2])
  25. (defvar gnus-widget-button-keymap nil)
  26. (defvar gnus-mode-line-modified
  27. (if (featurep 'xemacs)
  28. '("--**-" . "-----")
  29. '("**" "--")))
  30. (eval-and-compile
  31. (autoload 'gnus-xmas-define "gnus-xmas")
  32. (autoload 'gnus-xmas-redefine "gnus-xmas"))
  33. (autoload 'gnus-get-buffer-create "gnus")
  34. (autoload 'nnheader-find-etc-directory "nnheader")
  35. (autoload 'smiley-region "smiley")
  36. (defun gnus-kill-all-overlays ()
  37. "Delete all overlays in the current buffer."
  38. (let* ((overlayss (overlay-lists))
  39. (buffer-read-only nil)
  40. (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
  41. (while overlays
  42. (delete-overlay (pop overlays)))))
  43. ;;; Mule functions.
  44. (defun gnus-mule-max-width-function (el max-width)
  45. `(let* ((val (eval (, el)))
  46. (valstr (if (numberp val)
  47. (int-to-string val) val)))
  48. (if (> (length valstr) ,max-width)
  49. (truncate-string-to-width valstr ,max-width)
  50. valstr)))
  51. (eval-and-compile
  52. (if (featurep 'xemacs)
  53. (gnus-xmas-define)
  54. (defvar gnus-mouse-face-prop 'mouse-face
  55. "Property used for highlighting mouse regions.")))
  56. (defvar gnus-tmp-unread)
  57. (defvar gnus-tmp-replied)
  58. (defvar gnus-tmp-score-char)
  59. (defvar gnus-tmp-indentation)
  60. (defvar gnus-tmp-opening-bracket)
  61. (defvar gnus-tmp-lines)
  62. (defvar gnus-tmp-name)
  63. (defvar gnus-tmp-closing-bracket)
  64. (defvar gnus-tmp-subject-or-nil)
  65. (defvar gnus-check-before-posting)
  66. (defvar gnus-mouse-face)
  67. (defvar gnus-group-buffer)
  68. (defun gnus-ems-redefine ()
  69. (cond
  70. ((featurep 'xemacs)
  71. (gnus-xmas-redefine))
  72. ((featurep 'mule)
  73. ;; Mule and new Emacs definitions
  74. ;; [Note] Now there are three kinds of mule implementations,
  75. ;; original MULE, XEmacs/mule and Emacs 20+ including
  76. ;; MULE features. Unfortunately these APIs are different. In
  77. ;; particular, Emacs (including original Mule) and XEmacs are
  78. ;; quite different. However, this version of Gnus doesn't support
  79. ;; anything other than XEmacs 20+ and Emacs 20.3+.
  80. ;; Predicates to check are following:
  81. ;; (boundp 'MULE) is t only if Mule (original; anything older than
  82. ;; Mule 2.3) is running.
  83. ;; (featurep 'mule) is t when other mule variants are running.
  84. ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
  85. ;; (featurep 'xemacs). In this case, the implementation for
  86. ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
  87. (defvar gnus-summary-display-table nil
  88. "Display table used in summary mode buffers.")
  89. (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
  90. (when (boundp 'gnus-check-before-posting)
  91. (setq gnus-check-before-posting
  92. (delq 'long-lines
  93. (delq 'control-chars gnus-check-before-posting))))
  94. (defun gnus-summary-line-format-spec ()
  95. (insert gnus-tmp-unread gnus-tmp-replied
  96. gnus-tmp-score-char gnus-tmp-indentation)
  97. (put-text-property
  98. (point)
  99. (progn
  100. (insert
  101. gnus-tmp-opening-bracket
  102. (format "%4d: %-20s"
  103. gnus-tmp-lines
  104. (if (> (length gnus-tmp-name) 20)
  105. (truncate-string-to-width gnus-tmp-name 20)
  106. gnus-tmp-name))
  107. gnus-tmp-closing-bracket)
  108. (point))
  109. gnus-mouse-face-prop gnus-mouse-face)
  110. (insert " " gnus-tmp-subject-or-nil "\n")))))
  111. ;; Clone of `appt-select-lowest-window' in appt.el.
  112. (defun gnus-select-lowest-window ()
  113. "Select the lowest window on the frame."
  114. (let ((lowest-window (selected-window))
  115. (bottom-edge (nth 3 (window-edges))))
  116. (walk-windows (lambda (w)
  117. (let ((next-bottom-edge (nth 3 (window-edges w))))
  118. (when (< bottom-edge next-bottom-edge)
  119. (setq bottom-edge next-bottom-edge
  120. lowest-window w)))))
  121. (select-window lowest-window)))
  122. (defun gnus-region-active-p ()
  123. "Say whether the region is active."
  124. (and (boundp 'transient-mark-mode)
  125. transient-mark-mode
  126. (boundp 'mark-active)
  127. mark-active))
  128. (defun gnus-mark-active-p ()
  129. "Non-nil means the mark and region are currently active in this buffer."
  130. mark-active) ; aliased to region-exists-p in XEmacs.
  131. (autoload 'gnus-alive-p "gnus-util")
  132. (autoload 'mm-disable-multibyte "mm-util")
  133. ;;; Image functions.
  134. (defun gnus-image-type-available-p (type)
  135. (and (fboundp 'image-type-available-p)
  136. (image-type-available-p type)
  137. (if (fboundp 'display-images-p)
  138. (display-images-p)
  139. t)))
  140. (defun gnus-create-image (file &optional type data-p &rest props)
  141. (let ((face (plist-get props :face)))
  142. (when face
  143. (setq props (plist-put props :foreground (face-foreground face)))
  144. (setq props (plist-put props :background (face-background face))))
  145. (ignore-errors
  146. (apply 'create-image file type data-p props))))
  147. (defun gnus-put-image (glyph &optional string category)
  148. (let ((point (point)))
  149. (insert-image glyph (or string " "))
  150. (put-text-property point (point) 'gnus-image-category category)
  151. (unless string
  152. (put-text-property (1- (point)) (point)
  153. 'gnus-image-text-deletable t))
  154. glyph))
  155. (defun gnus-remove-image (image &optional category)
  156. "Remove the image matching IMAGE and CATEGORY found first."
  157. (let ((start (point-min))
  158. val end)
  159. (while (and (not end)
  160. (or (setq val (get-text-property start 'display))
  161. (and (setq start
  162. (next-single-property-change start 'display))
  163. (setq val (get-text-property start 'display)))))
  164. (setq end (or (next-single-property-change start 'display)
  165. (point-max)))
  166. (if (and (equal val image)
  167. (equal (get-text-property start 'gnus-image-category)
  168. category))
  169. (progn
  170. (put-text-property start end 'display nil)
  171. (when (get-text-property start 'gnus-image-text-deletable)
  172. (delete-region start end)))
  173. (unless (= end (point-max))
  174. (setq start end
  175. end nil))))))
  176. (defmacro gnus-string-mark-left-to-right (string)
  177. (if (fboundp 'bidi-string-mark-left-to-right)
  178. `(bidi-string-mark-left-to-right ,string)
  179. string))
  180. (eval-and-compile
  181. ;; XEmacs does not have window-inside-pixel-edges
  182. (defalias 'gnus-window-inside-pixel-edges
  183. (if (fboundp 'window-inside-pixel-edges)
  184. 'window-inside-pixel-edges
  185. 'window-pixel-edges))
  186. (if (fboundp 'set-process-plist)
  187. (progn
  188. (defalias 'gnus-set-process-plist 'set-process-plist)
  189. (defalias 'gnus-process-plist 'process-plist)
  190. (defalias 'gnus-process-get 'process-get)
  191. (defalias 'gnus-process-put 'process-put))
  192. (defun gnus-set-process-plist (process plist)
  193. "Replace the plist of PROCESS with PLIST. Returns PLIST."
  194. (put 'gnus-process-plist-internal process plist))
  195. (defun gnus-process-plist (process)
  196. "Return the plist of PROCESS."
  197. ;; This form works but can't prevent the plist data from
  198. ;; growing infinitely.
  199. ;;(get 'gnus-process-plist-internal process)
  200. (let* ((plist (symbol-plist 'gnus-process-plist-internal))
  201. (tem (memq process plist)))
  202. (prog1
  203. (cadr tem)
  204. ;; Remove it from the plist data.
  205. (when tem
  206. (if (eq plist tem)
  207. (progn
  208. (setcar plist (caddr plist))
  209. (setcdr plist (or (cdddr plist) '(nil))))
  210. (setcdr (nthcdr (- (length plist) (length tem) 1) plist)
  211. (cddr tem)))))))
  212. (defun gnus-process-get (process propname)
  213. "Return the value of PROCESS' PROPNAME property.
  214. This is the last value stored with `(gnus-process-put PROCESS PROPNAME VALUE)'."
  215. (plist-get (gnus-process-plist process) propname))
  216. (defun gnus-process-put (process propname value)
  217. "Change PROCESS' PROPNAME property to VALUE.
  218. It can be retrieved with `(gnus-process-get PROCESS PROPNAME)'."
  219. (gnus-set-process-plist process
  220. (plist-put (gnus-process-plist process)
  221. propname value)))))
  222. (provide 'gnus-ems)
  223. ;;; gnus-ems.el ends here