Mercurial > emacs
comparison lisp/mh-e/mh-search.el @ 90291:d6f8fe3307c8
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-11
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 34-42)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 14-17)
- Update from CVS
- Merge from emacs--devo--0
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sat, 04 Feb 2006 01:01:38 +0000 |
parents | 52ef8d8ecd83 |
children | 156eafa22e3e |
comparison
equal
deleted
inserted
replaced
90290:6a1672fcf6ae | 90291:d6f8fe3307c8 |
---|---|
49 (require 'mh-e) | 49 (require 'mh-e) |
50 (mh-require-cl) | 50 (mh-require-cl) |
51 | 51 |
52 (require 'gnus-util) | 52 (require 'gnus-util) |
53 (require 'imenu) | 53 (require 'imenu) |
54 (require 'which-func nil t) | |
55 | 54 |
56 (defvar mh-searcher nil | 55 (defvar mh-searcher nil |
57 "Cached value of chosen search program.") | 56 "Cached value of chosen search program.") |
58 | 57 |
59 (defvar mh-search-function nil | 58 (defvar mh-search-function nil |
356 "---------\n") | 355 "---------\n") |
357 (mh-search-mode) | 356 (mh-search-mode) |
358 (goto-char (point-min)) | 357 (goto-char (point-min)) |
359 (dotimes (i 5) | 358 (dotimes (i 5) |
360 (add-text-properties (point) (1+ (point)) '(front-sticky t)) | 359 (add-text-properties (point) (1+ (point)) '(front-sticky t)) |
361 (add-text-properties (- (line-end-position) 2) (1- (line-end-position)) | 360 (add-text-properties (- (mh-line-end-position) 2) |
361 (1- (mh-line-end-position)) | |
362 '(rear-nonsticky t)) | 362 '(rear-nonsticky t)) |
363 (add-text-properties (point) (1- (line-end-position)) '(read-only t)) | 363 (add-text-properties (point) (1- (mh-line-end-position)) '(read-only t)) |
364 (forward-line)) | 364 (forward-line)) |
365 (add-text-properties (point) (1+ (point)) '(front-sticky t)) | 365 (add-text-properties (point) (1+ (point)) '(front-sticky t)) |
366 (add-text-properties (point) (1- (line-end-position)) '(read-only t)) | 366 (add-text-properties (point) (1- (mh-line-end-position)) '(read-only t)) |
367 (goto-char (point-max))) | 367 (goto-char (point-max))) |
368 | 368 |
369 ;; Sequence Searches | 369 ;; Sequence Searches |
370 | 370 |
371 ;;;###mh-autoload | 371 ;;;###mh-autoload |
524 (let (folder msg) | 524 (let (folder msg) |
525 (save-excursion | 525 (save-excursion |
526 (cond ((and (bolp) (eolp)) | 526 (cond ((and (bolp) (eolp)) |
527 (ignore-errors (forward-line -1)) | 527 (ignore-errors (forward-line -1)) |
528 (setq msg (mh-get-msg-num t))) | 528 (setq msg (mh-get-msg-num t))) |
529 ((equal (char-after (line-beginning-position)) ?+) | 529 ((equal (char-after (mh-line-beginning-position)) ?+) |
530 (setq folder (buffer-substring-no-properties | 530 (setq folder (buffer-substring-no-properties |
531 (line-beginning-position) (line-end-position)))) | 531 (mh-line-beginning-position) |
532 (mh-line-end-position)))) | |
532 (t (setq msg (mh-get-msg-num t))))) | 533 (t (setq msg (mh-get-msg-num t))))) |
533 (when (not folder) | 534 (when (not folder) |
534 (setq folder (car (gethash (gethash msg mh-index-msg-checksum-map) | 535 (setq folder (car (gethash (gethash msg mh-index-msg-checksum-map) |
535 mh-index-checksum-origin-map)))) | 536 mh-index-checksum-origin-map)))) |
536 (when (or (not (get-buffer folder)) | 537 (when (or (not (get-buffer folder)) |
653 (let ((pattern-list ()) | 654 (let ((pattern-list ()) |
654 (in-body-flag nil) | 655 (in-body-flag nil) |
655 start begin) | 656 start begin) |
656 (goto-char (point-min)) | 657 (goto-char (point-min)) |
657 (while (not (eobp)) | 658 (while (not (eobp)) |
658 (if (search-forward "--------" (line-end-position) t) | 659 (if (search-forward "--------" (mh-line-end-position) t) |
659 (setq in-body-flag t) | 660 (setq in-body-flag t) |
660 (beginning-of-line) | 661 (beginning-of-line) |
661 (setq begin (point)) | 662 (setq begin (point)) |
662 (setq start (if in-body-flag | 663 (setq start (if in-body-flag |
663 (point) | 664 (point) |
664 (search-forward ":" (line-end-position) t) | 665 (search-forward ":" (mh-line-end-position) t) |
665 (point))) | 666 (point))) |
666 (push (cons (and (not in-body-flag) | 667 (push (cons (and (not in-body-flag) |
667 (intern (downcase | 668 (intern (downcase |
668 (buffer-substring-no-properties | 669 (buffer-substring-no-properties |
669 begin (1- start))))) | 670 begin (1- start))))) |
670 (mh-index-parse-search-regexp | 671 (mh-index-parse-search-regexp |
671 (buffer-substring-no-properties | 672 (buffer-substring-no-properties |
672 start (line-end-position)))) | 673 start (mh-line-end-position)))) |
673 pattern-list)) | 674 pattern-list)) |
674 (forward-line)) | 675 (forward-line)) |
675 pattern-list))) | 676 pattern-list))) |
676 | 677 |
677 (defun mh-index-parse-search-regexp (input-string) | 678 (defun mh-index-parse-search-regexp (input-string) |
977 (block nil | 978 (block nil |
978 (when (or (eobp) (equal (char-after (point)) ?.)) | 979 (when (or (eobp) (equal (char-after (point)) ?.)) |
979 (return nil)) | 980 (return nil)) |
980 (when (equal (char-after (point)) ?#) | 981 (when (equal (char-after (point)) ?#) |
981 (return 'error)) | 982 (return 'error)) |
982 (let* ((start (search-forward " " (line-end-position) t)) | 983 (let* ((start (search-forward " " (mh-line-end-position) t)) |
983 (end (search-forward " " (line-end-position) t))) | 984 (end (search-forward " " (mh-line-end-position) t))) |
984 (unless (and start end) | 985 (unless (and start end) |
985 (return 'error)) | 986 (return 'error)) |
986 (setq end (1- end)) | 987 (setq end (1- end)) |
987 (unless (file-exists-p (buffer-substring-no-properties start end)) | 988 (unless (file-exists-p (buffer-substring-no-properties start end)) |
988 (return 'error)) | 989 (return 'error)) |
1056 (return nil)) | 1057 (return nil)) |
1057 (unless (eq (char-after) ?/) | 1058 (unless (eq (char-after) ?/) |
1058 (return 'error)) | 1059 (return 'error)) |
1059 (let ((start (point)) | 1060 (let ((start (point)) |
1060 end msg-start) | 1061 end msg-start) |
1061 (setq end (line-end-position)) | 1062 (setq end (mh-line-end-position)) |
1062 (unless (search-forward mh-mairix-folder end t) | 1063 (unless (search-forward mh-mairix-folder end t) |
1063 (return 'error)) | 1064 (return 'error)) |
1064 (goto-char (match-beginning 0)) | 1065 (goto-char (match-beginning 0)) |
1065 (unless (equal (point) start) | 1066 (unless (equal (point) start) |
1066 (return 'error)) | 1067 (return 'error)) |
1189 "Get the next result from namazu output." | 1190 "Get the next result from namazu output." |
1190 (prog1 | 1191 (prog1 |
1191 (block nil | 1192 (block nil |
1192 (when (eobp) (return nil)) | 1193 (when (eobp) (return nil)) |
1193 (let ((file-name (buffer-substring-no-properties | 1194 (let ((file-name (buffer-substring-no-properties |
1194 (point) (line-end-position)))) | 1195 (point) (mh-line-end-position)))) |
1195 (unless (equal (string-match mh-namazu-folder file-name) 0) | 1196 (unless (equal (string-match mh-namazu-folder file-name) 0) |
1196 (return 'error)) | 1197 (return 'error)) |
1197 (unless (file-exists-p file-name) | 1198 (unless (file-exists-p file-name) |
1198 (return 'error)) | 1199 (return 'error)) |
1199 (string-match mh-user-path file-name) | 1200 (string-match mh-user-path file-name) |
1237 (defun mh-pick-next-result () | 1238 (defun mh-pick-next-result () |
1238 "Return the next pick search result." | 1239 "Return the next pick search result." |
1239 (prog1 | 1240 (prog1 |
1240 (block nil | 1241 (block nil |
1241 (when (eobp) (return nil)) | 1242 (when (eobp) (return nil)) |
1242 (when (search-forward-regexp "^\+" (line-end-position) t) | 1243 (when (search-forward-regexp "^\+" (mh-line-end-position) t) |
1243 (setq mh-index-pick-folder | 1244 (setq mh-index-pick-folder |
1244 (buffer-substring-no-properties (line-beginning-position) | 1245 (buffer-substring-no-properties (mh-line-beginning-position) |
1245 (line-end-position))) | 1246 (mh-line-end-position))) |
1246 (return 'error)) | 1247 (return 'error)) |
1247 (unless (search-forward-regexp "^[1-9][0-9]*$" (line-end-position) t) | 1248 (unless (search-forward-regexp "^[1-9][0-9]*$" (mh-line-end-position) t) |
1248 (return 'error)) | 1249 (return 'error)) |
1249 (list mh-index-pick-folder | 1250 (list mh-index-pick-folder |
1250 (string-to-number | 1251 (string-to-number |
1251 (buffer-substring-no-properties (line-beginning-position) | 1252 (buffer-substring-no-properties (mh-line-beginning-position) |
1252 (line-end-position))) | 1253 (mh-line-end-position))) |
1253 nil)) | 1254 nil)) |
1254 (forward-line))) | 1255 (forward-line))) |
1255 | 1256 |
1256 ;; All implementations of pick have special options -cc, -date, -from and | 1257 ;; All implementations of pick have special options -cc, -date, -from and |
1257 ;; -subject that allow to search for corresponding components. Any other | 1258 ;; -subject that allow to search for corresponding components. Any other |
1324 record is invalid return 'error." | 1325 record is invalid return 'error." |
1325 (prog1 | 1326 (prog1 |
1326 (block nil | 1327 (block nil |
1327 (when (eobp) | 1328 (when (eobp) |
1328 (return nil)) | 1329 (return nil)) |
1329 (let ((eol-pos (line-end-position)) | 1330 (let ((eol-pos (mh-line-end-position)) |
1330 (bol-pos (line-beginning-position)) | 1331 (bol-pos (mh-line-beginning-position)) |
1331 folder-start msg-end) | 1332 folder-start msg-end) |
1332 (goto-char bol-pos) | 1333 (goto-char bol-pos) |
1333 (unless (search-forward mh-user-path eol-pos t) | 1334 (unless (search-forward mh-user-path eol-pos t) |
1334 (return 'error)) | 1335 (return 'error)) |
1335 (setq folder-start (point)) | 1336 (setq folder-start (point)) |
1406 (delete-region (point) (progn (forward-line) (point))) | 1407 (delete-region (point) (progn (forward-line) (point))) |
1407 (forward-line))) | 1408 (forward-line))) |
1408 (when cur-msg (mh-goto-msg cur-msg t t)) | 1409 (when cur-msg (mh-goto-msg cur-msg t t)) |
1409 (set-buffer-modified-p old-buffer-modified-flag))) | 1410 (set-buffer-modified-p old-buffer-modified-flag))) |
1410 | 1411 |
1412 (mh-require 'which-func nil t) | |
1413 | |
1411 ;; Shush compiler. | 1414 ;; Shush compiler. |
1412 (eval-when-compile (mh-do-in-xemacs (defvar which-func-mode))) | 1415 (eval-when-compile |
1416 (if (or mh-xemacs-flag (< emacs-major-version 22)) | |
1417 (defvar which-func-mode))) | |
1413 | 1418 |
1414 ;;;###mh-autoload | 1419 ;;;###mh-autoload |
1415 (defun mh-index-create-imenu-index () | 1420 (defun mh-index-create-imenu-index () |
1416 "Create alist of folder names and positions in index folder buffers." | 1421 "Create alist of folder names and positions in index folder buffers." |
1417 (save-excursion | 1422 (save-excursion |
1421 (goto-char (point-min)) | 1426 (goto-char (point-min)) |
1422 (while (re-search-forward "^+" nil t) | 1427 (while (re-search-forward "^+" nil t) |
1423 (save-excursion | 1428 (save-excursion |
1424 (beginning-of-line) | 1429 (beginning-of-line) |
1425 (push (cons (buffer-substring-no-properties | 1430 (push (cons (buffer-substring-no-properties |
1426 (point) (line-end-position)) | 1431 (point) (mh-line-end-position)) |
1427 (set-marker (make-marker) (point))) | 1432 (set-marker (make-marker) (point))) |
1428 alist))) | 1433 alist))) |
1429 (setq imenu--index-alist (nreverse alist))))) | 1434 (setq imenu--index-alist (nreverse alist))))) |
1430 | 1435 |
1431 ;;;###mh-autoload | 1436 ;;;###mh-autoload |
1694 "Check if MSG in FOLDER has X-MHE-Checksum header value of CHECKSUM." | 1699 "Check if MSG in FOLDER has X-MHE-Checksum header value of CHECKSUM." |
1695 (with-temp-buffer | 1700 (with-temp-buffer |
1696 (mh-exec-cmd-output mh-scan-prog nil "-width" "80" | 1701 (mh-exec-cmd-output mh-scan-prog nil "-width" "80" |
1697 "-format" "%{x-mhe-checksum}\n" folder msg) | 1702 "-format" "%{x-mhe-checksum}\n" folder msg) |
1698 (goto-char (point-min)) | 1703 (goto-char (point-min)) |
1699 (string-equal (buffer-substring-no-properties (point) (line-end-position)) | 1704 (string-equal (buffer-substring-no-properties |
1705 (point) (mh-line-end-position)) | |
1700 checksum))) | 1706 checksum))) |
1701 | 1707 |
1702 | 1708 |
1703 | 1709 |
1704 ;;; Serialization of Index Data | 1710 ;;; Serialization of Index Data |
1803 (setq mh-checksum-parser #'mh-md5-parser)) | 1809 (setq mh-checksum-parser #'mh-md5-parser)) |
1804 (t (error "No suitable checksum program")))))) | 1810 (t (error "No suitable checksum program")))))) |
1805 | 1811 |
1806 (defun mh-md5sum-parser () | 1812 (defun mh-md5sum-parser () |
1807 "Parse md5sum output." | 1813 "Parse md5sum output." |
1808 (let ((begin (line-beginning-position)) | 1814 (let ((begin (mh-line-beginning-position)) |
1809 (end (line-end-position)) | 1815 (end (mh-line-end-position)) |
1810 first-space last-slash) | 1816 first-space last-slash) |
1811 (setq first-space (search-forward " " end t)) | 1817 (setq first-space (search-forward " " end t)) |
1812 (goto-char end) | 1818 (goto-char end) |
1813 (setq last-slash (search-backward "/" begin t)) | 1819 (setq last-slash (search-backward "/" begin t)) |
1814 (cond ((and first-space last-slash) | 1820 (cond ((and first-space last-slash) |
1817 (buffer-substring-no-properties begin (1- first-space)))) | 1823 (buffer-substring-no-properties begin (1- first-space)))) |
1818 (t (cons nil nil))))) | 1824 (t (cons nil nil))))) |
1819 | 1825 |
1820 (defun mh-openssl-parser () | 1826 (defun mh-openssl-parser () |
1821 "Parse openssl output." | 1827 "Parse openssl output." |
1822 (let ((begin (line-beginning-position)) | 1828 (let ((begin (mh-line-beginning-position)) |
1823 (end (line-end-position)) | 1829 (end (mh-line-end-position)) |
1824 last-space last-slash) | 1830 last-space last-slash) |
1825 (goto-char end) | 1831 (goto-char end) |
1826 (setq last-space (search-backward " " begin t)) | 1832 (setq last-space (search-backward " " begin t)) |
1827 (setq last-slash (search-backward "/" begin t)) | 1833 (setq last-slash (search-backward "/" begin t)) |
1828 (cond ((and last-slash last-space) | 1834 (cond ((and last-slash last-space) |
1852 folder "all") | 1858 folder "all") |
1853 (goto-char (point-min)) | 1859 (goto-char (point-min)) |
1854 (let (msg checksum) | 1860 (let (msg checksum) |
1855 (while (not (eobp)) | 1861 (while (not (eobp)) |
1856 (setq msg (buffer-substring-no-properties | 1862 (setq msg (buffer-substring-no-properties |
1857 (point) (line-end-position))) | 1863 (point) (mh-line-end-position))) |
1858 (forward-line) | 1864 (forward-line) |
1859 (save-excursion | 1865 (save-excursion |
1860 (cond ((not (string-match "^[0-9]*$" msg))) | 1866 (cond ((not (string-match "^[0-9]*$" msg))) |
1861 ((eolp) | 1867 ((eolp) |
1862 ;; need to compute checksum | 1868 ;; need to compute checksum |
1863 (set-buffer mh-temp-checksum-buffer) | 1869 (set-buffer mh-temp-checksum-buffer) |
1864 (insert mh-user-path (substring folder 1) "/" msg "\n")) | 1870 (insert mh-user-path (substring folder 1) "/" msg "\n")) |
1865 (t | 1871 (t |
1866 ;; update maps | 1872 ;; update maps |
1867 (setq checksum (buffer-substring-no-properties | 1873 (setq checksum (buffer-substring-no-properties |
1868 (point) (line-end-position))) | 1874 (point) (mh-line-end-position))) |
1869 (let ((msg (string-to-number msg))) | 1875 (let ((msg (string-to-number msg))) |
1870 (set-buffer folder) | 1876 (set-buffer folder) |
1871 (mh-index-update-single-msg msg checksum origin-map))))) | 1877 (mh-index-update-single-msg msg checksum origin-map))))) |
1872 (forward-line)))) | 1878 (forward-line)))) |
1873 ;; Run checksum program if needed | 1879 ;; Run checksum program if needed |