Gnus development mailing list
 help / color / mirror / Atom feed
* Gnus to work on a Babyl file (update)
@ 2000-01-25 17:34 François Pinard
       [not found] ` <uya9c29n8.fsf@Globeset.Com>
  0 siblings, 1 reply; 2+ messages in thread
From: François Pinard @ 2000-01-25 17:34 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 4308 bytes --]

Hi, people.  I slightly amended my code for being able to use Gnus to browse
a Babyl file, and I found it so useful I want to share the update with you.

This is only meaningful if you keep mail archives in Babyl folders.
When you visit them with Emacs, you get RMAIL mode.  The following code
implement `!'  to trigger Gnus on the whole Babyl file using `nndoc'.
You use `q' from the Gnus summary to return to RMAIL mode.

What I changed is that any message I decide to mark as "read" within Gnus
now automatically gets deleted in the equivalent Babyl file.  The deletion
occurs at `q' time.  Also, the last current message at `q' time becomes
the current message in RMAIL mode.  This tremendously helps effectively
switching back and forth betwen RMAIL and Gnus.

Here is the code.  There is also the `C-u !' command to see a single
message, this code is unchanged from my previous message on that subject, but
I repeat it here for completeness.


;; 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.")

(defun fp-rmail-display-with-gnus (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)))

(defun fp-rmail-display-babyl-message-with-gnus ()
  "Display current message with Gnus, using a nnone ephemeral server."
  (interactive)
  (fp-maybe-start-gnus)
  (let ((rmail-buffer (current-buffer))
	(nnone-buffer (save-excursion
			(nnheader-set-temp-buffer " *copy article*")))
	(group (format "nnone:%s-%d[%d]"
		       (file-name-nondirectory buffer-file-name)
		       (incf fp-rmail-display-with-gnus-counter)
		       rmail-current-message)))
    (if (rmail-msg-is-pruned)
	(let ((modified (buffer-modified-p)))
	  (rmail-toggle-header)
	  (append-to-buffer nnone-buffer (point-min) (point-max))
	  (rmail-toggle-header)
	  (set-buffer-modified-p modified))
      (append-to-buffer nnone-buffer (point-min) (point-max)))
    (if (gnus-group-read-ephemeral-group
	 group `(nnone ,group (nnone-article-buffer ,nnone-buffer))
	 nil (cons rmail-buffer (current-window-configuration)))
	(progn
	  (gnus-summary-beginning-of-article)
	  (bury-buffer)
	  (delete-window))
      (kill-buffer nnone-buffer)
      (set-buffer rmail-buffer)
      (gnus-error 3 "Article couldn't be entered"))))

(defun fp-rmail-display-babyl-file-with-gnus ()
  "Display the whole Babyl file with Gnus, using a nndoc ephemeral server."
  (interactive)
  (fp-maybe-start-gnus)
  (let ((rmail-buffer (current-buffer))
	(group (format "nndoc:%s-%d"
		       (file-name-nondirectory buffer-file-name)
		       (incf fp-rmail-display-with-gnus-counter)))
	(article rmail-current-message))
    (if (save-restriction
	  (widen)
	  (gnus-group-read-ephemeral-group
	   group `(nndoc ,group (nndoc-address ,rmail-buffer)
			 (nndoc-article-type babyl))
	   t (cons rmail-buffer (current-window-configuration))))
	(progn
	  (make-local-variable 'gnus-summary-prepare-exit-hook)
	  (add-hook 'gnus-summary-prepare-exit-hook
		    'fp-gnus-exit-babyl-file-group-routine)
	  (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 ()
  "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)
    (save-excursion
      (set-buffer nndoc-address)
      (setq message 0
	    counter 0)
      (while (< message rmail-total-messages)
	(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) (message "All messages kept"))
	  ((= counter 1) (message "One message deleted"))
	  (t (message "Deleted %d messages" counter)))))


;; Ephemeral backend for RMAIL.
(gnus-declare-backend "nnone" 'mail 'respool 'address)


[-- Attachment #2: nnone.el --]
[-- Type: application/emacs-lisp, Size: 1427 bytes --]

[-- Attachment #3: Type: text/plain, Size: 59 bytes --]


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Gnus to work on a Babyl file (update)
       [not found] ` <uya9c29n8.fsf@Globeset.Com>
@ 2000-01-26 15:18   ` François Pinard
  0 siblings, 0 replies; 2+ messages in thread
From: François Pinard @ 2000-01-26 15:18 UTC (permalink / raw)


[I guess it is better also send this message to the list.]

alfred@Globeset.com (Alfred J Correira) écrit:

> Was there an earlier posting that defined "fp-maybe-start-gnus"?  It's a
> simply function to write (based on its name) but I'm wondering if anything
> else is needed as well ...

I did not keep my previous posts so I cannot check.  But yes, sorry,
the function is missing (yet not that important, if Gnus has already be
started once in that Emacs session).  Here it is:


(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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-01-26 15:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-25 17:34 Gnus to work on a Babyl file (update) François Pinard
     [not found] ` <uya9c29n8.fsf@Globeset.Com>
2000-01-26 15:18   ` François Pinard

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).