Gnus development mailing list
 help / color / mirror / Atom feed
From: "François Pinard" <pinard@iro.umontreal.ca>
Subject: Help needed for a rmail-Gnus Mule problem
Date: 10 Jul 2000 14:19:37 -0400	[thread overview]
Message-ID: <oqu2dxg85i.fsf@titan.progiciels-bpi.ca> (raw)

Hi, people.

I've been using the piece of code below for a good while, and despite
very, very useful for me, that code is irritating because of those (usual)
pesky \201's in all over in Latin-1 messages.  Even worse, these \201's
multiply like rabbits when I successively migrate a message between folders.

My feeling is that both RMAIL mode and Gnus are converting the file to
Mule, probably one message at a time in each case.  I wonder if someone
knowledgeable in Mule matters could not give me a hand with this: I'm lost!

By the way, the code might be useful to people handling Babyl (or RMAIL
mode) files.  For one, I keep a lot of archives in Babyl format.  The code
automatically triggers Gnus to read such files, and deletions from the
Gnus summary are later reflected in the Babyl files when exiting the summary.

I hope I include all pieces.  The code is a bit hairy, so please, be gentle
and don't laugh too loud! :-) Constructive criticisms always welcome!




;; FIXME: Rather depend on uniquification of names.
(defvar fp-rmail-display-with-gnus-counter 0
  "To make sure no two servers are simultaneously opened with the same name.")

;; FIXME: Something breaks when more than one Babyl in Gnus.  So use a lock.
(defvar fp-rmail-babyl-file-with-gnus-lock nil
  "Gnus summary buffer visiting a Babyl file, or nil if none.
To make sure only one Babyl file is visited in Gnus at a time.")

(defun fp-rmail-display-babyl-file-with-gnus (&optional article)
  "Display the whole Babyl file with Gnus, using a nndoc ephemeral server."
  (when (and fp-rmail-babyl-file-with-gnus-lock
	     (buffer-file-name fp-rmail-babyl-file-with-gnus-lock))
    (error "Gnus already displaying a Babyl file."))
  (let ((config (current-window-configuration))
	(rmail-buffer (current-buffer)))
    (fp-maybe-start-gnus)
    (let ((group (format "nndoc:%s-%d"
			 (file-name-nondirectory buffer-file-name)
			 (incf fp-rmail-display-with-gnus-counter))))
      (if (save-restriction
	    (widen)
	    (gnus-group-read-ephemeral-group
	     group `(nndoc ,group (nndoc-address ,rmail-buffer)
			   (nndoc-article-type babyl))
	     t (cons rmail-buffer config)))
	  (progn
	    (setq fp-rmail-babyl-file-with-gnus-lock (current-buffer))
	    (make-local-variable 'gnus-summary-prepare-exit-hook)
	    (add-hook 'gnus-summary-prepare-exit-hook
		      'fp-gnus-exit-babyl-file-group-routine)
	    (when article
	      (gnus-summary-goto-article article)))
	(set-buffer rmail-buffer)
	(gnus-error 3 "Babyl group couldn't be entered")))))

(defun fp-gnus-exit-babyl-file-group-routine ()
  "Reposition the Babyl file according to the current article in Gnus.
If not `Q', delete in the Babyl file what has not been kept on the Gnus side."
  (let ((current gnus-current-article)
	(unreads gnus-newsgroup-unreads)
	(ticked gnus-newsgroup-marked)
	message counter total)
    (save-excursion
      (set-buffer nndoc-address)
      (setq message 0
	    counter 0
	    total rmail-total-messages)
      (if (eq last-command-char ?Q)
	  (progn
	    (rmail-show-message current)
	    (save-buffer))
	(while (< message total)
	  (setq message (1+ message))
	  (unless (or (memq message unreads) (memq message ticked))
	    (message "Deleting message %d" message)
	    (rmail-show-message message t)
	    (rmail-delete-message)
	    (setq counter (1+ counter))))
	(rmail-show-message current)
	(cond ((zerop counter)
	       (save-buffer)
	       (message "All %d messages kept" total))
	      (t (rmail-expunge)
		 (setq total rmail-total-messages)
		 (save-buffer)
		 (if (> total 0)
		     (message "Deleted %d messages, keeping %d" counter total)
		   (delete-file buffer-file-name)
		   (message "Deleted file `%s'" buffer-file-name))
		 ;; Messages have been renumbered through expunging, article
		 ;; numbers from the summary are not dependable anymore.
		 ;; Dead summaries could become deadly if ever revived.
		 ;; To play safe, merely kill the Babyl buffer if expunged.
		 (kill-buffer (current-buffer))))
	(setq fp-rmail-babyl-file-with-gnus-lock nil)))))




(defvar fp-rmail-currently-visited-list nil)

(defun fp-rmail-mode-routine ()
  ;; [...]
  (local-set-key "!" 'fp-rmail-display-with-gnus)
  ;; [...]
  ;;; Immediately switch to Gnus, yet on initial visit only.
  (unless (member buffer-file-name fp-rmail-currently-visited-list)
    (push buffer-file-name fp-rmail-currently-visited-list)
    (let ((modified (buffer-modified-p)))
      (fp-rmail-display-babyl-file-with-gnus)
      ;; FIXME: I wonder what modified the buffer unconditionally.
      (set-buffer-modified-p modified))))
(add-hook 'rmail-mode-hook 'fp-rmail-mode-routine)

(defun fp-rmail-display-with-gnus (&optional flag)
  "Display the whole Babyl file with Gnus, using a nndoc ephemeral server.
With a flag argument, display only the current message instead, using nnone."
  (interactive "P")
  (if flag
      (fp-rmail-display-babyl-message-with-gnus)
    (fp-rmail-display-babyl-file-with-gnus rmail-current-message)))

(defun fp-rmail-display-babyl-message-with-gnus ()
  "Display current message with Gnus, using a nnone ephemeral server."
  ; [... not provided, not required, and probably not much useful...]
  nil)



(defun fp-maybe-start-gnus ()
  "Have Gnus started, if not already."
  (save-window-excursion
    (unless (gnus-alive-p)
      (gnus))))
(autoload 'gnus-alive-p "gnus-util")

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




                 reply	other threads:[~2000-07-10 18:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=oqu2dxg85i.fsf@titan.progiciels-bpi.ca \
    --to=pinard@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).