*** empty log message ***
[gnus] / lisp / gnus-xmas.el
1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'text-props)
28 (eval-when-compile (require 'cl))
29 (defvar menu-bar-mode t)
30
31 (defvar gnus-xmas-glyph-directory nil
32   "*Directory where Gnus logos and icons are located.
33 If this variable is nil, Gnus will try to locate the directory
34 automatically.")
35
36 ;;; Internal variables.
37
38 (defvar gnus-xmas-logo (make-glyph (make-specifier 'image)))
39
40 ;; Don't warn about these undefined variables.
41
42 (defvar gnus-group-mode-hook)
43 (defvar gnus-summary-mode-hook)
44 (defvar gnus-article-mode-hook)
45
46 ;;defined in gnus.el
47 (defvar gnus-active-hashtb)
48 (defvar gnus-article-buffer)
49 (defvar gnus-auto-center-summary)
50 (defvar gnus-buffer-list)
51 (defvar gnus-current-headers)
52 (defvar gnus-level-killed)
53 (defvar gnus-level-zombie)
54 (defvar gnus-newsgroup-bookmarks)
55 (defvar gnus-newsgroup-dependencies)
56 (defvar gnus-newsgroup-selected-overlay)
57 (defvar gnus-newsrc-hashtb)
58 (defvar gnus-read-mark)
59 (defvar gnus-refer-article-method)
60 (defvar gnus-reffed-article-number)
61 (defvar gnus-unread-mark)
62 (defvar gnus-version)
63 (defvar gnus-view-pseudos)
64 (defvar gnus-view-pseudos-separately)
65 (defvar gnus-visual)
66 (defvar gnus-zombie-list)
67 ;;defined in gnus-msg.el
68 (defvar gnus-article-copy)
69 (defvar gnus-check-before-posting)
70 ;;defined in gnus-vis.el
71 (defvar gnus-article-button-face)
72 (defvar gnus-article-mouse-face)
73 (defvar gnus-summary-selected-face)
74 (defvar gnus-group-reading-menu)
75 (defvar gnus-group-group-menu)
76 (defvar gnus-group-misc-menu)
77 (defvar gnus-summary-article-menu)
78 (defvar gnus-summary-thread-menu)
79 (defvar gnus-summary-misc-menu)
80 (defvar gnus-summary-post-menu)
81 (defvar gnus-summary-kill-menu)
82 (defvar gnus-article-article-menu)
83 (defvar gnus-article-treatment-menu)
84 (defvar gnus-mouse-2)
85 (defvar standard-display-table)
86
87 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
88   "You should NEVER use this function.  It is ideologically blasphemous.
89 It is provided only to ease porting of broken FSF Emacs programs."
90   (if (and (stringp buffer) (not (setq buffer (get-buffer buffer))))
91       nil
92     (map-extents (lambda (extent ignored)
93                    (remove-text-properties 
94                     start end
95                     (list (extent-property extent 'text-prop) nil)
96                     buffer))
97                  buffer start end nil nil 'text-prop)
98     (add-text-properties start end props buffer)))
99
100 (defun gnus-xmas-highlight-selected-summary ()
101   ;; Highlight selected article in summary buffer
102   (if gnus-summary-selected-face
103       (progn
104         (if gnus-newsgroup-selected-overlay
105             (delete-extent gnus-newsgroup-selected-overlay))
106         (setq gnus-newsgroup-selected-overlay 
107               (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
108         (set-extent-face gnus-newsgroup-selected-overlay
109                          gnus-summary-selected-face))))
110
111 (defun gnus-xmas-summary-recenter ()
112   (let* ((top (cond ((< (window-height) 4) 0)
113                     ((< (window-height) 7) 1)
114                     (t 2)))
115          (height (- (window-height) 2))
116          (bottom (save-excursion (goto-char (point-max))
117                                  (forward-line (- height))
118                                  (point)))
119          (window (get-buffer-window (current-buffer))))
120     (and 
121      ;; The user has to want it,
122      gnus-auto-center-summary 
123      ;; the article buffer must be displayed,
124      (get-buffer-window gnus-article-buffer)
125      ;; Set the window start to either `bottom', which is the biggest
126      ;; possible valid number, or the second line from the top,
127      ;; whichever is the least.
128      (set-window-start
129       window (min bottom (save-excursion
130                            (forward-line (- top)) (point)))))))
131
132 (defun gnus-xmas-group-remove-excess-properties ()
133   (let ((end (point))
134         (beg (progn (forward-line -1) (point))))
135     (remove-text-properties (1+ beg) end '(gnus-group nil))
136     (remove-text-properties 
137      beg end 
138      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
139     (goto-char end)))
140                   
141 (defun gnus-xmas-topic-remove-excess-properties ()
142   (let ((end (point))
143         (beg (progn (forward-line -1) (point))))
144     (remove-text-properties beg end '(gnus-group nil))
145     (goto-char end)))
146
147 (defun gnus-xmas-extent-start-open (point)
148   (map-extents (lambda (extent arg)
149                  (set-extent-property extent 'start-open t))
150                nil point (min (1+ (point)) (point-max))))
151                   
152 (defun gnus-xmas-copy-article-buffer (&optional article-buffer)
153   (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
154   (buffer-disable-undo gnus-article-copy)
155   (or (memq gnus-article-copy gnus-buffer-list)
156       (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
157   (let ((article-buffer (or article-buffer gnus-article-buffer))
158         buf)
159     (if (and (get-buffer article-buffer)
160              (buffer-name (get-buffer article-buffer)))
161         (save-excursion
162           (set-buffer article-buffer)
163           (widen)
164           (setq buf (buffer-substring (point-min) (point-max)))
165           (set-buffer gnus-article-copy)
166           (erase-buffer)
167           (insert (format "%s" buf))))))
168
169 (defun gnus-xmas-article-push-button (event)
170   "Check text under the mouse pointer for a callback function.
171 If the text under the mouse pointer has a `gnus-callback' property,
172 call it with the value of the `gnus-data' text property."
173   (interactive "e")
174   (set-buffer (window-buffer (event-window event)))
175   (let* ((pos (event-closest-point event))
176          (data (get-text-property pos 'gnus-data))
177          (fun (get-text-property pos 'gnus-callback)))
178     (if fun (funcall fun data))))
179
180 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
181   (set-extent-endpoints extent start end))
182
183 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
184 (defun gnus-xmas-article-add-button (from to fun &optional data)
185   "Create a button between FROM and TO with callback FUN and data DATA."
186   (and gnus-article-button-face
187        (gnus-overlay-put (gnus-make-overlay from to) 
188                          'face gnus-article-button-face))
189   (add-text-properties 
190    from to
191    (nconc
192     (and gnus-article-mouse-face
193          (list 'mouse-face gnus-article-mouse-face))
194     (list 'gnus-callback fun)
195     (and data (list 'gnus-data data))
196     (list 'highlight t))))
197
198 (defun gnus-xmas-window-top-edge (&optional window)
199   (nth 1 (window-pixel-edges window)))
200
201 (defun gnus-xmas-tree-minimize ()
202   (when (and gnus-tree-minimize-window
203              (not (one-window-p)))
204     (let* ((window-min-height 2)
205            (height (1+ (count-lines (point-min) (point-max))))
206            (min (max (1- window-min-height) height))
207            (tot (if (numberp gnus-tree-minimize-window)
208                     (min gnus-tree-minimize-window min)
209                   min))
210            (win (get-buffer-window (current-buffer)))
211            (wh (and win (1- (window-height win)))))
212       (when (and win
213                  (not (eq tot wh)))
214         (let ((selected (selected-window)))
215           (select-window win)
216           (enlarge-window (- tot wh))
217           (select-window selected))))))
218
219 ;; Select the lowest window on the frame.
220 (defun gnus-xmas-appt-select-lowest-window ()
221   (let* ((lowest-window (selected-window))
222          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
223          (last-window (previous-window))
224          (window-search t))
225     (while window-search
226       (let* ((this-window (next-window))
227              (next-bottom-edge (car (cdr (cdr (cdr 
228                                                (window-pixel-edges 
229                                                 this-window)))))))
230         (if (< bottom-edge next-bottom-edge)
231             (progn
232               (setq bottom-edge next-bottom-edge)
233               (setq lowest-window this-window)))
234
235         (select-window this-window)
236         (if (eq last-window this-window)
237             (progn
238               (select-window lowest-window)
239               (setq window-search nil)))))))
240
241 (defun gnus-xmas-group-menu-add ()
242   (easy-menu-add gnus-group-reading-menu)
243   (easy-menu-add gnus-group-group-menu)
244   (easy-menu-add gnus-group-misc-menu))
245
246 (defun gnus-xmas-summary-menu-add ()
247   (easy-menu-add gnus-summary-article-menu)
248   (easy-menu-add gnus-summary-thread-menu)
249   (easy-menu-add gnus-summary-misc-menu)
250   (easy-menu-add gnus-summary-post-menu)
251   (easy-menu-add gnus-summary-kill-menu)) 
252
253 (defun gnus-xmas-article-menu-add ()
254   (easy-menu-add gnus-article-article-menu)
255   (easy-menu-add gnus-article-treatment-menu))
256
257 (defun gnus-xmas-read-event-char ()
258   "Get the next event."
259   (let ((event (next-event)))
260     ;; We junk all non-key events.  Is this naughty?
261     (while (not (key-press-event-p event))
262       (setq event (next-event)))
263     (cons (and (key-press-event-p event) 
264               ; (numberp (event-key event))
265                (event-to-character event)) 
266           event)))
267
268 (defun gnus-xmas-seconds-since-epoch (date)
269   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
270   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
271                         (timezone-parse-date date)))
272          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
273                         (timezone-parse-time
274                          (aref (timezone-parse-date date) 3))))
275          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
276                         (timezone-parse-date "Jan 1 12:00:00 1970")))
277          (tday (- (timezone-absolute-from-gregorian 
278                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
279                   (timezone-absolute-from-gregorian 
280                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
281     (+ (nth 2 ttime)
282        (* (nth 1 ttime) 60)
283        (* (float (nth 0 ttime)) 60 60)
284        (* (float tday) 60 60 24))))
285
286 (defun gnus-xmas-define ()
287   (setq gnus-mouse-2 [button2])
288
289   (or (memq 'underline (list-faces))
290       (and (fboundp 'make-face)
291            (funcall (intern "make-face") 'underline)))
292   ;; Must avoid calling set-face-underline-p directly, because it
293   ;; is a defsubst in emacs19, and will make the .elc files non
294   ;; portable!
295   (or (face-differs-from-default-p 'underline)
296       (funcall (intern "set-face-underline-p") 'underline t))
297
298   (fset 'gnus-make-overlay 'make-extent)
299   (fset 'gnus-overlay-put 'set-extent-property)
300   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
301   (fset 'gnus-overlay-end 'extent-end-position)
302   (fset 'gnus-extent-detached-p 'extent-detached-p)
303       
304   (fset 'set-text-properties 'gnus-xmas-set-text-properties)
305
306   (fset 'nnheader-find-file-noselect 'gnus-xmas-find-file-noselect)
307
308   (or (boundp 'standard-display-table) (setq standard-display-table nil))
309
310   (defvar gnus-mouse-face-prop 'highlight)
311
312   (unless (fboundp 'encode-time)
313     (defun encode-time (sec minute hour day month year &optional zone)
314       (let ((seconds
315              (gnus-xmas-seconds-since-epoch
316               (timezone-make-arpa-date 
317                year month day (timezone-make-time-string hour minute sec)
318                zone))))
319         (list (floor (/ seconds (expt 2 16)))
320               (round (mod seconds (expt 2 16)))))))
321       
322   (defun gnus-byte-code (func)
323     "Return a form that can be `eval'ed based on FUNC."
324     (let ((fval (symbol-function func)))
325       (if (byte-code-function-p fval)
326           (list 'funcall fval)
327         (cons 'progn (cdr (cdr fval))))))
328       
329   ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
330   (defvar gnus-display-type (device-class)
331     "A symbol indicating the display Emacs is running under.
332 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
333 guesses this display attribute wrongly, either set this variable in
334 your `~/.emacs' or set the resource `Emacs.displayType' in your
335 `~/.Xdefaults'. See also `gnus-background-mode'.
336
337 This is a meta-variable that will affect what default values other
338 variables get.  You would normally not change this variable, but
339 pounce directly on the real variables themselves.")
340
341
342   (or (fboundp 'x-color-values)
343       (fset 'x-color-values 
344             (lambda (color)
345               (color-instance-rgb-components
346                (make-color-instance color)))))
347     
348   (defvar gnus-background-mode 
349     (let ((bg-resource 
350            (condition-case ()
351                (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
352              (error nil)))
353           (params (frame-parameters)))
354       (cond (bg-resource (intern (downcase bg-resource)))
355             ((and (assq 'background-color params)
356                   (< (apply '+ (x-color-values
357                                 (cdr (assq 'background-color params))))
358                      (/ (apply '+ (x-color-values "white")) 3)))
359              'dark)
360             (t 'light)))
361     "A symbol indicating the Emacs background brightness.
362 The symbol should be one of `light' or `dark'.
363 If Emacs guesses this frame attribute wrongly, either set this variable in
364 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
365 `~/.Xdefaults'.
366 See also `gnus-display-type'.
367
368 This is a meta-variable that will affect what default values other
369 variables get.  You would normally not change this variable, but
370 pounce directly on the real variables themselves.")
371   )
372
373
374
375 (defun gnus-xmas-redefine ()
376   "Redefine lots of Gnus functions for XEmacs."
377   (fset 'gnus-summary-make-display-table (lambda () nil))
378   (fset 'gnus-visual-turn-off-edit-menu 'identity)
379   (fset 'gnus-highlight-selected-summary
380         'gnus-xmas-highlight-selected-summary)
381   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
382   (fset 'gnus-group-remove-excess-properties
383         'gnus-xmas-group-remove-excess-properties)
384   (fset 'gnus-topic-remove-excess-properties
385         'gnus-xmas-topic-remove-excess-properties)
386   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
387   (fset 'gnus-copy-article-buffer 'gnus-xmas-copy-article-buffer)
388   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
389   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
390   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
391   (fset 'set-text-properties 'gnus-xmas-set-text-properties)
392   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
393   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
394   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
395
396   (or (fboundp 'appt-select-lowest-window)
397       (fset 'appt-select-lowest-window 
398             'gnus-xmas-appt-select-lowest-window))
399
400   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
401   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
402   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
403
404   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
405   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar))
406
407
408 ;;; XEmacs logo and toolbar.
409
410 (defun gnus-xmas-find-glyph-directory ()
411   (or gnus-xmas-glyph-directory ; We have a dir already...
412       (let ((path load-path)
413             dir)
414         ;; We try to find the dir by looking at the load path,
415         ;; stripping away the last component and adding "etc/".
416         (while path
417           (setq dir (concat
418                      (file-name-directory (directory-file-name (car path)))
419                      "etc/gnus/"))
420           (if (and (file-exists-p dir)
421                    (file-directory-p dir)
422                    (file-exists-p (concat dir "gnus-group-exit-icon-up.xpm")))
423               (setq gnus-xmas-glyph-directory dir
424                     path nil)
425             (setq path (cdr path))))
426         gnus-xmas-glyph-directory)))
427
428 (defun gnus-xmas-group-startup-message (&optional x y)
429   "Insert startup message in current buffer."
430   ;; Insert the message.
431   (gnus-xmas-find-glyph-directory)
432   (erase-buffer)
433   (let ((file (and gnus-xmas-glyph-directory
434                    (concat 
435                     (file-name-as-directory gnus-xmas-glyph-directory)
436                     "gnus.xpm"))))
437     (if (and (featurep 'xpm)
438              (not (equal (device-type) 'tty))
439              file (file-exists-p file))
440         (progn
441           (set-glyph-property gnus-xmas-logo 'image file)
442           (set-glyph-image gnus-xmas-logo file 'global 'x)
443
444           (insert " ")
445           (set-extent-begin-glyph (make-extent (point) (point)) gnus-xmas-logo)
446           (goto-char (point-min))
447           (while (not (eobp))
448             (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
449                                  ? ))
450             (forward-line 1))
451           (goto-char (point-min))
452           (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
453                  (wheight (window-height))
454                  (rest (- wheight pheight)))
455             (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
456
457       (insert
458        (format "              %s
459           _    ___ _             _      
460           _ ___ __ ___  __    _ ___     
461           __   _     ___    __  ___     
462               _           ___     _     
463              _  _ __             _      
464              ___   __            _      
465                    __           _       
466                     _      _   _        
467                    _      _    _        
468                       _  _    _         
469                   __  ___               
470                  _   _ _     _          
471                 _   _                   
472               _    _                    
473              _    _                     
474             _                         
475           __                             
476
477
478                ""))
479       ;; And then hack it.
480       (gnus-indent-rigidly (point-min) (point-max) 
481                            (/ (max (- (window-width) (or x 46)) 0) 2))
482       (goto-char (point-min))
483       (forward-line 1)
484       (let* ((pheight (count-lines (point-min) (point-max)))
485              (wheight (window-height))
486              (rest (- wheight pheight)))
487         (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
488     ;; Fontify some.
489     (goto-char (point-min))
490     (and (search-forward "Praxis" nil t)
491          (put-text-property (match-beginning 0) (match-end 0) 'face 'bold))
492     (goto-char (point-min))
493     (let* ((mode-string (gnus-group-set-mode-line)))
494       (setq mode-line-buffer-identification 
495             (list (concat gnus-version (substring (car mode-string) 4))))
496       (set-buffer-modified-p t))))
497
498
499 ;;; The toolbar.
500
501 (defvar gnus-use-toolbar 'default-toolbar
502   "*If nil, do not use a toolbar.
503 If it is non-nil, it must be a toolbar.  The five legal values are
504 `default-toolbar', `top-toolbar', `bottom-toolbar',
505 `right-toolbar', and `left-toolbar'.")
506
507 (defvar gnus-group-toolbar 
508   '([gnus-group-exit-icon gnus-group-exit t "Exit Gnus"]
509     [gnus-group-kill-group-icon gnus-group-kill-group t "Kill group"]
510     [gnus-group-get-new-news-icon gnus-group-get-new-news t "Get new news"]
511     [gnus-group-get-new-news-this-group-icon 
512      gnus-group-get-new-news-this-group t "Get new news in this group"]
513     [gnus-group-catchup-current-icon 
514      gnus-group-catchup-current t "Catchup group"]
515     [gnus-group-describe-group-icon 
516      gnus-group-describe-group t "Describe group"])
517   "The group buffer toolbar.")
518
519 (defvar gnus-summary-toolbar 
520   '([gnus-summary-post-news-icon 
521      gnus-summary-post-news t "Post an article"]
522     [gnus-summary-save-article-file-icon
523      gnus-summary-save-article-file t "Save article in file"]
524     [gnus-summary-save-article-icon
525      gnus-summary-save-article t "Save article"]
526     [gnus-summary-reply-icon 
527      gnus-summary-reply t "Mail a reply"]
528     [gnus-summary-reply-with-original-icon
529      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
530     [gnus-summary-followup-icon 
531      gnus-summary-followup t "Post a followup"]
532     [gnus-summary-followup-with-original-icon
533      gnus-summary-followup-with-original t 
534      "Post a followup and yank the original"]
535     [gnus-uu-decode-uu-icon
536      gnus-uu-decode-uu t "Decode uuencoded articles"]
537     [gnus-uu-post-news-icon 
538      gnus-uu-post-news t "Post an uuencoded article"]
539     [gnus-summary-caesar-message-icon
540      gnus-summary-caesar-message t "Rot 13"]
541     [gnus-summary-cancel-article-icon
542      gnus-summary-cancel-article t "Cancel article"])
543   "The summary buffer toolbar.")
544
545 (defun gnus-xmas-setup-toolbar (bar &optional force)
546   (let ((dir (gnus-xmas-find-glyph-directory))
547         icon up down disabled name)
548     (if (not dir)
549         ()
550       (if (and (not force)
551                (boundp (aref (car bar) 0)))
552           dir
553         (while bar
554           (setq icon (aref (car bar) 0)
555                 name (symbol-name icon)
556                 bar (cdr bar))
557           (setq up (concat dir name "-up.xpm"))
558           (setq down (concat dir name "-down.xpm"))
559           (setq disabled (concat dir name "-disabled.xpm"))
560           (if (not (file-exists-p up))
561               (set icon nil)
562             (set icon (toolbar-make-button-list
563                        up (and (file-exists-p down) down)
564                        (and (file-exists-p disabled) disabled)))))
565         dir))))
566
567 (defun gnus-xmas-setup-group-toolbar ()
568   (and gnus-use-toolbar
569        (gnus-xmas-setup-toolbar gnus-group-toolbar)
570        (set-specifier (symbol-value gnus-use-toolbar)
571                       (cons (current-buffer) gnus-group-toolbar))))
572
573 (defun gnus-xmas-setup-summary-toolbar ()
574   (and gnus-use-toolbar
575        (gnus-xmas-setup-toolbar gnus-summary-toolbar)
576        (set-specifier (symbol-value gnus-use-toolbar)
577                       (cons (current-buffer) gnus-summary-toolbar))))
578
579 ;; Written by Erik Naggum <erik@naggum.no>.
580 ;; Saved by Steve Baur <steve@miranova.com>.
581 (defun insert-file-contents-literally (filename &optional visit beg end replace)
582   "Like `insert-file-contents', q.v., but only reads in the file.
583 A buffer may be modified in several ways after reading into the buffer due
584 to advanced Emacs features, such as file-name-handlers, format decoding,
585 find-file-hooks, etc.
586   This function ensures that none of these modifications will take place."
587   (let (                                ; (file-name-handler-alist nil)
588         (format-alist nil)
589         (after-insert-file-functions nil)
590         (find-buffer-file-type-function 
591          (if (fboundp 'find-buffer-file-type)
592              (symbol-function 'find-buffer-file-type)
593            nil)))
594     (unwind-protect
595         (progn
596           (fset 'find-buffer-file-type (lambda (filename) t))
597           (insert-file-contents filename visit beg end replace))
598       (if find-buffer-file-type-function
599           (fset 'find-buffer-file-type find-buffer-file-type-function)
600         (fmakunbound 'find-buffer-file-type)))))
601
602 (defun gnus-xmas-find-file-noselect (filename &optional nowarn rawfile)
603   "Read file FILENAME into a buffer and return the buffer.
604 If a buffer exists visiting FILENAME, return that one, but
605 verify that the file has not changed since visited or saved.
606 The buffer is not selected, just returned to the caller."
607   (setq filename
608         (abbreviate-file-name
609          (expand-file-name filename)))
610   (if (file-directory-p filename)
611       (if find-file-run-dired
612           (dired-noselect filename)
613         (error "%s is a directory." filename))
614     (let* ((buf (get-file-buffer filename))
615            (truename (abbreviate-file-name (file-truename filename)))
616            (number (nthcdr 10 (file-attributes truename)))
617            ;; Find any buffer for a file which has same truename.
618            (other (and (not buf) 
619                        (if (fboundp 'find-buffer-visiting)
620                            (find-buffer-visiting filename)
621                          (get-file-buffer filename))))
622            error)
623       ;; Let user know if there is a buffer with the same truename.
624       (if other
625           (progn
626             (or nowarn
627                 (string-equal filename (buffer-file-name other))
628                 (message "%s and %s are the same file"
629                          filename (buffer-file-name other)))
630             ;; Optionally also find that buffer.
631             (if (or (and (boundp 'find-file-existing-other-name)
632                          find-file-existing-other-name)
633                     find-file-visit-truename)
634                 (setq buf other))))
635       (if buf
636           (or nowarn
637               (verify-visited-file-modtime buf)
638               (cond ((not (file-exists-p filename))
639                      (error "File %s no longer exists!" filename))
640                     ((yes-or-no-p
641                       (if (string= (file-name-nondirectory filename)
642                                    (buffer-name buf))
643                           (format
644                            (if (buffer-modified-p buf)
645                                "File %s changed on disk.  Discard your edits? "
646                              "File %s changed on disk.  Reread from disk? ")
647                            (file-name-nondirectory filename))
648                         (format
649                          (if (buffer-modified-p buf)
650                              "File %s changed on disk.  Discard your edits in %s? "
651                            "File %s changed on disk.  Reread from disk into %s? ")
652                          (file-name-nondirectory filename)
653                          (buffer-name buf))))
654                      (save-excursion
655                        (set-buffer buf)
656                        (revert-buffer t t)))))
657         (save-excursion
658 ;;; The truename stuff makes this obsolete.
659 ;;;       (let* ((link-name (car (file-attributes filename)))
660 ;;;              (linked-buf (and (stringp link-name)
661 ;;;                               (get-file-buffer link-name))))
662 ;;;         (if (bufferp linked-buf)
663 ;;;             (message "Symbolic link to file in buffer %s"
664 ;;;                      (buffer-name linked-buf))))
665           (setq buf (create-file-buffer filename))
666           ;;      (set-buffer-major-mode buf)
667           (set-buffer buf)
668           (erase-buffer)
669           (if rawfile
670               (condition-case ()
671                   (insert-file-contents-literally filename t)
672                 (file-error
673                  ;; Unconditionally set error
674                  (setq error t)))
675             (condition-case ()
676                 (insert-file-contents filename t)
677               (file-error
678                ;; Run find-file-not-found-hooks until one returns non-nil.
679                (or t                    ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
680                    ;; If they fail too, set error.
681                    (setq error t)))))
682           ;; Find the file's truename, and maybe use that as visited name.
683           (setq buffer-file-truename truename)
684           (setq buffer-file-number number)
685           ;; On VMS, we may want to remember which directory in a search list
686           ;; the file was found in.
687           (and (eq system-type 'vax-vms)
688                (let (logical)
689                  (if (string-match ":" (file-name-directory filename))
690                      (setq logical (substring (file-name-directory filename)
691                                               0 (match-beginning 0))))
692                  (not (member logical find-file-not-true-dirname-list)))
693                (setq buffer-file-name buffer-file-truename))
694           (if find-file-visit-truename
695               (setq buffer-file-name
696                     (setq filename
697                           (expand-file-name buffer-file-truename))))
698           ;; Set buffer's default directory to that of the file.
699           (setq default-directory (file-name-directory filename))
700           ;; Turn off backup files for certain file names.  Since
701           ;; this is a permanent local, the major mode won't eliminate it.
702           (and (not (funcall backup-enable-predicate buffer-file-name))
703                (progn
704                  (make-local-variable 'backup-inhibited)
705                  (setq backup-inhibited t)))
706           (if rawfile
707               nil
708             (after-find-file error (not nowarn)))))
709       buf)))
710
711
712 ;;; gnus-xmas.el ends here