annotate lisp/occur.el @ 3000:5df5ea55d3fc

[xemacs-hg @ 2005-10-18 20:49:41 by malcolmp] Sync of occur mode with GNU Emacs 22.0.50.1 (CVS)
author malcolmp
date Tue, 18 Oct 2005 20:49:43 +0000
parents
children 1e7cc382eb16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3000
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
1 ;;; occur.el --- Show all lines in the current buffer containing a match for REGEXP.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
2
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1996, 1997, 2000, 2001,
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
4 ;; 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
5
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
7 ;; Keywords: internal
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
8
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
9 ;; This file is part of XEmacs.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
10
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
14 ;; any later version.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
15
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful,
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
19 ;; GNU General Public License for more details.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
20
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
25
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
26 ;;; Synched up with: FSF 22.0.50.1 (CVS)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
27
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
28 (require 'next-error)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
29 (defun query-replace-descr (string)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
30 (mapconcat 'isearch-text-char-description string ""))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
31
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
32 (defvar occur-mode-map ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
33 "Keymap for `occur-mode'.")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
34 (if occur-mode-map
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
35 ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
36 (setq occur-mode-map (make-sparse-keymap))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
37 (set-keymap-name occur-mode-map 'occur-mode-map) ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
38 (define-key occur-mode-map 'button2 'occur-mode-mouse-goto) ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
39 (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
40 (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
41 (define-key occur-mode-map "o" 'occur-mode-goto-occurrence-other-window)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
42 (define-key occur-mode-map "\C-o" 'occur-mode-display-occurrence)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
43 (define-key occur-mode-map "\M-n" 'occur-next)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
44 (define-key occur-mode-map "\M-p" 'occur-prev)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
45 (define-key occur-mode-map "r" 'occur-rename-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
46 (define-key occur-mode-map "c" 'clone-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
47 (define-key occur-mode-map "g" 'revert-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
48 (define-key occur-mode-map "q" 'quit-window)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
49 (define-key occur-mode-map "z" 'kill-this-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
50 (define-key occur-mode-map "\C-c\C-f" 'next-error-follow-minor-mode))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
51
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
52 (defvar occur-revert-arguments nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
53 "Arguments to pass to `occur-1' to revert an Occur mode buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
54 See `occur-revert-function'.")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
55
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
56 (defcustom occur-mode-hook nil ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
57 "Hook run when entering Occur mode."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
58 :type 'hook
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
59 :group 'matching)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
60
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
61 (defcustom occur-hook nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
62 "Hook run by Occur when there are any matches."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
63 :type 'hook
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
64 :group 'matching)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
65
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
66 (put 'occur-mode 'mode-class 'special)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
67 ;;;###autoload
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
68 (defun occur-mode ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
69 "Major mode for output from \\[occur].
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
70 \\<occur-mode-map>Move point to one of the items in this buffer, then use
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
71 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
72 Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
73
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
74 \\{occur-mode-map}"
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
75 (interactive)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
76 (kill-all-local-variables)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
77 (use-local-map occur-mode-map)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
78 (setq major-mode 'occur-mode)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
79 (setq mode-name (gettext "Occur")) ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
80 (set (make-local-variable 'revert-buffer-function) 'occur-revert-function)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
81 (make-local-variable 'occur-revert-arguments)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
82 (add-hook 'change-major-mode-hook 'turn-off-font-lock t t)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
83 (setq next-error-function 'occur-next-error)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
84 (require 'mode-motion) ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
85 (setq mode-motion-hook 'mode-motion-highlight-line) ; XEmacs
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
86 (run-mode-hooks 'occur-mode-hook))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
87
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
88 (defun occur-revert-function (ignore1 ignore2)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
89 "Handle `revert-buffer' for Occur mode buffers."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
90 (apply 'occur-1 (append occur-revert-arguments (list (buffer-name)))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
91
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
92 ;; FSF Version of next function:
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
93 ; (defun occur-mode-mouse-goto (event)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
94 ; "In Occur mode, go to the occurrence whose line you click on."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
95 ; (interactive "e")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
96 ; (let (pos)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
97 ; (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
98 ; (set-buffer (window-buffer (posn-window (event-end event))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
99 ; (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
100 ; (goto-char (posn-point (event-end event)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
101 ; (setq pos (occur-mode-find-occurrence))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
102 ; (pop-to-buffer (marker-buffer pos))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
103 ; (goto-char pos)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
104
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
105 (defun occur-mode-mouse-goto (event)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
106 "Go to the occurrence highlighted by mouse.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
107 This function should be bound to a mouse key in the `*Occur*' buffer."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
108 (interactive "e")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
109 (let ((window-save (selected-window))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
110 (frame-save (selected-frame)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
111 ;; preserve the window/frame setup
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
112 (unwind-protect
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
113 (progn
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
114 (mouse-set-point event)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
115 (occur-mode-goto-occurrence))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
116 (select-frame frame-save)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
117 (select-window window-save))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
118
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
119 (defun occur-mode-find-occurrence ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
120 (let ((pos (get-text-property (point) 'occur-target)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
121 (unless pos
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
122 (error "No occurrence on this line"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
123 (unless (buffer-live-p (marker-buffer pos))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
124 (error "Buffer for this occurrence was killed"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
125 pos))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
126
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
127 (defun occur-mode-goto-occurrence ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
128 "Go to the occurrence the current line describes."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
129 (interactive)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
130 (let ((pos (occur-mode-find-occurrence)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
131 (pop-to-buffer (marker-buffer pos))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
132 (goto-char pos)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
133
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
134 (defun occur-mode-goto-occurrence-other-window ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
135 "Go to the occurrence the current line describes, in another window."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
136 (interactive)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
137 (let ((pos (occur-mode-find-occurrence)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
138 (switch-to-buffer-other-window (marker-buffer pos))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
139 (goto-char pos)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
140
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
141 (defun occur-mode-display-occurrence ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
142 "Display in another window the occurrence the current line describes."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
143 (interactive)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
144 (let ((pos (occur-mode-find-occurrence))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
145 window
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
146 ;; Bind these to ensure `display-buffer' puts it in another window.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
147 same-window-buffer-names
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
148 same-window-regexps)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
149 (setq window (display-buffer (marker-buffer pos)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
150 ;; This is the way to set point in the proper window.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
151 (save-selected-window
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
152 (select-window window)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
153 (goto-char pos))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
154
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
155 (defun occur-find-match (n search message)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
156 (if (not n) (setq n 1))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
157 (let ((r))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
158 (while (> n 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
159 (setq r (funcall search (point) 'occur-match))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
160 (and r
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
161 (get-text-property r 'occur-match)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
162 (setq r (funcall search r 'occur-match)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
163 (if r
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
164 (goto-char r)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
165 (error message))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
166 (setq n (1- n)))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
167
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
168 (defun occur-next (&optional n)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
169 "Move to the Nth (default 1) next match in an Occur mode buffer."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
170 (interactive "p")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
171 (occur-find-match n #'next-single-property-change "No more matches"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
172
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
173 (defun occur-prev (&optional n)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
174 "Move to the Nth (default 1) previous match in an Occur mode buffer."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
175 (interactive "p")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
176 (occur-find-match n #'previous-single-property-change "No earlier matches"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
177
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
178 (defun occur-next-error (&optional argp reset)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
179 "Move to the Nth (default 1) next match in an Occur mode buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
180 Compatibility function for \\[next-error] invocations."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
181 (interactive "p")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
182 ;; we need to run occur-find-match from within the Occur buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
183 (with-current-buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
184 ;; Choose the buffer and make it current.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
185 (if (next-error-buffer-p (current-buffer))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
186 (current-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
187 (next-error-find-buffer nil nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
188 (lambda ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
189 (eq major-mode 'occur-mode))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
190
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
191 (goto-char (cond (reset (point-min))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
192 ((< argp 0) (line-beginning-position))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
193 ((line-end-position))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
194 (occur-find-match
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
195 (abs argp)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
196 (if (> 0 argp)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
197 #'previous-single-property-change
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
198 #'next-single-property-change)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
199 "No more matches")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
200 ;; In case the *Occur* buffer is visible in a nonselected window.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
201 (set-window-point (get-buffer-window (current-buffer)) (point))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
202 (occur-mode-goto-occurrence)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
203
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
204 (defface match
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
205 '((((class color) (background light))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
206 (:background "Tan"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
207 (((class color) (background dark))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
208 (:background "RoyalBlue3"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
209 (((class color))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
210 (:background "blue" :foreground "white"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
211 (((type tty) (class mono))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
212 (:inverse-video t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
213 (t (:background "gray")))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
214 "Face used to highlight matches permanently."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
215 :group 'matching
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
216 :version "22.1")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
217
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
218 (defcustom list-matching-lines-default-context-lines 0
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
219 "*Default number of context lines included around `list-matching-lines' matches.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
220 A negative number means to include that many lines before the match.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
221 A positive number means to include that many lines both before and after."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
222 :type 'integer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
223 :group 'matching)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
224
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
225 (defalias 'list-matching-lines 'occur)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
226
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
227 (defcustom list-matching-lines-face 'match
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
228 "*Face used by \\[list-matching-lines] to show the text that matches.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
229 If the value is nil, don't highlight the matching portions specially."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
230 :type 'face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
231 :group 'matching)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
232
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
233 (defcustom list-matching-lines-buffer-name-face 'underline
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
234 "*Face used by \\[list-matching-lines] to show the names of buffers.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
235 If the value is nil, don't highlight the buffer names specially."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
236 :type 'face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
237 :group 'matching)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
238
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
239 (defun occur-accumulate-lines (count &optional keep-props)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
240 (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
241 (let ((forwardp (> count 0))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
242 result beg end)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
243 (while (not (or (zerop count)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
244 (if forwardp
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
245 (eobp)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
246 (bobp))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
247 (setq count (+ count (if forwardp -1 1)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
248 (setq beg (line-beginning-position)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
249 end (line-end-position))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
250 (if (and keep-props (if (boundp 'jit-lock-mode) jit-lock-mode)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
251 (text-property-not-all beg end 'fontified t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
252 (if (fboundp 'jit-lock-fontify-now)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
253 (jit-lock-fontify-now beg end)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
254 (push
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
255 (funcall (if keep-props
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
256 #'buffer-substring
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
257 #'buffer-substring-no-properties)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
258 beg end)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
259 result)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
260 (forward-line (if forwardp 1 -1)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
261 (nreverse result))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
262
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
263 (defun occur-read-primary-args ()
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
264 (list (let* ((default (or (symbol-near-point)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
265 (and regexp-history
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
266 (car regexp-history))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
267 (minibuffer-history-minimum-string-length 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
268 (input
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
269 (if default
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
270 ;; XEmacs: rewritten for I18N3 snarfing
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
271 (read-from-minibuffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
272 (format "List lines matching regexp (default `%s'): "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
273 default) nil nil nil 'regexp-history nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
274 default)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
275 (read-from-minibuffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
276 "List lines matching regexp: "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
277 nil nil nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
278 'regexp-history))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
279 (if (equal input "")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
280 default
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
281 input))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
282 (when current-prefix-arg
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
283 (prefix-numeric-value current-prefix-arg))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
284
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
285 ;;;###autoload
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
286 (defun occur-rename-buffer (&optional unique-p interactive-p)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
287 "Rename the current *Occur* buffer to *Occur: original-buffer-name*.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
288 Here `original-buffer-name' is the buffer name were Occur was originally run.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
289 When given the prefix argument, or called non-interactively, the renaming
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
290 will not clobber the existing buffer(s) of that name, but use
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
291 `generate-new-buffer-name' instead. You can add this to `occur-hook'
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
292 if you always want a separate *Occur* buffer for each buffer where you
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
293 invoke `occur'."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
294 (interactive "P\np")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
295 (with-current-buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
296 (if (eq major-mode 'occur-mode) (current-buffer) (get-buffer "*Occur*"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
297 (rename-buffer (concat "*Occur: "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
298 (mapconcat #'buffer-name
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
299 (car (cddr occur-revert-arguments)) "/")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
300 "*")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
301 (or unique-p (not interactive-p)))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
302
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
303 ;;;###autoload
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
304 (defun occur (regexp &optional nlines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
305 "Show all lines in the current buffer containing a match for REGEXP.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
306 This function can not handle matches that span more than one line.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
307
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
308 Each line is displayed with NLINES lines before and after, or -NLINES
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
309 before if NLINES is negative.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
310 NLINES defaults to `list-matching-lines-default-context-lines'.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
311 Interactively it is the prefix arg.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
312
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
313 The lines are shown in a buffer named `*Occur*'.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
314 It serves as a menu to find any of the occurrences in this buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
315 \\<occur-mode-map>\\[describe-mode] in that buffer will explain how.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
316
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
317 If REGEXP contains upper case characters (excluding those preceded by `\\'),
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
318 the matching is case-sensitive."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
319 (interactive (occur-read-primary-args))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
320 (occur-1 regexp nlines (list (current-buffer))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
321
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
322 ;;;###autoload
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
323 (defun multi-occur (bufs regexp &optional nlines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
324 "Show all lines in buffers BUFS containing a match for REGEXP.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
325 This function acts on multiple buffers; otherwise, it is exactly like
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
326 `occur'."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
327 (interactive
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
328 (cons
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
329 (let* ((bufs (list (read-buffer "First buffer to search: "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
330 (current-buffer) t)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
331 (buf nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
332 (ido-ignore-item-temp-list bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
333 (while (not (string-equal
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
334 (setq buf (read-buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
335 (if (and-boundp 'read-buffer-function
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
336 '(eq read-buffer-function 'ido-read-buffer))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
337 "Next buffer to search (C-j to end): "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
338 "Next buffer to search (RET to end): ")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
339 nil t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
340 ""))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
341 (add-to-list 'bufs buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
342 (setq ido-ignore-item-temp-list bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
343 (nreverse (mapcar #'get-buffer bufs)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
344 (occur-read-primary-args)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
345 (occur-1 regexp nlines bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
346
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
347 ;;;###autoload
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
348 (defun multi-occur-by-filename-regexp (bufregexp regexp &optional nlines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
349 "Show all lines matching REGEXP in buffers named by BUFREGEXP.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
350 See also `multi-occur'."
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
351 (interactive
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
352 (cons
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
353 (let* ((default (car regexp-history))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
354 (input
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
355 (read-from-minibuffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
356 "List lines in buffers whose filename matches regexp: "
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
357 nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
358 nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
359 nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
360 'regexp-history)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
361 (if (equal input "")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
362 default
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
363 input))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
364 (occur-read-primary-args)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
365 (when bufregexp
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
366 (occur-1 regexp nlines
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
367 (delq nil
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
368 (mapcar (lambda (buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
369 (when (and (buffer-file-name buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
370 (string-match bufregexp
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
371 (buffer-file-name buf)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
372 buf))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
373 (buffer-list))))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
374
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
375 (defun occur-1 (regexp nlines bufs &optional buf-name)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
376 (unless buf-name
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
377 (setq buf-name "*Occur*"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
378 (let (occur-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
379 (active-bufs (delq nil (mapcar #'(lambda (buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
380 (when (buffer-live-p buf) buf))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
381 bufs))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
382 ;; Handle the case where one of the buffers we're searching is the
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
383 ;; output buffer. Just rename it.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
384 (when (member buf-name (mapcar 'buffer-name active-bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
385 (with-current-buffer (get-buffer buf-name)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
386 (rename-uniquely)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
387
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
388 ;; Now find or create the output buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
389 ;; If we just renamed that buffer, we will make a new one here.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
390 (setq occur-buf (get-buffer-create buf-name))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
391
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
392 (with-current-buffer occur-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
393 (occur-mode)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
394 (let ((inhibit-read-only t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
395 (erase-buffer)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
396 (let ((count (occur-engine
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
397 regexp active-bufs occur-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
398 (or nlines list-matching-lines-default-context-lines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
399 (and case-fold-search
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
400 (no-upper-case-p regexp t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
401 list-matching-lines-buffer-name-face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
402 nil list-matching-lines-face t)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
403 (let* ((bufcount (length active-bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
404 (diff (- (length bufs) bufcount)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
405 (message "Searched %d buffer%s%s; %s match%s for `%s'"
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
406 bufcount (if (= bufcount 1) "" "s")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
407 (if (zerop diff) "" (format " (%d killed)" diff))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
408 (if (zerop count) "no" (format "%d" count))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
409 (if (= count 1) "" "es")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
410 regexp))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
411 (setq occur-revert-arguments (list regexp nlines bufs))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
412 (if (= count 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
413 (kill-buffer occur-buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
414 (display-buffer occur-buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
415 (setq next-error-last-buffer occur-buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
416 (setq buffer-read-only t)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
417 (set-buffer-modified-p nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
418 (run-hooks 'occur-hook)))))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
419
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
420 (defun occur-engine-add-prefix (lines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
421 (mapcar
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
422 #'(lambda (line)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
423 (concat " :" line "\n"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
424 lines))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
425
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
426 (defun occur-engine (regexp buffers out-buf nlines case-fold-search
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
427 title-face prefix-face match-face keep-props)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
428 (with-current-buffer out-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
429 (let ((globalcount 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
430 ;; Don't generate undo entries for creation of the initial contents.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
431 (buffer-undo-list t)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
432 (coding nil))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
433 ;; Map over all the buffers
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
434 (dolist (buf buffers)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
435 (when (buffer-live-p buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
436 (let ((matches 0) ;; count of matched lines
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
437 (lines 1) ;; line count
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
438 (matchbeg 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
439 (origpt nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
440 (begpt nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
441 (endpt nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
442 (marker nil)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
443 (curstring "")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
444 (headerpt (with-current-buffer out-buf (point))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
445 (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
446 (set-buffer buf)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
447 (or coding
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
448 ;; Set CODING only if the current buffer locally
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
449 ;; binds buffer-file-coding-system.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
450 (not (local-variable-p 'buffer-file-coding-system (current-buffer)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
451 (setq coding buffer-file-coding-system))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
452 (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
453 (goto-char (point-min)) ;; begin searching in the buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
454 (while (not (eobp))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
455 (setq origpt (point))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
456 (when (setq endpt (re-search-forward regexp nil t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
457 (setq matches (1+ matches)) ;; increment match count
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
458 (setq matchbeg (match-beginning 0))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
459 (setq lines (+ lines (1- (count-lines origpt endpt))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
460 (save-excursion
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
461 (goto-char matchbeg)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
462 (setq begpt (line-beginning-position)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
463 endpt (line-end-position)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
464 (setq marker (make-marker))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
465 (set-marker marker matchbeg)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
466 (if (and keep-props
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
467 (if (boundp 'jit-lock-mode) jit-lock-mode)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
468 (text-property-not-all begpt endpt 'fontified t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
469 (if (fboundp 'jit-lock-fontify-now)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
470 (jit-lock-fontify-now begpt endpt)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
471 (setq curstring (buffer-substring begpt endpt))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
472 ;; Depropertize the string, and maybe
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
473 ;; highlight the matches
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
474 (let ((len (length curstring))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
475 (start 0))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
476 (unless keep-props
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
477 (set-text-properties 0 len nil curstring))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
478 (while (and (< start len)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
479 (string-match regexp curstring start))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
480 (add-text-properties
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
481 (match-beginning 0) (match-end 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
482 (append
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
483 `(occur-match t)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
484 (when match-face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
485 ;; Use `face' rather than `font-lock-face' here
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
486 ;; so as to override faces copied from the buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
487 `(face ,match-face)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
488 curstring)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
489 (setq start (match-end 0))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
490 ;; Generate the string to insert for this match
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
491 (let* ((out-line
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
492 (concat
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
493 ;; Using 7 digits aligns tabs properly.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
494 (apply #'propertize (format "%7d:" lines)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
495 (append
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
496 (when prefix-face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
497 `(font-lock-face prefix-face))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
498 '(occur-prefix t)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
499 ;; We don't put `mouse-face' on the newline,
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
500 ;; because that loses. And don't put it
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
501 ;; on context lines to reduce flicker.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
502 (propertize curstring 'mouse-face 'highlight)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
503 "\n"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
504 (data
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
505 (if (= nlines 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
506 ;; The simple display style
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
507 out-line
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
508 ;; The complex multi-line display
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
509 ;; style. Generate a list of lines,
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
510 ;; concatenate them all together.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
511 (apply #'concat
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
512 (nconc
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
513 (occur-engine-add-prefix (nreverse (cdr (occur-accumulate-lines (- (1+ (abs nlines))) keep-props))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
514 (list out-line)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
515 (if (> nlines 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
516 (occur-engine-add-prefix
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
517 (cdr (occur-accumulate-lines (1+ nlines) keep-props)))))))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
518 ;; Actually insert the match display data
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
519 (with-current-buffer out-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
520 (let ((beg (point))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
521 (end (progn (insert data) (point))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
522 (unless (= nlines 0)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
523 (insert "-------\n"))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
524 (add-text-properties
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
525 beg end
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
526 `(occur-target ,marker help-echo "mouse-2: go to this occurrence")))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
527 (goto-char endpt))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
528 (if endpt
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
529 (progn
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
530 (setq lines (1+ lines))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
531 ;; On to the next match...
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
532 (forward-line 1))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
533 (goto-char (point-max))))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
534 (when (not (zerop matches)) ;; is the count zero?
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
535 (setq globalcount (+ globalcount matches))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
536 (with-current-buffer out-buf
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
537 (goto-char headerpt)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
538 (let ((beg (point))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
539 end)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
540 (insert (format "%d match%s for \"%s\" in buffer: %s\n"
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
541 matches (if (= matches 1) "" "es")
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
542 regexp (buffer-name buf)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
543 (setq end (point))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
544 (add-text-properties beg end
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
545 (append
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
546 (when title-face
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
547 `(font-lock-face ,title-face))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
548 `(occur-title ,buf))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
549 (goto-char (point-min)))))))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
550 (if coding
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
551 ;; CODING is buffer-file-coding-system of the first buffer
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
552 ;; that locally binds it. Let's use it also for the output
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
553 ;; buffer.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
554 (set-buffer-file-coding-system coding))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
555 ;; Return the number of matches
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
556 globalcount)))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
557
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents:
diff changeset
558 (provide 'occur)