diff lisp/replace.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 16738b49b833
children f00192e1cd49 308d34e9f07d
line wrap: on
line diff
--- a/lisp/replace.el	Mon Oct 17 21:51:33 2005 +0000
+++ b/lisp/replace.el	Tue Oct 18 20:49:43 2005 +0000
@@ -19,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
-;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-;; 02111-1307, USA.
+;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Synched up with: FSF 19.34 [Partially].
 
@@ -455,271 +455,7 @@
 	(message "%d occurrences" count)))))
 
 
-(defvar occur-mode-map ())
-(if occur-mode-map
-    ()
-  (setq occur-mode-map (make-sparse-keymap))
-  (set-keymap-name occur-mode-map 'occur-mode-map) ; XEmacs
-  (define-key occur-mode-map 'button2 'occur-mode-mouse-goto) ; XEmacs
-  (define-key occur-mode-map "\C-c\C-c" 'occur-mode-goto-occurrence)
-  (define-key occur-mode-map "\C-m" 'occur-mode-goto-occurrence))
-
-(defvar occur-buffer nil)
-(defvar occur-nlines nil)
-(defvar occur-pos-list nil)
-
-(defun occur-mode ()
-  "Major mode for output from \\[occur].
-\\<occur-mode-map>Move point to one of the items in this buffer, then use
-\\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to.
-Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
-
-\\{occur-mode-map}"
-  (kill-all-local-variables)
-  (use-local-map occur-mode-map)
-  (setq major-mode 'occur-mode)
-  (setq mode-name (gettext "Occur")) ; XEmacs
-  (make-local-variable 'occur-buffer)
-  (make-local-variable 'occur-nlines)
-  (make-local-variable 'occur-pos-list)
-  (require 'mode-motion) ; XEmacs
-  (setq mode-motion-hook 'mode-motion-highlight-line) ; XEmacs
-  (run-hooks 'occur-mode-hook))
-
-;; FSF Version of next function:
-;  (let (buffer pos)
-;    (save-excursion
-;      (set-buffer (window-buffer (posn-window (event-end event))))
-;      (save-excursion
-;       (goto-char (posn-point (event-end event)))
-;       (setq pos (occur-mode-find-occurrence))
-;       (setq buffer occur-buffer)))
-;    (pop-to-buffer buffer)
-;    (goto-char (marker-position pos))))
-
-(defun occur-mode-mouse-goto (event)
-  "Go to the occurrence highlighted by mouse.
-This function should be bound to a mouse key in the `*Occur*' buffer."
-  (interactive "e")
-  (let ((window-save (selected-window))
-	(frame-save (selected-frame)))
-    ;; preserve the window/frame setup
-    (unwind-protect
-	(progn
-	  (mouse-set-point event)
-	  (occur-mode-goto-occurrence))
-      (select-frame frame-save)
-      (select-window window-save))))
-
-;; Called occur-mode-find-occurrence in FSF
-(defun occur-mode-goto-occurrence ()
-  "Go to the occurrence the current line describes."
-  (interactive)
-  (if (or (null occur-buffer)
-	  (null (buffer-name occur-buffer)))
-      (progn
-	(setq occur-buffer nil
-	      occur-pos-list nil)
-	(error "Buffer in which occurrences were found is deleted")))
-  (let* ((line-count
-	  (count-lines (point-min)
-		       (save-excursion
-			 (beginning-of-line)
-			 (point))))
-	 (occur-number (save-excursion
-			 (beginning-of-line)
-			 (/ (1- line-count)
-			    (cond ((< occur-nlines 0)
-				   (- 2 occur-nlines))
-				  ((> occur-nlines 0)
-				   (+ 2 (* 2 occur-nlines)))
-				  (t 1)))))
-	 (pos (nth occur-number occur-pos-list))
-	 ;; removed t arg from Bob Weiner, 10/6/95
-	 (window (get-buffer-window occur-buffer))
-	 (occur-source-buffer occur-buffer))
-    (if (< line-count 1)
-	(error "No occurrence on this line"))
-    (or pos
-	(error "No occurrence on this line"))
-    ;; XEmacs: don't raise window unless it isn't visible
-    ;; allow for the possibility that the occur buffer is on another frame
-    (or (and window
-	     (window-live-p window)
-	     (frame-visible-p (window-frame window))
-	     (set-buffer occur-source-buffer))
-	(and (pop-to-buffer occur-source-buffer)
-	     (setq window (get-buffer-window occur-source-buffer))))
-    (goto-char pos)
-    (set-window-point window pos)))
-
-
-(defvar list-matching-lines-default-context-lines 0
-  "*Default number of context lines to include around a `list-matching-lines'
-match.  A negative number means to include that many lines before the match.
-A positive number means to include that many lines both before and after.")
-
-;; XEmacs addition
-;;; Damn you Jamie, this is utter trash.
-(defvar list-matching-lines-whole-buffer t
-  "If t, occur operates on whole buffer, otherwise occur starts from point.
-default is t.")
-
-(define-function 'occur 'list-matching-lines)
-(defun list-matching-lines (regexp &optional nlines)
-  "Show all lines in the current buffer containing a match for REGEXP.
-
-If a match spreads across multiple lines, all those lines are shown.
-
-If variable `list-matching-lines-whole-buffer' is non-nil, the entire
-buffer is searched, otherwise search begins at point.
-
-Each line is displayed with NLINES lines before and after, or -NLINES
-before if NLINES is negative.
-NLINES defaults to `list-matching-lines-default-context-lines'.
-Interactively it is the prefix arg.
-
-The lines are shown in a buffer named `*Occur*'.
-It serves as a menu to find any of the occurrences in this buffer.
-\\[describe-mode] in that buffer will explain how."
-  (interactive
-   ;; XEmacs change
-   (list (let* ((default (or (symbol-near-point)
-			     (and regexp-history
-				  (car regexp-history))))
-		(minibuffer-history-minimum-string-length 0)
-		(input
-		 (if default
-		     ;; rewritten for I18N3 snarfing
-		     (read-from-minibuffer
-		      (format "List lines matching regexp (default `%s'): "
-			      default) nil nil nil 'regexp-history nil
-                              default)
-		   (read-from-minibuffer
-		    "List lines matching regexp: "
-		    nil nil nil
-		    'regexp-history))))
-	   (if (and (equal input "") default)
-	       (progn
-		 (setq input default)
-		 (setcar regexp-history default)))
-	   ;; clear extra entries
-	   (setcdr regexp-history (delete (car regexp-history)
-					  (cdr regexp-history)))
-	   input)
-	 current-prefix-arg))
-  (if (equal regexp "")
-      (error "Must pass non-empty regexp to `list-matching-lines'"))
-  (setq nlines (if nlines (prefix-numeric-value nlines)
-		 list-matching-lines-default-context-lines))
-  (let ((first t)
-	(dir default-directory)
-	(buffer (current-buffer))
-	(linenum 1)
-	(prevpos (point-min))
-	;; The rest of this function is very different from FSF.
-	;; Presumably that's due to Jamie's misfeature
-        (final-context-start (make-marker)))
-    (if (not list-matching-lines-whole-buffer)
-	(save-excursion
-	  (beginning-of-line)
-	  (setq linenum (1+ (count-lines (point-min) (point))))
-	  (setq prevpos (point))))
-    (with-output-to-temp-buffer "*Occur*"
-      (save-excursion
-	(set-buffer standard-output)
-	(setq default-directory dir)
-	;; We will insert the number of lines, and "lines", later.
-	;; #### Needs fixing for I18N3
-	(let ((print-escape-newlines t))
-	  (insert (format " matching %s in buffer %s.\n"
-			  regexp (buffer-name buffer))))
-	(occur-mode)
-	(setq occur-buffer buffer)
-	(setq occur-nlines nlines)
-	(setq occur-pos-list ()))
-      (if (eq buffer standard-output)
-	  (goto-char (point-max)))
-      (with-interactive-search-caps-disable-folding regexp t
-	(save-excursion
-	  (if list-matching-lines-whole-buffer
-	      (beginning-of-buffer))
-	  (message "Searching for %s ..." regexp)
-	  ;; Find next match, but give up if prev match was at end of buffer.
-	  (while (and (not (= prevpos (point-max)))
-		      (re-search-forward regexp nil t))
-	    (goto-char (match-beginning 0))
-	    (beginning-of-line)
-	    (save-match-data
-	      (setq linenum (+ linenum (count-lines prevpos (point)))))
-	    (setq prevpos (point))
-	    (goto-char (match-end 0))
-	    (let* ((start (save-excursion
-			    (goto-char (match-beginning 0))
-			    (forward-line (if (< nlines 0) nlines (- nlines)))
-			    (point)))
-		   (end (save-excursion
-			  (goto-char (match-end 0))
-			  (if (> nlines 0)
-			      (forward-line (1+ nlines))
-			    (forward-line 1))
-			  (point)))
-		   (tag (format "%5d" linenum))
-		   (empty (make-string (length tag) ?\ ))
-		   tem)
-	      (save-excursion
-		(setq tem (make-marker))
-		(set-marker tem (point))
-		(set-buffer standard-output)
-		(setq occur-pos-list (cons tem occur-pos-list))
-		(or first (zerop nlines)
-		    (insert "--------\n"))
-		(setq first nil)
-		(insert-buffer-substring buffer start end)
-		(set-marker final-context-start
-			    (- (point) (- end (match-end 0))))
-		(backward-char (- end start))
-		(setq tem (if (< nlines 0) (- nlines) nlines))
-		(while (> tem 0)
-		  (insert empty ?:)
-		  (forward-line 1)
-		  (setq tem (1- tem)))
-		(let ((this-linenum linenum))
-		  (while (< (point) final-context-start)
-		    (if (null tag)
-			(setq tag (format "%5d" this-linenum)))
-		    (insert tag ?:)
-		    ;; FSFmacs --
-		    ;; we handle this using mode-motion-highlight-line, above.
-		    ;;		  (put-text-property (save-excursion
-		    ;;				       (beginning-of-line)
-		    ;;				       (point))
-		    ;;				     (save-excursion
-		    ;;				       (end-of-line)
-		    ;;				       (point))
-		    ;;				     'mouse-face 'highlight)
-		    (forward-line 1)
-		    (setq tag nil)
-		    (setq this-linenum (1+ this-linenum)))
-		  (while (<= (point) final-context-start)
-		    (insert empty ?:)
-		    (forward-line 1)
-		    (setq this-linenum (1+ this-linenum))))
-		(while (< tem nlines)
-		  (insert empty ?:)
-		  (forward-line 1)
-		  (setq tem (1+ tem)))
-		(goto-char (point-max)))
-	      (forward-line 1)))
-	  (set-buffer standard-output)
-	  ;; Put positions in increasing order to go with buffer.
-	  (setq occur-pos-list (nreverse occur-pos-list))
-	  (goto-char (point-min))
-	  (if (= (length occur-pos-list) 1)
-	      (insert "1 line")
-	    (insert (format "%d lines" (length occur-pos-list))))
-	  (if (interactive-p)
-	      (message "%d matching lines." (length occur-pos-list))))))))
+;;; occur code moved to occur.el
 
 ;; It would be nice to use \\[...], but there is no reasonable way
 ;; to make that display both SPC and Y.