;;; nnir.el --- search mail with various search engines -*- coding: iso-8859-1 -*-
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+;; 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Kai Großjohann <grossjohann@ls6.cs.uni-dortmund.de>
;; Swish-e and Swish++ backends by:
;; IMAP search improved by Daniel Pittman <daniel@rimspace.net>.
;; nnmaildir support for Swish++ and Namazu backends by:
;; Justus Piater <Justus <at> Piater.name>
+;; Keywords: news mail searching ir
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
;; TODO: Documentation in the Gnus manual
;; `gnus-group-make-nnir-group' might be described in (info
;; "(gnus)Foreign Groups") as well.
-;; Keywords: news mail searching ir
-
-;; This file is 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 3, 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
-
-;;; Commentary:
;; The most recent version of this can always be fetched from the Gnus
;; CVS repository. See http://www.gnus.org/ for more information.
(require 'gnus-sum)
(require 'message)
(require 'gnus-util)
-(eval-and-compile
+(eval-when-compile
(require 'cl))
(nnoo-declare nnir)
`((wais nnir-run-waissearch
())
(imap nnir-run-imap
- ((criteria
+ ((criteria
"Search in: " ; Prompt
,nnir-imap-search-arguments ; alist for completing
nil ; no filtering
;; `nnir-swish-e-additional-switches'
(make-obsolete-variable 'nnir-swish-e-index-file
- 'nnir-swish-e-index-files)
+ 'nnir-swish-e-index-files "Emacs 23.1")
(defcustom nnir-swish-e-index-file
(expand-file-name "~/Mail/index.swish-e")
"*Index file for swish-e.
gnus-current-window-configuration)
nil)))
+(eval-when-compile
+ (when (featurep 'xemacs)
+ ;; The `kbd' macro requires that the `read-kbd-macro' macro is available.
+ (require 'edmacro)))
+
(defun nnir-group-mode-hook ()
(define-key gnus-group-mode-map (kbd "G G")
'gnus-group-make-nnir-group))
(defmacro nnir-add-result (dirnam artno score prefix server artlist)
- "Ask `nnir-compose-result' to construct a result vector,
+ "Ask `nnir-compose-result' to construct a result vector,
and if it is non-nil, add it to artlist."
`(let ((result (nnir-compose-result ,dirnam ,artno ,score ,prefix ,server)))
(when (not (null result))
(unless (string-match prefix dirnam)
(nnheader-report 'nnir "Dir name %s doesn't contain prefix %s"
dirnam prefix))
- (setq group (substitute ?. ?/ (replace-match "" t t dirnam)))
+ (setq group (gnus-replace-in-string
+ (replace-match "" t t dirnam) "/" "."))
(push (vector (nnir-group-full-name group server)
(string-to-number artno)
(string-to-number score))
artlist))
(message "Massaging waissearch output...done")
(apply 'vector
- (sort* artlist
- (function (lambda (x y)
- (> (nnir-artitem-rsv x)
- (nnir-artitem-rsv y)))))))))
+ (sort artlist
+ (function (lambda (x y)
+ (> (nnir-artitem-rsv x)
+ (nnir-artitem-rsv y)))))))))
;; IMAP interface.
;; todo:
to an arbitrary query string to the end user.
The search is always case-insensitive, as defined by RFC2060, and supports
-the following features (inspired by the Google search input language):
+the following features (inspired by the Google search input language):
Automatic \"and\" queries
If you specify multiple words then they will be treated as an \"and\"
"Are we at the end of input?"
(skip-chars-forward "[[:blank:]]")
(looking-at "$"))
-
+
;; Swish++ interface.
;; -cc- Todo
;; Sort by score
(apply 'vector
- (sort* artlist
- (function (lambda (x y)
- (> (nnir-artitem-rsv x)
- (nnir-artitem-rsv y)))))))))
+ (sort artlist
+ (function (lambda (x y)
+ (> (nnir-artitem-rsv x)
+ (nnir-artitem-rsv y)))))))))
;; Swish-E interface.
(defun nnir-run-swish-e (query server &optional group)
;; eliminate all ".", "/", "\" from beginning. Always matches.
(string-match "^[./\\]*\\(.*\\)$" dirnam)
;; "/" -> "."
- (setq group (substitute ?. ?/ (match-string 1 dirnam)))
+ (setq group (gnus-replace-in-string (match-string 1 dirnam) "/" "."))
;; Windows "\\" -> "."
- (setq group (substitute ?. ?\\ group))
+ (setq group (gnus-replace-in-string group "\\\\" "."))
(push (vector (nnir-group-full-name group server)
(string-to-number artno)
;; Sort by score
(apply 'vector
- (sort* artlist
- (function (lambda (x y)
- (> (nnir-artitem-rsv x)
- (nnir-artitem-rsv y)))))))))
+ (sort artlist
+ (function (lambda (x y)
+ (> (nnir-artitem-rsv x)
+ (nnir-artitem-rsv y)))))))))
;; HyREX interface
(defun nnir-run-hyrex (query server &optional group)
score (match-string 3))
(when (string-match prefix dirnam)
(setq dirnam (replace-match "" t t dirnam)))
- (push (vector (nnir-group-full-name (substitute ?. ?/ dirnam) server)
+ (push (vector (nnir-group-full-name
+ (gnus-replace-in-string dirnam "/" ".") server)
(string-to-number artno)
(string-to-number score))
artlist))
(message "Massaging hyrex-search output...done.")
(apply 'vector
- (sort* artlist
- (function (lambda (x y)
- (if (string-lessp (nnir-artitem-group x)
- (nnir-artitem-group y))
- t
- (< (nnir-artitem-number x)
- (nnir-artitem-number y)))))))
+ (sort artlist
+ (function (lambda (x y)
+ (if (string-lessp (nnir-artitem-group x)
+ (nnir-artitem-group y))
+ t
+ (< (nnir-artitem-number x)
+ (nnir-artitem-number y)))))))
)))
;; Namazu interface
;; sort artlist by score
(apply 'vector
- (sort* artlist
- (function (lambda (x y)
- (> (nnir-artitem-rsv x)
- (nnir-artitem-rsv y)))))))))
+ (sort artlist
+ (function (lambda (x y)
+ (> (nnir-artitem-rsv x)
+ (nnir-artitem-rsv y)))))))))
(defun nnir-run-find-grep (query server &optional group)
"Run find and grep to obtain matching articles."
"."
;; Try accessing the group literally as well as
;; interpreting dots as directory separators so the
- ;; engine works with plain nnml as well as the Gnus
- ;; Cache.
- (find-if 'file-directory-p
- (let ((group (gnus-group-real-name group)))
- (list group (gnus-replace-in-string group "\\." "/" t)))))))
+ ;; engine works with plain nnml as well as the Gnus Cache.
+ (let ((group (gnus-group-real-name group)))
+ ;; Replace cl-func find-if.
+ (if (file-directory-p group)
+ group
+ (if (file-directory-p
+ (setq group (gnus-replace-in-string group "\\." "/" t)))
+ group))))))
(unless group
(error "Cannot locate directory for group"))
(save-excursion
'call-process "find" nil t
"find" group "-type" "f" "-name" "[0-9]*" "-exec"
"grep"
- `("-l" ,@(and grep-options (split-string grep-options "\\s-" t))
+ `("-l" ,@(and grep-options
+ ;; Note: the 3rd arg of `split-string' is not
+ ;; available in Emacs 21.
+ (delete "" (split-string grep-options "\\s-")))
"-e" ,regexp "{}" "+"))))
;; Translate relative paths to group names.
(while (not (eobp))
- (let* ((path (split-string
- (buffer-substring (point) (line-end-position)) "/" t))
+ (let* ((path (delete
+ ""
+ (split-string
+ (buffer-substring (point) (line-end-position)) "/")))
(art (string-to-number (car (last path)))))
(while (string= "." (car path))
(setq path (cdr path)))
- (let ((group (mapconcat 'identity (subseq path 0 -1) ".")))
+ (let ((group (mapconcat 'identity
+ ;; Replace cl-func: (subseq path 0 -1)
+ (let ((end (1- (length path)))
+ res)
+ (while (>= (setq end (1- end)) 0)
+ (push (pop path) res))
+ (nreverse res))
+ ".")))
(push (vector (nnir-group-full-name group server) art 0)
artlist))
(forward-line 1)))
;; The end.
(provide 'nnir)
-;;; arch-tag: 9b3fecf8-4397-4bbb-bf3c-6ac3cbbc6664
+;; arch-tag: 9b3fecf8-4397-4bbb-bf3c-6ac3cbbc6664
+;;; nnir.el ends here