From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/15686 Path: main.gmane.org!not-for-mail From: Kai Grossjohann Newsgroups: gmane.emacs.gnus.general Subject: First experimental version of nnglimpse.el, or: Buglet report Date: 21 Jul 1998 00:10:29 +0200 Sender: owner-ding@hpc.uh.edu Message-ID: <871zrguqay.fsf@slowfox.do.uunet.de> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1035154673 23434 80.91.224.250 (20 Oct 2002 22:57:53 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 20 Oct 2002 22:57:53 +0000 (UTC) Return-Path: Original-Received: from gwyn.tux.org (gwyn.tux.org [207.96.122.8]) by altair.xemacs.org (8.9.1/8.9.1) with ESMTP id PAA28802 for ; Mon, 20 Jul 1998 15:36:17 -0700 Original-Received: from gizmo.hpc.uh.edu (gizmo.hpc.uh.edu [129.7.102.31]) by gwyn.tux.org (8.8.8/8.8.8) with ESMTP id SAA02017 for ; Mon, 20 Jul 1998 18:32:33 -0400 Original-Received: from sina.hpc.uh.edu (sina.hpc.uh.edu [129.7.3.5]) by gizmo.hpc.uh.edu (8.7.6/8.7.3) with ESMTP id RAS01282; Mon, 20 Jul 1998 17:02:42 -0500 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Mon, 20 Jul 1998 17:28:45 -0500 (CDT) Original-Received: from sclp3.sclp.com (root@sclp3.sclp.com [209.195.19.139]) by sina.hpc.uh.edu (8.7.3/8.7.3) with ESMTP id RAA16352 for ; Mon, 20 Jul 1998 17:28:33 -0500 (CDT) Original-Received: from waldorf.informatik.uni-dortmund.de (waldorf.informatik.uni-dortmund.de [129.217.4.42]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id SAA15222 for ; Mon, 20 Jul 1998 18:28:30 -0400 (EDT) Original-Received: from ramses.informatik.uni-dortmund.de (ramses.informatik.uni-dortmund.de [129.217.20.180]) by waldorf.informatik.uni-dortmund.de with SMTP id AAA04573 for ; Tue, 21 Jul 1998 00:28:28 +0200 (MES) Original-Received: by ramses.informatik.uni-dortmund.de id AAA09009; Tue, 21 Jul 1998 00:28:27 +0200 Original-To: ding@gnus.org X-Mailer: Gnus v5.6.24/Emacs 20.2 Original-Lines: 368 Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:15686 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:15686 Hi all, I have finally gotten around to taking a first shot at implementing nnglimpse.el, a way of searching your mail from within Gnus if you use Glimpse. Or you can read it as a bug report. Search for the string `Bug?' to see what it is. At least I think it's a bug. Don't forget your asbestos longjohns, this is pre-pre-pre-alpha code! (If you don't know what to do with the Lisp code, you don't have the right kind of longjohns, yet ;-) Limitations/assumptions: - Mail backend is (nnml "") - Mail is stored in $HOME/Mail - Glimpse index is stored in $HOME (uses `-H $HOME' option for running glimpse) - Pretends to be somewhat customizable, but probably isn't - Ugly code Still, I'm posting this in case someone actually wants to look at it and make some suggestions. How would I go about adding the group name the article came from to the output of nnglimpse? To the nnglimpse summary buffer? To the article buffer? Those of you who have indexed their mail with Glimpse: How have you set up your Glimpse index? Which files are indexed, where does the `-H' option point? What kinds of file names does Glimpse output? $HOME/Mail/... just like for me? Those of you who don't use nnml but instead use nnfolder or nnmbox or nnbabyl: Have you got any idea how to determine the article number from the output of Glimpse? Another idea: I'd like to define a function for the nnglimpse summary buffer which enters another summary buffer, showing the group the article is actually coming from. Since there is this nifty command gnus-summary-refer-thread it would be quite easy to create a summary buffer showing just the one article, then invoke this nifty command, to produce a summary buffer showing the whole thread the article belongs to. How does one go about defining a function for nnglimpse summary buffers only? How does one go about creating such a `subsidiary' summary buffer, such that one gets back to the nnglimpse summary buffer with `q'? kai -- You ate somebody? -- Just a leg. -- That's terrible! -- Not with mustard. (Terry Pratchett: Interesting Times) ;;; nnglimpse.el --- search mail with Glimpse ;; Copyright (C) 1998 Kai Großjohann ;; Author: Kai Großjohann ;; Keywords: news, mail, searching, glimpse ;; This file is not part of GNU Emacs. ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;;; Code: ;; Setup. (nnoo-declare nnglimpse) (nnoo-define-skeleton nnglimpse) (nnoo-define-basics nnglimpse) (gnus-declare-backend "nnglimpse" 'mail) ;; Variables. (defvoo nnglimpse-glimpse-program "glimpse" "Name of Glimpse executable.") (defvoo nnglimpse-glimpse-home (getenv "HOME") "Value of `-H' cmd line argument in running Glimpse.") (defvoo nnglimpse-mail-backend '(nnml "") "Backend that is used for storing mail. Currently, only nnml and nnmh (and compatible) backends are supported.") ;; Internal variables. (defvoo nnglimpse-current-query nil "Internal: stores current query (= group name).") (defvoo nnglimpse-articles nil "Internal: stores search result.") (defvoo nnglimpse-scratch-buffer (get-buffer-create "*nnglimpse*") "Internal: temporary buffer.") ;; Functions. ;; Gnus glue. (defun gnus-group-make-nnglimpse-group (query) (interactive "sGlimpse query: ") (gnus-group-read-ephemeral-group query '(nnglimpse "") t nil nil)) (define-key gnus-group-mode-map (kbd "G G") 'gnus-group-make-nnglimpse-group) ;; Interface functions. (deffoo nnglimpse-open-server (server &optional definitions) ;; just set server variables appropriately (nnoo-change-server 'nnglimpse server definitions) ) (deffoo nnglimpse-request-group (group &optional server fast) "GROUP is the Glimpse query." (nnglimpse-possibly-change-server server) (setq nnglimpse-articles (nnglimpse-run-glimpse group)) ;; Result data (save-excursion (set-buffer nntp-server-buffer) (nnheader-insert "211 %d %d %d %s\n" ; art nos: (nnglimpse-artlist-length nnglimpse-articles) ; total 1 ; lowest (nnglimpse-artlist-length nnglimpse-articles) ; highest group) ; group name )) ;; Ignores group argument -- uses nnglimpse-current-query instead. (deffoo nnglimpse-retrieve-headers (articles &optional group server fetch-old) (save-excursion (let ((artlist (copy-sequence articles)) (idx 1) (art nil) (artitem nil) (artgroup nil) (artno nil) (artfullgroup nil) (novitem nil) (novdata nil) (foo nil)) (while (not (null artlist)) (setq art (car artlist)) (or (numberp art) (nnheader-report "nnglimpse-retrieve-headers doesn't grok message ids: %s" art)) (setq artitem (nnglimpse-article-from-artlist nnglimpse-articles art)) (setq artgroup (nnglimpse-artitem-group artitem)) (setq artno (nnglimpse-artitem-number artitem)) (setq artfullgroup (gnus-group-prefixed-name artgroup nnglimpse-mail-backend)) ;; retrieve NOV or HEAD data for this article, transform into ;; NOV data and prepend to `novdata' (set-buffer nntp-server-buffer) (case (setq foo (gnus-retrieve-headers (list artno) artfullgroup nil)) (nov (setq novitem (nnheader-parse-nov))) (headers (setq novitem (nnheader-parse-head))) (t (nnheader-report "Don't support header type %s." foo))) ;; replace article number in original group with article number ;; in nnglimpse group (aset novitem 0 idx) (push novitem novdata) (setq artlist (cdr artlist)) (setq idx (1+ idx))) (setq novdata (nreverse novdata)) (set-buffer nntp-server-buffer) (erase-buffer) (mapcar 'nnheader-insert-nov novdata) 'nov))) ;(deffoo nnglimpse-close-server (&optional server) ; ; ... ; ) ;(deffoo nnglimpse-request-close () ; ; ... ; ) ;(deffoo nnglimpse-server-opened (&optional server) ; ; ... ; ) ;(deffoo nnglimpse-status-message (&optional server) ; ; ... ; ) (deffoo nnglimpse-request-article (article &optional group server to-buffer) (save-excursion (let* ((artitem (nnglimpse-article-from-artlist nnglimpse-articles article)) (artgroup (nnglimpse-artitem-group artitem)) (artno (nnglimpse-artitem-number artitem)) ;; Bug? ;; Why must we bind nntp-server-buffer here? It won't ;; work if `buf' is used, say. (Of course, the set-buffer ;; line below must then be updated, too.) (nntp-server-buffer (or to-buffer nntp-server-buffer))) (set-buffer nntp-server-buffer) (erase-buffer) (message "Requesting article %d from group %s" artno (gnus-group-prefixed-name artgroup nnglimpse-mail-backend)) (gnus-request-article artno (gnus-group-prefixed-name artgroup nnglimpse-mail-backend) nntp-server-buffer) (cons artgroup artno)))) ;(deffoo nnglimpse-close-group (group &optional server) ; ; ... ; ) ;(deffoo nnglimpse-request-list (&optional server) ; ; ... ; ) ;(deffoo nnglimpse-request-post (&optional server) ; ; ... ; ) ;;; Internal functions (defun nnglimpse-possibly-change-server (server) (unless (and server (nnglimpse-server-opened server)) (nnglimpse-open-server server))) (defun nnglimpse-run-glimpse (query) "Run given query against glimpse. Returns a list of (group name, file name) pairs." (save-excursion (let ((fnprefix (concat (getenv "HOME") "/Mail/")) (artlist nil)) (setq nnglimpse-current-query query) (set-buffer nnglimpse-scratch-buffer) (erase-buffer) (message "Doing glimpse query %s..." query) ;; CCC debug (if (string= query "xyzzy") [["wimis" 97] ["wimis" 127]] (call-process nnglimpse-glimpse-program nil ; input from /dev/null t ; output nil ; don't redisplay "-H" (getenv "HOME") ; search home dir "-W" ; match pattern in file "-i" "-l" ; misc options "-F" fnprefix ; only mail files query ; the query, in glimpse format ) (message "Doing glimpse query %s...done" query) (sit-for 0) ;; remove superfluous stuff from glimpse output (goto-char (point-min)) (delete-matching-lines "\\.overview~?$") (goto-char (point-min)) (while (re-search-forward (concat "^" fnprefix) nil t) (replace-match "")) ;; separate group name from article number with \t (goto-char (point-min)) (while (re-search-forward "\\(/\\)[0-9]+$" nil t) (replace-match "\t" t t nil 1)) ;; replace / with . in group names (subst-char-in-region (point-min) (point-max) ?/ ?. t) ;; massage buffer to contain some Lisp; ;; this depends on the artlist encoding internals ;; maybe this dependency should be removed? (goto-char (point-min)) (while (not (eobp)) (insert "[\"") (skip-chars-forward "^\t") (insert "\" ") (end-of-line) (insert "]") (forward-line 1)) (insert "])\n") (goto-char (point-min)) (insert "(setq artlist [\n") (eval-buffer) (sort* artlist (function (lambda (x y) (if (string-lessp (nnglimpse-artitem-group x) (nnglimpse-artitem-group y)) t (< (nnglimpse-artitem-number x) (nnglimpse-artitem-number y)))))) )))) ;; Data type `article list'. (defun nnglimpse-artlist-length (artlist) "Returns number of articles in artlist." (length artlist)) (defun nnglimpse-artlist-nth (artlist n) "Returns Nth artitem (element) of ARTLIST (first arg). N starts counting at 0." (elt artlist n)) (defun nnglimpse-article-from-artlist (artlist n) "Returns element from ARTLIST corresponding to number N. N starts counting at 1." (elt artlist (1- n))) (defun nnglimpse-artitem-group (artitem) "Returns group of artlist item ARTIITEM." (elt artitem 0)) (defun nnglimpse-artitem-number (artitem) "Returns number of artlist item ARTITEM." (elt artitem 1)) (defun nnglimpse-nth-artitem-group (artlist n) "Returns group of Nth artitem in ARTLIST." (nnglimpse-artitem-group (nnglimpse-artlist-nth artlist n))) (defun nnglimpse-nth-artitem-number (artlist n) "Returns number of Nth artitem in ARTLIST." (nnglimpse-artitem-number (nnglimpse-artlist-nth artlist n))) (defun nnglimpse-artlist-groups (artlist) "Returns a list of groups in the given ARTLIST." (let ((res nil) (with-dups nil)) ;; extract all groups, maybe with duplicates (setq with-dups (mapcar (function (lambda (x) (nnglimpse-artitem-group x))) artlist)) ;; remove duplicates (mapcar (function (lambda (x) (add-to-list 'res x))) with-dups) res)) (defun nnglimpse-artlist-for-group (artlist group) "Returns a list of all artitems in ARTLIST for GROUP." (let ((res nil) (idx 0)) (mapcar (function (lambda (x) (when (string= (nnglimpse-artitem-group x) group) (push (cons (nnglimpse-artitem-number x) idx) res) (setq idx (1+ idx))))) artlist) (nreverse res))) ;; The end. (provide 'nnglimpse)