Mercurial > emacs
comparison lisp/replace.el @ 45444:84e0e49bfb75
(occur-engine): Increment globalcount all at once after searching a buffer.
(occur-mode-map): Don't escape plain "o".
(occur-mode-hook): New variable.
(occur-fontify-region-function): Deleted.
(occur-mode): Don't use it. Set up `font-lock-category-alist' instead.
(occur-fontify-on-property): Deleted.
(occur-engine): Use categories from `font-lock-category-alist'.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Tue, 21 May 2002 21:01:14 +0000 |
parents | abd8a68f87a7 |
children | 177f92e9f497 |
comparison
equal
deleted
inserted
replaced
45443:8fd13e1863ed | 45444:84e0e49bfb75 |
---|---|
438 (defvar occur-mode-map | 438 (defvar occur-mode-map |
439 (let ((map (make-sparse-keymap))) | 439 (let ((map (make-sparse-keymap))) |
440 (define-key map [mouse-2] 'occur-mode-mouse-goto) | 440 (define-key map [mouse-2] 'occur-mode-mouse-goto) |
441 (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence) | 441 (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence) |
442 (define-key map "\C-m" 'occur-mode-goto-occurrence) | 442 (define-key map "\C-m" 'occur-mode-goto-occurrence) |
443 (define-key map "\o" 'occur-mode-goto-occurrence-other-window) | 443 (define-key map "o" 'occur-mode-goto-occurrence-other-window) |
444 (define-key map "\C-o" 'occur-mode-display-occurrence) | 444 (define-key map "\C-o" 'occur-mode-display-occurrence) |
445 (define-key map "\M-n" 'occur-next) | 445 (define-key map "\M-n" 'occur-next) |
446 (define-key map "\M-p" 'occur-prev) | 446 (define-key map "\M-p" 'occur-prev) |
447 (define-key map "g" 'revert-buffer) | 447 (define-key map "g" 'revert-buffer) |
448 (define-key map "q" 'delete-window) | 448 (define-key map "q" 'delete-window) |
451 | 451 |
452 (defvar occur-revert-arguments nil | 452 (defvar occur-revert-arguments nil |
453 "Arguments to pass to `occur-1' to revert an Occur mode buffer. | 453 "Arguments to pass to `occur-1' to revert an Occur mode buffer. |
454 See `occur-revert-function'.") | 454 See `occur-revert-function'.") |
455 | 455 |
456 (defcustom occur-mode-hook '(turn-on-font-lock) | |
457 "Hooks run when `occur' is called." | |
458 :type 'hook | |
459 :group 'matching) | |
460 | |
456 (put 'occur-mode 'mode-class 'special) | 461 (put 'occur-mode 'mode-class 'special) |
457 (defun occur-mode () | 462 (defun occur-mode () |
458 "Major mode for output from \\[occur]. | 463 "Major mode for output from \\[occur]. |
459 \\<occur-mode-map>Move point to one of the items in this buffer, then use | 464 \\<occur-mode-map>Move point to one of the items in this buffer, then use |
460 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to. | 465 \\[occur-mode-goto-occurrence] to go to the occurrence that the item refers to. |
464 (kill-all-local-variables) | 469 (kill-all-local-variables) |
465 (use-local-map occur-mode-map) | 470 (use-local-map occur-mode-map) |
466 (setq major-mode 'occur-mode) | 471 (setq major-mode 'occur-mode) |
467 (setq mode-name "Occur") | 472 (setq mode-name "Occur") |
468 (make-local-variable 'revert-buffer-function) | 473 (make-local-variable 'revert-buffer-function) |
469 (set (make-local-variable 'font-lock-defaults) | 474 (set (make-local-variable 'font-lock-category-alist) |
470 '(nil t nil nil nil | 475 `((,(make-symbol "occur-match") . bold) |
471 (font-lock-fontify-region-function . occur-fontify-region-function))) | 476 (,(make-symbol "occur-title") . underline))) |
472 (setq revert-buffer-function 'occur-revert-function) | |
473 (set (make-local-variable 'revert-buffer-function) 'occur-revert-function) | 477 (set (make-local-variable 'revert-buffer-function) 'occur-revert-function) |
474 (make-local-variable 'occur-revert-arguments) | 478 (make-local-variable 'occur-revert-arguments) |
475 (run-hooks 'occur-mode-hook)) | 479 (run-hooks 'occur-mode-hook)) |
476 | 480 |
477 (defun occur-revert-function (ignore1 ignore2) | 481 (defun occur-revert-function (ignore1 ignore2) |
761 (goto-char (point-min)) ;; begin searching in the buffer | 765 (goto-char (point-min)) ;; begin searching in the buffer |
762 (while (not (eobp)) | 766 (while (not (eobp)) |
763 (setq origpt (point)) | 767 (setq origpt (point)) |
764 (when (setq endpt (re-search-forward regexp nil t)) | 768 (when (setq endpt (re-search-forward regexp nil t)) |
765 (setq matches (1+ matches)) ;; increment match count | 769 (setq matches (1+ matches)) ;; increment match count |
766 (setq globalcount (1+ globalcount)) | |
767 (setq matchbeg (match-beginning 0) | 770 (setq matchbeg (match-beginning 0) |
768 matchend (match-end 0)) | 771 matchend (match-end 0)) |
769 (setq begpt (save-excursion | 772 (setq begpt (save-excursion |
770 (goto-char matchbeg) | 773 (goto-char matchbeg) |
771 (line-beginning-position))) | 774 (line-beginning-position))) |
775 (setq curstring (buffer-substring begpt | 778 (setq curstring (buffer-substring begpt |
776 (line-end-position))) | 779 (line-end-position))) |
777 ;; Depropertize the string, and maybe | 780 ;; Depropertize the string, and maybe |
778 ;; highlight the matches | 781 ;; highlight the matches |
779 (let ((len (length curstring)) | 782 (let ((len (length curstring)) |
783 (match-category (with-current-buffer out-buf | |
784 (car (nth 0 font-lock-category-alist)))) | |
780 (start 0)) | 785 (start 0)) |
781 (unless keep-props | 786 (unless keep-props |
782 (set-text-properties 0 len nil curstring)) | 787 (set-text-properties 0 len nil curstring)) |
783 (while (and (< start len) | 788 (while (and (< start len) |
784 (string-match regexp curstring start)) | 789 (string-match regexp curstring start)) |
785 (add-text-properties (match-beginning 0) | 790 (add-text-properties (match-beginning 0) |
786 (match-end 0) | 791 (match-end 0) |
787 (append | 792 (append |
788 '(occur-match t) | 793 `(occur-match t category ,match-category) |
789 (when match-face | 794 (when match-face |
790 `(face ,match-face))) | 795 `(face ,match-face))) |
791 curstring) | 796 curstring) |
792 (setq start (match-end 0)))) | 797 (setq start (match-end 0)))) |
793 ;; Generate the string to insert for this match | 798 ;; Generate the string to insert for this match |
829 (setq lines (1+ lines)) | 834 (setq lines (1+ lines)) |
830 ;; On to the next match... | 835 ;; On to the next match... |
831 (forward-line 1)) | 836 (forward-line 1)) |
832 (goto-char (point-max)))))) | 837 (goto-char (point-max)))))) |
833 (when (not (zerop matches)) ;; is the count zero? | 838 (when (not (zerop matches)) ;; is the count zero? |
839 (setq globalcount (+ globalcount matches)) | |
834 (with-current-buffer out-buf | 840 (with-current-buffer out-buf |
835 (goto-char headerpt) | 841 (goto-char headerpt) |
836 (let ((beg (point)) | 842 (let ((beg (point)) |
837 end) | 843 end) |
838 (insert (format "%d lines matching \"%s\" in buffer: %s\n" | 844 (insert (format "%d lines matching \"%s\" in buffer: %s\n" |
840 (setq end (point)) | 846 (setq end (point)) |
841 (add-text-properties beg end | 847 (add-text-properties beg end |
842 (append | 848 (append |
843 (when title-face | 849 (when title-face |
844 `(face ,title-face)) | 850 `(face ,title-face)) |
845 `(occur-title ,buf)))) | 851 `(occur-title |
852 ,buf category | |
853 ,(car (nth 1 font-lock-category-alist)))))) | |
846 (goto-char (point-min))))))) | 854 (goto-char (point-min))))))) |
847 ;; Return the number of matches | 855 ;; Return the number of matches |
848 globalcount))) | 856 globalcount))) |
849 | |
850 (defun occur-fontify-on-property (prop face beg end) | |
851 (let ((prop-beg (or (and (get-text-property (point) prop) (point)) | |
852 (next-single-property-change (point) prop nil end)))) | |
853 (when (and prop-beg (not (= prop-beg end))) | |
854 (let ((prop-end (next-single-property-change beg prop nil end))) | |
855 (when (and prop-end (not (= prop-end end))) | |
856 (put-text-property prop-beg prop-end 'face face) | |
857 prop-end))))) | |
858 | |
859 (defun occur-fontify-region-function (beg end &optional verbose) | |
860 (when verbose (message "Fontifying...")) | |
861 (let ((inhibit-read-only t)) | |
862 (save-excursion | |
863 (dolist (e `((occur-title . ,list-matching-lines-buffer-name-face) | |
864 (occur-match . ,list-matching-lines-face))) | |
865 ; (occur-prefix . ,list-matching-lines-prefix-face))) | |
866 (goto-char beg) | |
867 (let ((change-end nil)) | |
868 (while (setq change-end (occur-fontify-on-property (car e) | |
869 (cdr e) | |
870 (point) | |
871 end)) | |
872 (goto-char change-end)))))) | |
873 (when verbose (message "Fontifying...done"))) | |
874 | 857 |
875 | 858 |
876 ;; It would be nice to use \\[...], but there is no reasonable way | 859 ;; It would be nice to use \\[...], but there is no reasonable way |
877 ;; to make that display both SPC and Y. | 860 ;; to make that display both SPC and Y. |
878 (defconst query-replace-help | 861 (defconst query-replace-help |