1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
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)
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.
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 the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
30 (defvar menu-bar-mode t)
31 (require 'message-xmas)
33 (defvar gnus-xmas-glyph-directory nil
34 "*Directory where Gnus logos and icons are located.
35 If this variable is nil, Gnus will try to locate the directory
38 ;;; Internal variables.
40 (defvar gnus-xmas-logo (make-glyph (make-specifier 'image)))
42 ;; Don't warn about these undefined variables.
44 (defvar gnus-group-mode-hook)
45 (defvar gnus-summary-mode-hook)
46 (defvar gnus-article-mode-hook)
49 (defvar gnus-active-hashtb)
50 (defvar gnus-article-buffer)
51 (defvar gnus-auto-center-summary)
52 (defvar gnus-buffer-list)
53 (defvar gnus-current-headers)
54 (defvar gnus-level-killed)
55 (defvar gnus-level-zombie)
56 (defvar gnus-newsgroup-bookmarks)
57 (defvar gnus-newsgroup-dependencies)
58 (defvar gnus-newsgroup-selected-overlay)
59 (defvar gnus-newsrc-hashtb)
60 (defvar gnus-read-mark)
61 (defvar gnus-refer-article-method)
62 (defvar gnus-reffed-article-number)
63 (defvar gnus-unread-mark)
65 (defvar gnus-view-pseudos)
66 (defvar gnus-view-pseudos-separately)
68 (defvar gnus-zombie-list)
69 ;;defined in gnus-msg.el
70 (defvar gnus-article-copy)
71 (defvar gnus-check-before-posting)
72 ;;defined in gnus-vis.el
73 (defvar gnus-article-button-face)
74 (defvar gnus-article-mouse-face)
75 (defvar gnus-summary-selected-face)
76 (defvar gnus-group-reading-menu)
77 (defvar gnus-group-group-menu)
78 (defvar gnus-group-misc-menu)
79 (defvar gnus-summary-article-menu)
80 (defvar gnus-summary-thread-menu)
81 (defvar gnus-summary-misc-menu)
82 (defvar gnus-summary-post-menu)
83 (defvar gnus-summary-kill-menu)
84 (defvar gnus-article-article-menu)
85 (defvar gnus-article-treatment-menu)
87 (defvar standard-display-table)
89 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
90 "You should NEVER use this function. It is ideologically blasphemous.
91 It is provided only to ease porting of broken FSF Emacs programs."
94 (map-extents (lambda (extent ignored)
95 (remove-text-properties
97 (list (extent-property extent 'text-prop) nil)
99 buffer start end nil nil 'text-prop)
100 (gnus-add-text-properties start end props buffer)))
102 (defun gnus-xmas-highlight-selected-summary ()
103 ;; Highlight selected article in summary buffer
104 (if gnus-summary-selected-face
106 (if gnus-newsgroup-selected-overlay
107 (delete-extent gnus-newsgroup-selected-overlay))
108 (setq gnus-newsgroup-selected-overlay
109 (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
110 (set-extent-face gnus-newsgroup-selected-overlay
111 gnus-summary-selected-face))))
113 (defun gnus-xmas-summary-recenter ()
114 "\"Center\" point in the summary window.
115 If `gnus-auto-center-summary' is nil, or the article buffer isn't
116 displayed, no centering will be performed."
117 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
118 ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
119 (when gnus-auto-center-summary
120 (let* ((height (if (fboundp 'window-displayed-height)
121 (window-displayed-height)
122 (- (window-height) 2)))
123 (top (cond ((< height 4) 0)
126 (bottom (save-excursion (goto-char (point-max))
127 (forward-line (- height))
129 (window (get-buffer-window (current-buffer))))
130 (when (get-buffer-window gnus-article-buffer)
131 ;; Only do recentering when the article buffer is displayed,
132 ;; Set the window start to either `bottom', which is the biggest
133 ;; possible valid number, or the second line from the top,
134 ;; whichever is the least.
136 window (min bottom (save-excursion
137 (forward-line (- top)) (point)))))
138 ;; Do horizontal recentering while we're at it.
139 (when (and (get-buffer-window (current-buffer) t)
140 (not (eq gnus-auto-center-summary 'vertical)))
141 (let ((selected (selected-window)))
142 (select-window (get-buffer-window (current-buffer) t))
143 (gnus-summary-position-point)
144 (gnus-horizontal-recenter)
145 (select-window selected))))))
147 (defun gnus-xmas-add-text-properties (start end props &optional object)
148 (add-text-properties start end props object)
149 (put-text-property start end 'start-closed nil object))
151 (defun gnus-xmas-put-text-property (start end prop value &optional object)
152 (put-text-property start end prop value object)
153 (put-text-property start end 'start-closed nil object))
155 (defun gnus-xmas-extent-start-open (point)
156 (map-extents (lambda (extent arg)
157 (set-extent-property extent 'start-open t))
158 nil point (min (1+ (point)) (point-max))))
160 (defun gnus-xmas-copy-article-buffer (&optional article-buffer)
161 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
162 (buffer-disable-undo gnus-article-copy)
163 (or (memq gnus-article-copy gnus-buffer-list)
164 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
165 (let ((article-buffer (or article-buffer gnus-article-buffer))
167 (if (and (get-buffer article-buffer)
168 (buffer-name (get-buffer article-buffer)))
170 (set-buffer article-buffer)
172 (setq buf (buffer-substring (point-min) (point-max)))
173 (set-buffer gnus-article-copy)
175 (insert (format "%s" buf))))
178 (defun gnus-xmas-article-push-button (event)
179 "Check text under the mouse pointer for a callback function.
180 If the text under the mouse pointer has a `gnus-callback' property,
181 call it with the value of the `gnus-data' text property."
183 (set-buffer (window-buffer (event-window event)))
184 (let* ((pos (event-closest-point event))
185 (data (get-text-property pos 'gnus-data))
186 (fun (get-text-property pos 'gnus-callback)))
187 (if fun (funcall fun data))))
189 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
190 (set-extent-endpoints extent start end))
192 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
193 (defun gnus-xmas-article-add-button (from to fun &optional data)
194 "Create a button between FROM and TO with callback FUN and data DATA."
195 (and gnus-article-button-face
196 (gnus-overlay-put (gnus-make-overlay from to)
197 'face gnus-article-button-face))
198 (gnus-add-text-properties
201 (and gnus-article-mouse-face
202 (list 'mouse-face gnus-article-mouse-face))
203 (list 'gnus-callback fun)
204 (and data (list 'gnus-data data))
205 (list 'highlight t))))
207 (defun gnus-xmas-window-top-edge (&optional window)
208 (nth 1 (window-pixel-edges window)))
210 (defun gnus-xmas-tree-minimize ()
211 (when (and gnus-tree-minimize-window
212 (not (one-window-p)))
213 (let* ((window-min-height 2)
214 (height (1+ (count-lines (point-min) (point-max))))
215 (min (max (1- window-min-height) height))
216 (tot (if (numberp gnus-tree-minimize-window)
217 (min gnus-tree-minimize-window min)
219 (win (get-buffer-window (current-buffer)))
220 (wh (and win (1- (window-height win)))))
223 (let ((selected (selected-window)))
225 (enlarge-window (- tot wh))
226 (select-window selected))))))
228 ;; Select the lowest window on the frame.
229 (defun gnus-xmas-appt-select-lowest-window ()
230 (let* ((lowest-window (selected-window))
231 (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
232 (last-window (previous-window))
235 (let* ((this-window (next-window))
236 (next-bottom-edge (car (cdr (cdr (cdr
239 (if (< bottom-edge next-bottom-edge)
241 (setq bottom-edge next-bottom-edge)
242 (setq lowest-window this-window)))
244 (select-window this-window)
245 (if (eq last-window this-window)
247 (select-window lowest-window)
248 (setq window-search nil)))))))
250 (defmacro gnus-xmas-menu-add (type &rest menus)
251 `(gnus-xmas-menu-add-1 ',type ',menus))
252 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
253 (put 'gnus-xmas-menu-add 'lisp-indent-hook 1)
255 (defun gnus-xmas-menu-add-1 (type menus)
256 (when (and menu-bar-mode
257 (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
259 (easy-menu-add (symbol-value (pop menus))))))
261 (defun gnus-xmas-group-menu-add ()
262 (gnus-xmas-menu-add group
263 gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
265 (defun gnus-xmas-summary-menu-add ()
266 (gnus-xmas-menu-add summary
267 gnus-summary-article-menu gnus-summary-thread-menu
268 gnus-summary-misc-menu gnus-summary-post-menu gnus-summary-kill-menu))
270 (defun gnus-xmas-article-menu-add ()
271 (gnus-xmas-menu-add article
272 gnus-article-article-menu gnus-article-treatment-menu))
274 (defun gnus-xmas-pick-menu-add ()
275 (gnus-xmas-menu-add pick
278 (defun gnus-xmas-binary-menu-add ()
279 (gnus-xmas-menu-add binary
282 (defun gnus-xmas-tree-menu-add ()
283 (gnus-xmas-menu-add tree
286 (defun gnus-xmas-grouplens-menu-add ()
287 (gnus-xmas-menu-add grouplens
288 gnus-grouplens-menu))
290 (defun gnus-xmas-read-event-char ()
291 "Get the next event."
292 (let ((event (next-event)))
293 ;; We junk all non-key events. Is this naughty?
294 (while (not (key-press-event-p event))
295 (setq event (next-event)))
296 (cons (and (key-press-event-p event)
297 ; (numberp (event-key event))
298 (event-to-character event))
301 (defun gnus-xmas-group-remove-excess-properties ()
303 (beg (progn (forward-line -1) (point))))
304 (remove-text-properties (1+ beg) end '(gnus-group nil))
305 (remove-text-properties
307 '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
311 (set-extent-property e 'start-closed t))
312 (current-buffer) beg end)))
314 (defun gnus-xmas-topic-remove-excess-properties ()
316 (beg (progn (forward-line -1) (point))))
317 (remove-text-properties beg end '(gnus-group nil gnus-unread nil))
318 (remove-text-properties (1+ beg) end '(gnus-topic nil))
321 (defun gnus-xmas-seconds-since-epoch (date)
322 "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
323 (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
324 (timezone-parse-date date)))
325 (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
327 (aref (timezone-parse-date date) 3))))
328 (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
329 (timezone-parse-date "Jan 1 12:00:00 1970")))
330 (tday (- (timezone-absolute-from-gregorian
331 (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
332 (timezone-absolute-from-gregorian
333 (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
336 (* (float (nth 0 ttime)) 60 60)
337 (* (float tday) 60 60 24))))
339 (defun gnus-xmas-define ()
340 (setq gnus-mouse-2 [button2])
342 (or (memq 'underline (list-faces))
343 (and (fboundp 'make-face)
344 (funcall (intern "make-face") 'underline)))
345 ;; Must avoid calling set-face-underline-p directly, because it
346 ;; is a defsubst in emacs19, and will make the .elc files non
348 (or (face-differs-from-default-p 'underline)
349 (funcall (intern "set-face-underline-p") 'underline t))
351 (fset 'gnus-make-overlay 'make-extent)
352 (fset 'gnus-overlay-put 'set-extent-property)
353 (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
354 (fset 'gnus-overlay-end 'extent-end-position)
355 (fset 'gnus-extent-detached-p 'extent-detached-p)
356 (fset 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
357 (fset 'gnus-put-text-property 'gnus-xmas-put-text-property)
359 (require 'text-props)
360 (if (< emacs-minor-version 14)
361 (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
363 (fset 'nnheader-find-file-noselect 'gnus-xmas-find-file-noselect)
365 (or (boundp 'standard-display-table) (setq standard-display-table nil))
367 (defvar gnus-mouse-face-prop 'highlight)
369 (unless (fboundp 'encode-time)
370 (defun encode-time (sec minute hour day month year &optional zone)
372 (gnus-xmas-seconds-since-epoch
373 (timezone-make-arpa-date
374 year month day (timezone-make-time-string hour minute sec)
376 (list (floor (/ seconds (expt 2 16)))
377 (round (mod seconds (expt 2 16)))))))
379 (defun gnus-byte-code (func)
380 "Return a form that can be `eval'ed based on FUNC."
381 (let ((fval (symbol-function func)))
382 (if (byte-code-function-p fval)
384 (cons 'progn (cdr (cdr fval))))))
386 ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
387 (defvar gnus-display-type (device-class)
388 "A symbol indicating the display Emacs is running under.
389 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
390 guesses this display attribute wrongly, either set this variable in
391 your `~/.emacs' or set the resource `Emacs.displayType' in your
392 `~/.Xdefaults'. See also `gnus-background-mode'.
394 This is a meta-variable that will affect what default values other
395 variables get. You would normally not change this variable, but
396 pounce directly on the real variables themselves.")
399 (fset 'gnus-x-color-values
400 (if (fboundp 'x-color-values)
403 (color-instance-rgb-components
404 (make-color-instance color)))))
406 (defvar gnus-background-mode
409 (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
411 (params (frame-parameters))
412 (color (condition-case ()
413 (or (assq 'background-color params)
416 (face-background 'default))))
418 (cond (bg-resource (intern (downcase bg-resource)))
420 (< (apply '+ (gnus-x-color-values color))
421 (/ (apply '+ (gnus-x-color-values "white")) 3)))
424 "A symbol indicating the Emacs background brightness.
425 The symbol should be one of `light' or `dark'.
426 If Emacs guesses this frame attribute wrongly, either set this variable in
427 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
429 See also `gnus-display-type'.
431 This is a meta-variable that will affect what default values other
432 variables get. You would normally not change this variable, but
433 pounce directly on the real variables themselves.")
438 (defun gnus-xmas-redefine ()
439 "Redefine lots of Gnus functions for XEmacs."
440 (fset 'gnus-summary-make-display-table 'ignore)
441 (fset 'gnus-visual-turn-off-edit-menu 'identity)
442 (fset 'gnus-highlight-selected-summary
443 'gnus-xmas-highlight-selected-summary)
444 (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
445 (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
446 (fset 'gnus-copy-article-buffer 'gnus-xmas-copy-article-buffer)
447 (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
448 (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
449 (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
450 (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
451 (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
452 (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
453 (fset 'gnus-appt-select-lowest-window
454 'gnus-xmas-appt-select-lowest-window)
455 (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
456 (fset 'gnus-make-local-hook 'make-local-variable)
457 (fset 'gnus-character-to-event 'character-to-event)
459 (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
460 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
461 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
463 (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
464 (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
465 (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
466 (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
468 (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
469 (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
471 (when (and (<= emacs-major-version 19)
472 (<= emacs-minor-version 13))
473 (fset 'gnus-group-remove-excess-properties
474 'gnus-xmas-group-remove-excess-properties)
475 (fset 'gnus-topic-remove-excess-properties
476 'gnus-xmas-topic-remove-excess-properties)))
479 ;;; XEmacs logo and toolbar.
481 (defun gnus-xmas-group-startup-message (&optional x y)
482 "Insert startup message in current buffer."
483 ;; Insert the message.
484 (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
486 (let ((file (and gnus-xmas-glyph-directory
488 (file-name-as-directory gnus-xmas-glyph-directory)
490 (if (and (featurep 'xpm)
491 (not (equal (device-type) 'tty))
492 file (file-exists-p file))
494 (set-glyph-property gnus-xmas-logo 'image file)
495 (set-glyph-image gnus-xmas-logo file 'global 'x)
498 (set-extent-begin-glyph (make-extent (point) (point)) gnus-xmas-logo)
499 (goto-char (point-min))
501 (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
504 (goto-char (point-min))
505 (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
506 (wheight (window-height))
507 (rest (- wheight pheight)))
508 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
513 _ ___ __ ___ __ _ ___
533 (gnus-indent-rigidly (point-min) (point-max)
534 (/ (max (- (window-width) (or x 46)) 0) 2))
535 (goto-char (point-min))
537 (let* ((pheight (count-lines (point-min) (point-max)))
538 (wheight (window-height))
539 (rest (- wheight pheight)))
540 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
542 (goto-char (point-min))
543 (and (search-forward "Praxis" nil t)
544 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold))
545 (goto-char (point-min))
546 (let* ((mode-string (gnus-group-set-mode-line)))
547 (setq mode-line-buffer-identification
548 (list (concat gnus-version (substring (car mode-string) 4))))
549 (set-buffer-modified-p t))))
554 (defvar gnus-use-toolbar 'default-toolbar
555 "*If nil, do not use a toolbar.
556 If it is non-nil, it must be a toolbar. The five legal values are
557 `default-toolbar', `top-toolbar', `bottom-toolbar',
558 `right-toolbar', and `left-toolbar'.")
560 (defvar gnus-group-toolbar
561 '([gnus-group-exit gnus-group-exit t "Exit Gnus"]
562 [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
563 [gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
564 [gnus-group-get-new-news-this-group
565 gnus-group-get-new-news-this-group t "Get new news in this group"]
566 [gnus-group-catchup-current
567 gnus-group-catchup-current t "Catchup group"]
568 [gnus-group-describe-group
569 gnus-group-describe-group t "Describe group"])
570 "The group buffer toolbar.")
572 (defvar gnus-summary-toolbar
573 '([gnus-summary-post-news
574 gnus-summary-post-news t "Post an article"]
575 [gnus-summary-save-article-file
576 gnus-summary-save-article-file t "Save article in file"]
577 [gnus-summary-save-article
578 gnus-summary-save-article t "Save article"]
580 gnus-summary-reply t "Mail a reply"]
581 [gnus-summary-reply-with-original
582 gnus-summary-reply-with-original t "Mail a reply and yank the original"]
583 [gnus-summary-followup
584 gnus-summary-followup t "Post a followup"]
585 [gnus-summary-followup-with-original
586 gnus-summary-followup-with-original t
587 "Post a followup and yank the original"]
589 gnus-uu-decode-uu t "Decode uuencoded articles"]
591 gnus-uu-post-news t "Post an uuencoded article"]
592 [gnus-summary-caesar-message
593 gnus-summary-caesar-message t "Rot 13"]
594 [gnus-summary-cancel-article
595 gnus-summary-cancel-article t "Cancel article"])
596 "The summary buffer toolbar.")
598 (defvar gnus-summary-mail-toolbar
599 '([gnus-summary-mail-reply gnus-summary-reply t "Reply"]
600 [gnus-summary-mail-get gnus-mail-get t "Message get"]
601 [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
602 [gnus-summary-mail-save gnus-summary-save-article t "Save"]
603 [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
604 [gnus-summary-mail-delete gnus-summary-delete-article t "Delete message"]
605 [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
606 ; [gnus-summary-mail-spell gnus-mail-spell t "Spell"]
607 ; [gnus-summary-mail-help gnus-mail-help t "Message help"]
609 "The summary buffer mail toolbar.")
611 (defun gnus-xmas-setup-group-toolbar ()
613 (and gnus-use-toolbar
614 (setq dir (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus"))
615 (file-exists-p (concat dir "gnus-group-catchup-current-up.xpm"))
616 (set-specifier (symbol-value gnus-use-toolbar)
617 (cons (current-buffer) gnus-group-toolbar)))))
619 (defun gnus-xmas-setup-summary-toolbar ()
620 (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
621 gnus-summary-toolbar gnus-summary-mail-toolbar))
623 (and gnus-use-toolbar
624 (setq dir (message-xmas-setup-toolbar bar nil "gnus"))
625 (file-exists-p (concat dir "gnus-group-catchup-current-up.xpm"))
626 (set-specifier (symbol-value gnus-use-toolbar)
627 (cons (current-buffer) bar)))))
629 ;; Written by Erik Naggum <erik@naggum.no>.
630 ;; Saved by Steve Baur <steve@miranova.com>.
631 (or (fboundp 'insert-file-contents-literally)
632 (defun insert-file-contents-literally (filename &optional visit beg end replace)
633 "Like `insert-file-contents', q.v., but only reads in the file.
634 A buffer may be modified in several ways after reading into the buffer due
635 to advanced Emacs features, such as file-name-handlers, format decoding,
636 find-file-hooks, etc.
637 This function ensures that none of these modifications will take place."
638 (let ( ; (file-name-handler-alist nil)
640 (after-insert-file-functions nil)
641 (find-buffer-file-type-function
642 (if (fboundp 'find-buffer-file-type)
643 (symbol-function 'find-buffer-file-type)
647 (fset 'find-buffer-file-type (lambda (filename) t))
648 (insert-file-contents filename visit beg end replace))
649 (if find-buffer-file-type-function
650 (fset 'find-buffer-file-type find-buffer-file-type-function)
651 (fmakunbound 'find-buffer-file-type))))))
653 (defun gnus-xmas-find-file-noselect (filename &optional nowarn rawfile)
654 "Read file FILENAME into a buffer and return the buffer.
655 If a buffer exists visiting FILENAME, return that one, but
656 verify that the file has not changed since visited or saved.
657 The buffer is not selected, just returned to the caller."
659 (abbreviate-file-name
660 (expand-file-name filename)))
661 (if (file-directory-p filename)
662 (if find-file-run-dired
663 (dired-noselect filename)
664 (error "%s is a directory." filename))
665 (let* ((buf (get-file-buffer filename))
666 (truename (abbreviate-file-name (file-truename filename)))
667 (number (nthcdr 10 (file-attributes truename)))
668 ;; Find any buffer for a file which has same truename.
669 (other (and (not buf)
670 (if (fboundp 'find-buffer-visiting)
671 (find-buffer-visiting filename)
672 (get-file-buffer filename))))
674 ;; Let user know if there is a buffer with the same truename.
678 (string-equal filename (buffer-file-name other))
679 (message "%s and %s are the same file"
680 filename (buffer-file-name other)))
681 ;; Optionally also find that buffer.
682 (if (or (and (boundp 'find-file-existing-other-name)
683 find-file-existing-other-name)
684 find-file-visit-truename)
688 (verify-visited-file-modtime buf)
689 (cond ((not (file-exists-p filename))
690 (error "File %s no longer exists!" filename))
692 (if (string= (file-name-nondirectory filename)
695 (if (buffer-modified-p buf)
696 "File %s changed on disk. Discard your edits? "
697 "File %s changed on disk. Reread from disk? ")
698 (file-name-nondirectory filename))
700 (if (buffer-modified-p buf)
701 "File %s changed on disk. Discard your edits in %s? "
702 "File %s changed on disk. Reread from disk into %s? ")
703 (file-name-nondirectory filename)
707 (revert-buffer t t)))))
709 ;;; The truename stuff makes this obsolete.
710 ;;; (let* ((link-name (car (file-attributes filename)))
711 ;;; (linked-buf (and (stringp link-name)
712 ;;; (get-file-buffer link-name))))
713 ;;; (if (bufferp linked-buf)
714 ;;; (message "Symbolic link to file in buffer %s"
715 ;;; (buffer-name linked-buf))))
716 (setq buf (create-file-buffer filename))
717 ;; (set-buffer-major-mode buf)
722 (insert-file-contents-literally filename t)
724 ;; Unconditionally set error
727 (insert-file-contents filename t)
729 ;; Run find-file-not-found-hooks until one returns non-nil.
730 (or t ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
731 ;; If they fail too, set error.
733 ;; Find the file's truename, and maybe use that as visited name.
734 (setq buffer-file-truename truename)
735 (setq buffer-file-number number)
736 ;; On VMS, we may want to remember which directory in a search list
737 ;; the file was found in.
738 (and (eq system-type 'vax-vms)
740 (if (string-match ":" (file-name-directory filename))
741 (setq logical (substring (file-name-directory filename)
742 0 (match-beginning 0))))
743 (not (member logical find-file-not-true-dirname-list)))
744 (setq buffer-file-name buffer-file-truename))
745 (if find-file-visit-truename
746 (setq buffer-file-name
748 (expand-file-name buffer-file-truename))))
749 ;; Set buffer's default directory to that of the file.
750 (setq default-directory (file-name-directory filename))
751 ;; Turn off backup files for certain file names. Since
752 ;; this is a permanent local, the major mode won't eliminate it.
753 (and (not (funcall backup-enable-predicate buffer-file-name))
755 (make-local-variable 'backup-inhibited)
756 (setq backup-inhibited t)))
759 (after-find-file error (not nowarn)))))
762 (defun gnus-xmas-mail-strip-quoted-names (address)
763 "Protect mail-strip-quoted-names from NIL input.
764 XEmacs compatibility workaround."
767 (mail-strip-quoted-names address)))
769 ;;; gnus-xmas.el ends here