* Summary format - the `u' spec
@ 2001-03-04 16:21 Harry Putnam
2001-03-04 17:54 ` Kai Großjohann
2001-03-04 21:21 ` Pavel Janík ml.
0 siblings, 2 replies; 9+ messages in thread
From: Harry Putnam @ 2001-03-04 16:21 UTC (permalink / raw)
The following message is a courtesy copy of an article
that has been posted to gnu.emacs.gnus as well.
>From gnus info; this looks like it can be made to do what I want.
`u'
User defined specifier. The next character in the format string
should be a letter. Gnus will call the function
`gnus-user-format-function-'`X', where `X' is the letter following
`%u'. The function will be passed the current header as argument.
The function should return a string, which will be inserted into
the summary just like information from any other summary specifier.
Hopefully I'm, correct in thinking the line that says:
"...The function will be passed the current header as argument."
Means that all header lines get scanned.
I want to use this option to cause gnus to scan the headers for
this pattern `^Keywords: \\[A\\] '. And if found, to insert the capital
letter found inside the [] into th summary display.
I think this is fairly simple, maybe but don't really have a clue how
to proceed.
Does someone have an example of using this function in the way I
described?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-04 16:21 Summary format - the `u' spec Harry Putnam
@ 2001-03-04 17:54 ` Kai Großjohann
2001-03-04 21:52 ` Harry Putnam
2001-03-04 21:21 ` Pavel Janík ml.
1 sibling, 1 reply; 9+ messages in thread
From: Kai Großjohann @ 2001-03-04 17:54 UTC (permalink / raw)
Cc: ding
On 04 Mar 2001, Harry Putnam wrote:
> Hopefully I'm, correct in thinking the line that says:
> "...The function will be passed the current header as argument."
> Means that all header lines get scanned.
Hm, no, not really. `Mail header' in this context (oh, how I love the
inconsistent terminology in Gnus!) is a structure which contains the
information from the NOV (or overview) file/data in a Lisp-predigested
form. For example, if X is such a header, then (mail-header-subject
X) returns a string, the subject of the message.
Such a header contains only those bits of information that are present
in the overview file. For nnml, you can put more information into the
overview file using the variables gnus-extra-headers and
nnmail-extra-headers. Not sure if this works with NNTP (news) servers.
> I want to use this option to cause gnus to scan the headers for this
> pattern `^Keywords: \\[A\\] '. And if found, to insert the capital
> letter found inside the [] into th summary display.
Ah. Yes. Hm. What you want is to
(add-to-list 'nnmail-extra-headers 'Keywords)
(add-to-list 'gnus-extra-headers 'Keywords)
And then you can do:
(defun gnus-user-format-function-H (header)
(let* ((xtra (mail-header-extra header))
(kw (cdr (assq 'Keywords xtra))))
(if (and kw (stringp kw))
(substring kw 0 5)
" ")))
This is untested. Not sure if it works. It tries to print the first
5 or 6 characters of the Keywords header, or spaces (if there is no
Keywords header).
Does this work, and can you take it from here?
kai
--
Be indiscrete. Do it continuously.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-04 16:21 Summary format - the `u' spec Harry Putnam
2001-03-04 17:54 ` Kai Großjohann
@ 2001-03-04 21:21 ` Pavel Janík ml.
1 sibling, 0 replies; 9+ messages in thread
From: Pavel Janík ml. @ 2001-03-04 21:21 UTC (permalink / raw)
Cc: ding
From: Harry Putnam <reader@newsguy.com>
Date: 04 Mar 2001 08:21:59 -0800
Hi Harry,
> I want to use this option to cause gnus to scan the headers for
> this pattern `^Keywords: \\[A\\] '. And if found, to insert the capital
> letter found inside the [] into th summary display.
>
> I think this is fairly simple, maybe but don't really have a clue how
> to proceed.
>
> Does someone have an example of using this function in the way I
> described?
yes. I use something similar. This is workaround for tags which rmail can
do and gnus can not (it is already in the wish list). If the mail has
X-Annotations: header, the rest of the line is displayed in the summary:
(setq gnus-extra-headers '(To Cc X-Annotations))
(setq nnmail-extra-headers gnus-extra-headers)
(defun gnus-user-format-function-X (header)
"My user-defined function for annotations."
(let ((my-extra-headers (mail-header-extra gnus-tmp-header)))
; Search for X-Annotations
(while (and my-extra-headers (not (eq (car (car my-extra-headers)) 'X-Annotations)))
(setq my-extra-headers (cdr my-extra-headers)))
(setq my-extra-headers (cdr (car my-extra-headers)))
(if my-extra-headers
(concat "{" (rfc2047-decode-string my-extra-headers) "} ")
"")))
Tested, I use it almost everyday.
Hmm, isn't this the time where we should implement this? There are at least
three people who want it :-)
--
Pavel Janík ml.
Pavel@Janik.cz
http://www.janik.cz
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-04 17:54 ` Kai Großjohann
@ 2001-03-04 21:52 ` Harry Putnam
2001-03-05 0:39 ` Alex Schroeder
0 siblings, 1 reply; 9+ messages in thread
From: Harry Putnam @ 2001-03-04 21:52 UTC (permalink / raw)
Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:
> On 04 Mar 2001, Harry Putnam wrote:
>
> > Hopefully I'm, correct in thinking the line that says:
> > "...The function will be passed the current header as argument."
> > Means that all header lines get scanned.
>
> Hm, no, not really. `Mail header' in this context (oh, how I love the
> inconsistent terminology in Gnus!) is a structure which contains the
> information from the NOV (or overview) file/data in a Lisp-predigested
> form. For example, if X is such a header, then (mail-header-subject
> X) returns a string, the subject of the message.
Well, still close enough to get what I want here. I do understand the
NOV file a bit and as luck would have it I've had code in .gnus for a
long time to insert a `Keywords' header into the .overiew file. And
have them displayed in the article view buffer.
[...]
> > I want to use this option to cause gnus to scan the headers for this
> > pattern `^Keywords: \\[A\\] '. And if found, to insert the capital
> > letter found inside the [] into th summary display.
[...]
> And then you can do:
>
> (defun gnus-user-format-function-H (header)
> (let* ((xtra (mail-header-extra header))
> (kw (cdr (assq 'Keywords xtra))))
> (if (and kw (stringp kw))
> (substring kw 0 5)
> " ")))
>
> This is untested. Not sure if it works. It tries to print the first
> 5 or 6 characters of the Keywords header, or spaces (if there is no
> Keywords header).
>
> Does this work, and can you take it from here?
Yes it works, and I see how it works and how to adjust what gets
printed, at least somewhat. I don't really follow all the ins and
outs of even this simple code. But I see that this:
(defun gnus-user-format-function-H (header)
(let* ((xtra (mail-header-extra header))
(kw (cdr (assq 'Keywords xtra))))
(if (and kw (stringp kw))
(substring kw 4 5)
"N")))
Given a keywords header like:
Keywords: [ed]A something
And a format string like:
"%2t%U%R%7d%z%I%(%[%uH%4L: %-20,20f%]%) %s\n"
(inserted =>)^^^
will give a summary buffer line like:
(Printing an `N' if no keyword line)
1R 07-Oct [A 161: me ] [ed]V [comp.editors] Vim - append to file
inserted => ^^
I guess what I really want to know is if it can be made to match a
regexp instead of a a static number of characters in a string. And to
return that portion that matches or even better to edit the portion
that matches in some predictable way.
I see the first stringmatch thing is to match the keyword line itself
and I need that, and even bettter your trial code does do that
admirably.
Once we have a match, then the code looks as if it grabs a
predetermined number of characters from the Keyword header begining
with the first character after `:' (0 5).
And I do see how one would adjust that number, if need be.
I guess what I want is, once the keyword is matched, to take the
string after `:' and pluck a pattern from it leaving the rest behind.
Something like what one would do with sed (in bash) in this fashion.
echo "Keywords: [A] blabbity blah blick"\
|sed 's/^\(Keywords: \[\)\(A\)\(\]\).*/\2/'
A
Plucking out only the `A'
Or with awk
echo "Keywords: [A] blabbity blah blick"\
|awk -vRS="\\\[A\\\]" '{gsub (/\[|\]/,"",RT);print RT;ORS=FS}'
A
So once the keywords line is matched does elisp offer a pattern
matching command that returns the matched portion?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-04 21:52 ` Harry Putnam
@ 2001-03-05 0:39 ` Alex Schroeder
2001-03-05 1:07 ` Harry Putnam
2001-03-05 9:29 ` Kai Großjohann
0 siblings, 2 replies; 9+ messages in thread
From: Alex Schroeder @ 2001-03-05 0:39 UTC (permalink / raw)
Harry Putnam <reader@newsguy.com> writes:
> So once the keywords line is matched does elisp offer a pattern
> matching command that returns the matched portion?
Hm, you can probably use normal elisp to do it:
(if (string-match "\\[\\([A-Z]\\)\\]" some-string)
(match-string 0)
" ")
Or something like that.
Alex.
--
http://www.geocities.com/kensanata/
"Your .emacs is either in C:\ or in the directory of %HOME% under Win32."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-05 0:39 ` Alex Schroeder
@ 2001-03-05 1:07 ` Harry Putnam
2001-03-05 20:52 ` Alex Schroeder
2001-03-05 9:29 ` Kai Großjohann
1 sibling, 1 reply; 9+ messages in thread
From: Harry Putnam @ 2001-03-05 1:07 UTC (permalink / raw)
Alex Schroeder <alex@gnu.org> writes:
> Harry Putnam <reader@newsguy.com> writes:
>
> > So once the keywords line is matched does elisp offer a pattern
> > matching command that returns the matched portion?
>
> Hm, you can probably use normal elisp to do it:
>
> (if (string-match "\\[\\([A-Z]\\)\\]" some-string)
> (match-string 0)
> " ")
>
> Or something like that.
OK, but revealing the bottomless depths of my lisp ignorance:
How does this fit into the rest of the function?
I tried just splicing it in there a couple ways but of course that
ain't going to fly.
(defun gnus-user-format-function-H (header)
(let* ((xtra (mail-header-extra header))
(kw (cdr (assq 'Keywords xtra))))
(if (and kw (stringp kw)
(if (string-match "\\[\\([A-Z]\\)\\]" some-string)
(match-string 0)
" ")))))
(defun gnus-user-format-function-H (header)
(let* ((xtra (mail-header-extra header))
(kw (cdr (assq 'Keywords xtra))))
(if (and kw (stringp kw))
(string-match "\\[\\([A-Z]\\)\\]" some-string)
(match-string 0)
" ")))
NOT!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-05 0:39 ` Alex Schroeder
2001-03-05 1:07 ` Harry Putnam
@ 2001-03-05 9:29 ` Kai Großjohann
1 sibling, 0 replies; 9+ messages in thread
From: Kai Großjohann @ 2001-03-05 9:29 UTC (permalink / raw)
Cc: ding
On 05 Mar 2001, Alex Schroeder wrote:
> (if (string-match "\\[\\([A-Z]\\)\\]" some-string)
> (match-string 0)
> " ")
That should be (match-string 0 some-string). Or maybe (match-string 1
some-string), since Harry wants the stuff _inside_ the square brackets.
kai
--
Be indiscrete. Do it continuously.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-05 1:07 ` Harry Putnam
@ 2001-03-05 20:52 ` Alex Schroeder
2001-03-05 23:59 ` Harry Putnam
0 siblings, 1 reply; 9+ messages in thread
From: Alex Schroeder @ 2001-03-05 20:52 UTC (permalink / raw)
Harry Putnam <reader@newsguy.com> writes:
> (defun gnus-user-format-function-H (header)
> (let* ((xtra (mail-header-extra header))
> (kw (cdr (assq 'Keywords xtra))))
> (if (and kw (stringp kw)
> (if (string-match "\\[\\([A-Z]\\)\\]" some-string)
> (match-string 0)
> " ")))))
How about this (untested):
(defun gnus-user-format-function-H (header)
(let* ((xtra (mail-header-extra header))
(kw (cdr (assq 'Keywords xtra))))
(if (and (stringp kw)
(string-match "\\[\\([A-Z]\\)\\]" kw))
(match-string 1 kw)
" ")))
This assumes kw gets set correctly, I have never done this
mail-header-extra stuff, so you're on your own. :)
Alex.
--
http://www.geocities.com/kensanata/
"Emacs 21 will be out when it comes out. No beta available."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Summary format - the `u' spec
2001-03-05 20:52 ` Alex Schroeder
@ 2001-03-05 23:59 ` Harry Putnam
0 siblings, 0 replies; 9+ messages in thread
From: Harry Putnam @ 2001-03-05 23:59 UTC (permalink / raw)
Alex Schroeder <alex@gnu.org> writes:
> How about this (untested):
>
> (defun gnus-user-format-function-H (header)
> (let* ((xtra (mail-header-extra header))
> (kw (cdr (assq 'Keywords xtra))))
> (if (and (stringp kw)
> (string-match "\\[\\([A-Z]\\)\\]" kw))
> (match-string 1 kw)
> " ")))
>
> This assumes kw gets set correctly, I have never done this
> mail-header-extra stuff, so you're on your own. :)
Haa... right out of the box this baby works.
Thanks Alex
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2001-03-05 23:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-04 16:21 Summary format - the `u' spec Harry Putnam
2001-03-04 17:54 ` Kai Großjohann
2001-03-04 21:52 ` Harry Putnam
2001-03-05 0:39 ` Alex Schroeder
2001-03-05 1:07 ` Harry Putnam
2001-03-05 20:52 ` Alex Schroeder
2001-03-05 23:59 ` Harry Putnam
2001-03-05 9:29 ` Kai Großjohann
2001-03-04 21:21 ` Pavel Janík ml.
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).