Gnus development mailing list
 help / color / mirror / Atom feed
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Packing nnml folders...
Date: 28 Jul 2001 22:18:34 -0400	[thread overview]
Message-ID: <yge66ccpjet.fsf@asfast.com> (raw)
In-Reply-To: <m366ccvk85.fsf@multivac.cwru.edu>

prj@po.cwru.edu (Paul Jarc) writes:

> Lloyd Zusman <ljz@asfast.com> writes:
>> As soon as I figure out how to mass-copy the customization settings,
>> I'll write the function that does this "repacking from 1" operation
>> for nnml groups.
> 
> I don't think it would have to be specific to nnml.  If you were going
> to involve a particular backend, then you might as well make the
> backend store marks.  Then the renumbering could be done
> automatically, without requiring user intervention.

I agree that this would be the ideal way to handle group renumbering.

However, I'm not too familiar with backend processing, and so for the
moment, I don't feel confident enough to tackle that task.  Maybe one
of these days ... <sigh>

But for the time being, I've hacked out a function that will renumber
and repack an nnml group.  You can see it below.

WARNING!!! ... this is experimental.  I've tested it within my own
environment and it seems to work, but I wouldn't rely on it without a
lot more testing.  Be sure to BACK UP EVERYTHING before playing with
it.

And even if it seems to work, I strongly recommend to not yet make it
part of Gnus until a lot more error checking is inserted into the
code.  Also, I think that it can be rewritten to be more efficient.
Please remember that THIS IS STILL EXPERIMENTAL.

Nevertheless, it works for me, and if nothing else, it's a proof of
concept.  What do you folks think of it?

;; Helper function: return a unique, temporary group name
;; that's based on a specified nnml group name.
(defun create-temp-nnml-group-name (group)
  (let ((temp-name-pattern (concat group "-temp-%d"))
	(n 0)
	temp-name)
    ;; Uniqueness test:  1. make sure that no group exists
    ;;                      with the same name
    ;;                   2. make sure that there's no
    ;;                      nnml directory for a group
    ;;                      of this name (such a directory
    ;;                      might still exist if a group
    ;;                      with the specified name was
    ;;                      previously deleted)
    (while (or (gnus-gethash
		(setq temp-name (format temp-name-pattern n))
		gnus-newsrc-hashtb)
	       (file-directory-p
		(nnmail-group-pathname
		 (gnus-group-real-name temp-name) nnml-directory)))
      (setq n (1+ n)))
    temp-name))

;; Repack and renumber an nnml group.  I only allow this to work
;; if it's invoked from within the Group buffer.
(defun repack-and-renumber-nnml-group (group)
  (interactive (list
		(gnus-completing-read
		 (gnus-group-group-name)
		 "Group:" gnus-active-hashtb
		 nil 'require-match)))
  (unless (eq (current-buffer) (get-buffer gnus-group-buffer))
    (error "Must be invoked from within the %s buffer"
	   gnus-group-buffer))
  ;; Get the first temporary group name.
  (let ((temp-group-1 (create-temp-nnml-group-name group))
	temp-group-2)
    ;; Enter the group, with all articles visible.
    (gnus-group-read-group t t group)
    ;; Mark every article
    (gnus-uu-mark-all)
    ;; Copy the articles to the temporary group.
    ;; NOTE: if you're confident that all of this will
    ;;       work, you can change the following
    ;;       function to `gnus-summary-move-article'.
    (gnus-summary-copy-article nil temp-group-1)
    ;; Make sure we're back in the Group buffer
    (gnus-summary-exit)
    ;; Make sure that tne newly created temporary
    ;; group is of the same level as the original;
    ;; also positions the new group right before
    ;; the original.
    (gnus-group-change-level temp-group-1
			     (gnus-group-level group)
			     (gnus-group-level temp-group-1)
			     group)
    ;; Make sure that the new group has the same
    ;; customization parameters as the original.
    (gnus-group-set-info 
     (gnus-info-params (gnus-get-info group))
     temp-group-1
     'params)
    ;; We need to get the next temporary group name
    ;; now, *after* the first temporary group has
    ;; been created.
    (setq temp-group-2 (create-temp-nnml-group-name group))
    ;; Rename everything.  For some reason, it's
    ;; necessary to list all the groups before
    ;; renaming and deleting.
    (gnus-group-list-groups gnus-level-unsubscribed t)
    (gnus-group-rename-group group temp-group-2)
    (gnus-group-list-groups gnus-level-unsubscribed t)
    (gnus-group-rename-group temp-group-1 group)
    ;; Delete the original group, which has now been
    ;; renamed.  You'll be prompted for this.  If
    ;; you're really brave, add a fourth parameter
    ;; `t' to the following function invocation
    ;; to avoid the prompt.
    (gnus-group-list-groups gnus-level-unsubscribed t)
    (gnus-group-delete-group temp-group-2 t)))



-- 
 Lloyd Zusman
 ljz@asfast.com


  reply	other threads:[~2001-07-29  2:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-27 17:17 Jon Allen Boone
2001-07-27 20:22 ` Kai Großjohann
2001-07-28  0:47   ` Lloyd Zusman
2001-07-28  1:43     ` Jon Allen Boone
2001-07-28  2:13       ` Paul Jarc
2001-07-28  3:12         ` Jon Allen Boone
2001-07-28  6:30           ` Paul Jarc
2001-07-28 11:31           ` Kai Großjohann
2001-07-28 16:08             ` Lloyd Zusman
2001-07-28 18:38               ` Kai Großjohann
2001-07-28 19:02                 ` Lloyd Zusman
2001-07-28 21:20                   ` Kai Großjohann
2001-07-28 21:37                     ` Lloyd Zusman
2001-07-28 21:04               ` Paul Jarc
2001-07-29  2:18                 ` Lloyd Zusman [this message]
2001-07-29 19:01                   ` Lloyd Zusman
2001-07-29 20:58                   ` Kai Großjohann
2001-07-29 22:40                     ` Lloyd Zusman
2001-07-28 11:28     ` Kai Großjohann

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=yge66ccpjet.fsf@asfast.com \
    --to=ljz@asfast.com \
    /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).