Gnus development mailing list
 help / color / mirror / Atom feed
From: David Engster <deng@randomsample.de>
To: ding@gnus.org
Subject: Re: Shorter/customized group names?
Date: Sat, 30 May 2009 16:46:06 +0200	[thread overview]
Message-ID: <87vdnimyxd.fsf@randomsample.de> (raw)
In-Reply-To: <m2octbk0ca.fsf@boostpro.com> (David Abrahams's message of "Fri, 29 May 2009 18:31:33 -0400")

David Abrahams <dave@boostpro.com> writes:
> on Fri May 29 2009, David Abrahams <dave-AT-boostpro.com> wrote:
>
>> on Fri May 29 2009, David Engster <deng-AT-randomsample.de> wrote:
>>
>>> David Abrahams <dave@boostpro.com> writes:
>>>> This is pretty cool, but it's also got a few problems.  It relies on
>>>> implementation details of Gnus like the order in which groups get
>>>> formatted, that Gnus always formats *all* the groups (it doesn't) and on
>>>> some secret variables.
>>>
>>> It's a hack, for sure. Maybe the reason it works pretty well for me is
>>> because I'm using topic mode?
>>
>> I'm using topic mode too.
>
> A possibly-less-hacky approach might be to "after" advise the functions
> that operate on the *Group* buffer to postprocess those strings.  Still,
> I really think this (or the tools to support it) should be a built-in
> feature.

I couldn't exactly reproduce the problems you had, but I also noticed
some inconsistencies when the Group buffer is rebuild only partially
(e.g. when opening a topic). I agree that doing this as a postprocess is
the best way to go about this. Since there are more than enough hooks we
don't even need to advise anything. :-)

So here's yet another version, based on your already modified one. It
also uses an internal feature: the complete group name is saved in the
text properties at the beginning of each group line. Since many internal
Gnus functions use these, this isn't likely to change.

--8<---------------cut here---------------start------------->8---
(defun DE-collapse-group-names ()
  (save-excursion
    (let (previous-group current-group common-prefix
			 common-dot-count prefix suffix)
      (goto-char (point-min))
      (while (not (eobp))
	(when (setq current-group 
		    (get-text-property (point) 'gnus-group))
	  (setq current-group (symbol-name current-group))
	  (when (string-match "\\(.+\\):\\(.+\\)" current-group)
	    (setq current-group (match-string 2 current-group)))
	  (setq common-prefix (substring current-group 0 
					 (mismatch previous-group current-group))
		common-dot-count (count ?. common-prefix)
		prefix (mapconcat (lambda (x) x) 
				  (make-list common-dot-count "  .") "")
		suffix (and (string-match
			     (format "\\([^.]*[.]\\)\\{%d\\}\\(.+\\)" common-dot-count) 
			     current-group)
			    (match-string 2 current-group))
		previous-group current-group)
	  (unless (zerop (length prefix))
	    (when (search-forward current-group (point-at-eol) t)
	      (let ((props (text-properties-at (1- (point)))))
		(replace-match (apply 'propertize (concat prefix suffix)
				      props))))))
	(forward-line 1)))))

(add-hook 'gnus-group-prepare-hook 'DE-collapse-group-names)
(add-hook 'gnus-group-update-group-hook 'DE-collapse-group-names)
--8<---------------cut here---------------end--------------->8---

This code assumes that you use "%G" in your group line format.

I think you can even omit the last hook if you don't use a three pane
buffer configuration.

-David



  reply	other threads:[~2009-05-30 14:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-27 20:02 David Abrahams
2009-05-27 21:57 ` David Engster
2009-05-28  4:42   ` David Abrahams
2009-05-28  9:43     ` David Engster
2009-05-29 14:51       ` David Abrahams
2009-05-29 16:50         ` David Engster
2009-05-29 18:02           ` David Abrahams
2009-05-29 22:31             ` David Abrahams
2009-05-30 14:46               ` David Engster [this message]
2009-06-09 19:22                 ` David Abrahams
2009-07-08 19:17     ` Ted Zlatanov

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=87vdnimyxd.fsf@randomsample.de \
    --to=deng@randomsample.de \
    --cc=ding@gnus.org \
    /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).