/[emacs]/emacs/lisp/replace.el
ViewVC logotype

Diff of /emacs/lisp/replace.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.148 by walters, Sun Jun 9 00:17:17 2002 UTC revision 1.148.2.1 by miles, Fri Apr 4 06:20:10 2003 UTC
# Line 70  strings or patterns." Line 70  strings or patterns."
70    (let (from to)    (let (from to)
71      (if query-replace-interactive      (if query-replace-interactive
72          (setq from (car (if regexp-flag regexp-search-ring search-ring)))          (setq from (car (if regexp-flag regexp-search-ring search-ring)))
73        (setq from (read-from-minibuffer (format "%s: " string)        ;; The save-excursion here is in case the user marks and copies
74                                         nil nil nil        ;; a region in order to specify the minibuffer input.
75                                         query-replace-from-history-variable        ;; That should not clobber the region for the query-replace itself.
76                                         nil t))        (save-excursion
77            (setq from (read-from-minibuffer (format "%s: " string)
78                                             nil nil nil
79                                             query-replace-from-history-variable
80                                             nil t)))
81        ;; Warn if user types \n or \t, but don't reject the input.        ;; Warn if user types \n or \t, but don't reject the input.
82        (if (string-match "\\\\[nt]" from)        (if (string-match "\\\\[nt]" from)
83            (let ((match (match-string 0 from)))            (let ((match (match-string 0 from)))
# Line 84  strings or patterns." Line 88  strings or patterns."
88                (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))                (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
89              (sit-for 2))))              (sit-for 2))))
90    
91      (setq to (read-from-minibuffer (format "%s %s with: " string from)      (save-excursion
92                                     nil nil nil        (setq to (read-from-minibuffer (format "%s %s with: " string from)
93                                     query-replace-to-history-variable from t))                                       nil nil nil
94      (if (and transient-mark-mode mark-active)                                       query-replace-to-history-variable from t)))
95          (list from to current-prefix-arg (region-beginning) (region-end))      (list from to current-prefix-arg)))
       (list from to current-prefix-arg nil nil))))  
96    
97  (defun query-replace (from-string to-string &optional delimited start end)  (defun query-replace (from-string to-string &optional delimited start end)
98    "Replace some occurrences of FROM-STRING with TO-STRING.    "Replace some occurrences of FROM-STRING with TO-STRING.
# Line 103  If `query-replace-interactive' is non-ni Line 106  If `query-replace-interactive' is non-ni
106  string is used as FROM-STRING--you don't have to specify it with the  string is used as FROM-STRING--you don't have to specify it with the
107  minibuffer.  minibuffer.
108    
109  Replacement transfers the case of the old text to the new text,  Matching is independent of case if `case-fold-search' is non-nil and
110  if `case-replace' and `case-fold-search'  FROM-STRING has no uppercase letters.  Replacement transfers the case
111  are non-nil and FROM-STRING has no uppercase letters.  pattern of the old text to the new text, if `case-replace' and
112  \(Preserving case means that if the string matched is all caps, or capitalized,  `case-fold-search' are non-nil and FROM-STRING has no uppercase
113  then its replacement is upcased or capitalized.)  letters.  \(Transferring the case pattern means that if the old text
114    matched is all caps, or capitalized, then its replacement is upcased
115    or capitalized.)
116    
117  Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace  Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
118  only matches surrounded by word boundaries.  only matches surrounded by word boundaries.
119  Fourth and fifth arg START and END specify the region to operate on.  Fourth and fifth arg START and END specify the region to operate on.
120    
121  To customize possible responses, change the \"bindings\" in `query-replace-map'."  To customize possible responses, change the \"bindings\" in `query-replace-map'."
122    (interactive (query-replace-read-args "Query replace" nil))    (interactive (let ((common
123                          (query-replace-read-args "Query replace" nil)))
124                     (list (nth 0 common) (nth 1 common) (nth 2 common)
125                           ;; These are done separately here
126                           ;; so that command-history will record these expressions
127                           ;; rather than the values they had this time.
128                           (if (and transient-mark-mode mark-active)
129                               (region-beginning))
130                           (if (and transient-mark-mode mark-active)
131                               (region-end)))))
132    (perform-replace from-string to-string t nil delimited nil nil start end))    (perform-replace from-string to-string t nil delimited nil nil start end))
133    
134  (define-key esc-map "%" 'query-replace)  (define-key esc-map "%" 'query-replace)
# Line 131  If `query-replace-interactive' is non-ni Line 145  If `query-replace-interactive' is non-ni
145  regexp is used as REGEXP--you don't have to specify it with the  regexp is used as REGEXP--you don't have to specify it with the
146  minibuffer.  minibuffer.
147    
148  Preserves case in each replacement if `case-replace' and `case-fold-search'  Matching is independent of case if `case-fold-search' is non-nil and
149  are non-nil and REGEXP has no uppercase letters.  REGEXP has no uppercase letters.  Replacement transfers the case
150    pattern of the old text to the new text, if `case-replace' and
151    `case-fold-search' are non-nil and REGEXP has no uppercase letters.
152    \(Transferring the case pattern means that if the old text matched is
153    all caps, or capitalized, then its replacement is upcased or
154    capitalized.)
155    
156  Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace  Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
157  only matches surrounded by word boundaries.  only matches surrounded by word boundaries.
# Line 141  Fourth and fifth arg START and END speci Line 160  Fourth and fifth arg START and END speci
160  In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,  In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
161  and `\\=\\N' (where N is a digit) stands for  and `\\=\\N' (where N is a digit) stands for
162   whatever what matched the Nth `\\(...\\)' in REGEXP."   whatever what matched the Nth `\\(...\\)' in REGEXP."
163    (interactive (query-replace-read-args "Query replace regexp" t))    (interactive
164       (let ((common
165              (query-replace-read-args "Query replace regexp" t)))
166         (list (nth 0 common) (nth 1 common) (nth 2 common)
167               ;; These are done separately here
168               ;; so that command-history will record these expressions
169               ;; rather than the values they had this time.
170               (if (and transient-mark-mode mark-active)
171                   (region-beginning))
172               (if (and transient-mark-mode mark-active)
173                   (region-end)))))
174    
175    (perform-replace regexp to-string t t delimited nil nil start end))    (perform-replace regexp to-string t t delimited nil nil start end))
176  (define-key esc-map [?\C-%] 'query-replace-regexp)  (define-key esc-map [?\C-%] 'query-replace-regexp)
177    
# Line 174  Third arg DELIMITED (prefix arg if inter Line 204  Third arg DELIMITED (prefix arg if inter
204  only matches that are surrounded by word boundaries.  only matches that are surrounded by word boundaries.
205  Fourth and fifth arg START and END specify the region to operate on."  Fourth and fifth arg START and END specify the region to operate on."
206    (interactive    (interactive
207     (let (from to start end)     (let (from to)
      (when (and transient-mark-mode mark-active)  
        (setq start (region-beginning)  
              end (region-end)))  
208       (if query-replace-interactive       (if query-replace-interactive
209           (setq from (car regexp-search-ring))           (setq from (car regexp-search-ring))
210         (setq from (read-from-minibuffer "Query replace regexp: "         (setq from (read-from-minibuffer "Query replace regexp: "
# Line 190  Fourth and fifth arg START and END speci Line 217  Fourth and fifth arg START and END speci
217       ;; We make TO a list because replace-match-string-symbols requires one,       ;; We make TO a list because replace-match-string-symbols requires one,
218       ;; and the user might enter a single token.       ;; and the user might enter a single token.
219       (replace-match-string-symbols to)       (replace-match-string-symbols to)
220       (list from (car to) current-prefix-arg start end)))       (list from (car to) current-prefix-arg
221               (if (and transient-mark-mode mark-active)
222                   (region-beginning))
223               (if (and transient-mark-mode mark-active)
224                   (region-end)))))
225    (perform-replace regexp (cons 'replace-eval-replacement to-expr)    (perform-replace regexp (cons 'replace-eval-replacement to-expr)
226                     t t delimited nil nil start end))                     t t delimited nil nil start end))
227    
# Line 215  A prefix argument N says to use each rep Line 246  A prefix argument N says to use each rep
246  before rotating to the next.  before rotating to the next.
247  Fourth and fifth arg START and END specify the region to operate on."  Fourth and fifth arg START and END specify the region to operate on."
248    (interactive    (interactive
249     (let (from to start end)     (let (from to)
      (when (and transient-mark-mode mark-active)  
        (setq start (region-beginning)  
              end (region-end)))  
250       (setq from (if query-replace-interactive       (setq from (if query-replace-interactive
251                      (car regexp-search-ring)                      (car regexp-search-ring)
252                    (read-from-minibuffer "Map query replace (regexp): "                    (read-from-minibuffer "Map query replace (regexp): "
# Line 229  Fourth and fifth arg START and END speci Line 257  Fourth and fifth arg START and END speci
257                         from)                         from)
258                 nil nil nil                 nil nil nil
259                 'query-replace-history from t))                 'query-replace-history from t))
260       (list from to start end current-prefix-arg)))       (list from to
261               (and current-prefix-arg
262                    (prefix-numeric-value current-prefix-arg))
263               (if (and transient-mark-mode mark-active)
264                   (region-beginning))
265               (if (and transient-mark-mode mark-active)
266                   (region-end)))))
267    (let (replacements)    (let (replacements)
268      (if (listp to-strings)      (if (listp to-strings)
269          (setq replacements to-strings)          (setq replacements to-strings)
# Line 270  What you probably want is a loop like th Line 304  What you probably want is a loop like th
304  which will run faster and will not set the mark or print anything.  which will run faster and will not set the mark or print anything.
305  \(You may need a more complex loop if FROM-STRING can match the null string  \(You may need a more complex loop if FROM-STRING can match the null string
306  and TO-STRING is also null.)"  and TO-STRING is also null.)"
307    (interactive (query-replace-read-args "Replace string" nil))    (interactive
308       (let ((common
309              (query-replace-read-args "Replace string" nil)))
310         (list (nth 0 common) (nth 1 common) (nth 2 common)
311               (if (and transient-mark-mode mark-active)
312                   (region-beginning))
313               (if (and transient-mark-mode mark-active)
314                   (region-end)))))
315    (perform-replace from-string to-string nil nil delimited nil nil start end))    (perform-replace from-string to-string nil nil delimited nil nil start end))
316    
317  (defun replace-regexp (regexp to-string &optional delimited start end)  (defun replace-regexp (regexp to-string &optional delimited start end)
# Line 297  What you probably want is a loop like th Line 338  What you probably want is a loop like th
338    (while (re-search-forward REGEXP nil t)    (while (re-search-forward REGEXP nil t)
339      (replace-match TO-STRING nil nil))      (replace-match TO-STRING nil nil))
340  which will run faster and will not set the mark or print anything."  which will run faster and will not set the mark or print anything."
341    (interactive (query-replace-read-args "Replace regexp" t))    (interactive
342       (let ((common
343              (query-replace-read-args "Replace regexp" t)))
344         (list (nth 0 common) (nth 1 common) (nth 2 common)
345               (if (and transient-mark-mode mark-active)
346                   (region-beginning))
347               (if (and transient-mark-mode mark-active)
348                   (region-end)))))
349    (perform-replace regexp to-string nil t delimited nil nil start end))    (perform-replace regexp to-string nil t delimited nil nil start end))
350    
351    
# Line 332  on the contents of the region.  Otherwis Line 380  on the contents of the region.  Otherwis
380  end of the buffer."  end of the buffer."
381    
382    (interactive    (interactive
383     (keep-lines-read-args "Keep lines (containing match for regexp): "))     (progn
384         (barf-if-buffer-read-only)
385         (keep-lines-read-args "Keep lines (containing match for regexp): ")))
386    (if rstart    (if rstart
387        (goto-char (min rstart rend))        (progn
388            (goto-char (min rstart rend))
389            (setq rend (copy-marker (max rstart rend))))
390      (if (and transient-mark-mode mark-active)      (if (and transient-mark-mode mark-active)
391          (setq rstart (region-beginning)          (setq rstart (region-beginning)
392                rend (copy-marker (region-end)))                rend (copy-marker (region-end)))
# Line 356  end of the buffer." Line 408  end of the buffer."
408              ;; Now end is first char preserved by the new match.              ;; Now end is first char preserved by the new match.
409              (if (< start end)              (if (< start end)
410                  (delete-region start end))))                  (delete-region start end))))
411            
412          (setq start (save-excursion (forward-line 1) (point)))          (setq start (save-excursion (forward-line 1) (point)))
413          ;; If the match was empty, avoid matching again at same place.          ;; If the match was empty, avoid matching again at same place.
414          (and (< (point) rend)          (and (< (point) rend)
# Line 379  on the contents of the region.  Otherwis Line 431  on the contents of the region.  Otherwis
431  end of the buffer."  end of the buffer."
432    
433    (interactive    (interactive
434     (keep-lines-read-args "Flush lines (containing match for regexp): "))     (progn
435         (barf-if-buffer-read-only)
436         (keep-lines-read-args "Flush lines (containing match for regexp): ")))
437    (if rstart    (if rstart
438        (goto-char (min rstart rend))        (progn
439            (goto-char (min rstart rend))
440            (setq rend (copy-marker (max rstart rend))))
441      (if (and transient-mark-mode mark-active)      (if (and transient-mark-mode mark-active)
442          (setq rstart (region-beginning)          (setq rstart (region-beginning)
443                rend (copy-marker (region-end)))                rend (copy-marker (region-end)))
# Line 444  end of the buffer." Line 500  end of the buffer."
500      (define-key map "\C-o" 'occur-mode-display-occurrence)      (define-key map "\C-o" 'occur-mode-display-occurrence)
501      (define-key map "\M-n" 'occur-next)      (define-key map "\M-n" 'occur-next)
502      (define-key map "\M-p" 'occur-prev)      (define-key map "\M-p" 'occur-prev)
503        (define-key map "r" 'occur-rename-buffer)
504        (define-key map "c" 'clone-buffer)
505      (define-key map "g" 'revert-buffer)      (define-key map "g" 'revert-buffer)
506      (define-key map "q" 'delete-window)      (define-key map "q" 'quit-window)
507        (define-key map "z" 'kill-this-buffer)
508      map)      map)
509    "Keymap for `occur-mode'.")    "Keymap for `occur-mode'.")
510    
# Line 454  end of the buffer." Line 513  end of the buffer."
513  See `occur-revert-function'.")  See `occur-revert-function'.")
514    
515  (defcustom occur-mode-hook '(turn-on-font-lock)  (defcustom occur-mode-hook '(turn-on-font-lock)
516    "Hooks run when `occur' is called."    "Hook run when entering Occur mode."
517      :type 'hook
518      :group 'matching)
519    
520    (defcustom occur-hook nil
521      "Hook run when `occur' is called."
522    :type 'hook    :type 'hook
523    :group 'matching)    :group 'matching)
524    
# Line 466  See `occur-revert-function'.") Line 530  See `occur-revert-function'.")
530  Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.  Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
531    
532  \\{occur-mode-map}"  \\{occur-mode-map}"
533      (interactive)
534    (kill-all-local-variables)    (kill-all-local-variables)
535    (use-local-map occur-mode-map)    (use-local-map occur-mode-map)
536    (setq major-mode 'occur-mode)    (setq major-mode 'occur-mode)
537    (setq mode-name "Occur")    (setq mode-name "Occur")
538    (set (make-local-variable 'revert-buffer-function) 'occur-revert-function)    (set (make-local-variable 'revert-buffer-function) 'occur-revert-function)
   (set (make-local-variable 'font-lock-defaults)  
        '(nil t nil nil nil (font-lock-core-only . t)))  
539    (make-local-variable 'occur-revert-arguments)    (make-local-variable 'occur-revert-arguments)
540      (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
541    (run-hooks 'occur-mode-hook))    (run-hooks 'occur-mode-hook))
542    
543  (defun occur-revert-function (ignore1 ignore2)  (defun occur-revert-function (ignore1 ignore2)
# Line 528  Alternatively, click \\[occur-mode-mouse Line 592  Alternatively, click \\[occur-mode-mouse
592        (select-window window)        (select-window window)
593        (goto-char pos))))        (goto-char pos))))
594    
595  (defun occur-next (&optional n)  (defun occur-find-match (n search message)
   "Move to the Nth (default 1) next match in an Occur mode buffer."  
   (interactive "p")  
596    (if (not n) (setq n 1))    (if (not n) (setq n 1))
597    (let ((r))    (let ((r))
598      (while (> n 0)      (while (> n 0)
599        (if (get-text-property (point) 'occur-point)        (setq r (funcall search (point) 'occur-match))
600            (forward-char 1))        (and r
601        (setq r (next-single-property-change (point) 'occur-point))             (get-text-property r 'occur-match)
602               (setq r (funcall search r 'occur-match)))
603        (if r        (if r
604            (goto-char r)            (goto-char r)
605          (error "No more matches"))          (error message))
606        (setq n (1- n)))))        (setq n (1- n)))))
607    
608    (defun occur-next (&optional n)
609      "Move to the Nth (default 1) next match in an Occur mode buffer."
610      (interactive "p")
611      (occur-find-match n #'next-single-property-change "No more matches"))
612    
613  (defun occur-prev (&optional n)  (defun occur-prev (&optional n)
614    "Move to the Nth (default 1) previous match in an Occur mode buffer."    "Move to the Nth (default 1) previous match in an Occur mode buffer."
615    (interactive "p")    (interactive "p")
616    (if (not n) (setq n 1))    (occur-find-match n #'previous-single-property-change "No earlier matches"))
   (let ((r))  
     (while (> n 0)  
       
       (setq r (get-text-property (point) 'occur-point))  
       (if r (forward-char -1))  
         
       (setq r (previous-single-property-change (point) 'occur-point))  
       (if r  
           (goto-char (- r 1))  
         (error "No earlier matches"))  
         
       (setq n (1- n)))))  
617    
618  (defcustom list-matching-lines-default-context-lines 0  (defcustom list-matching-lines-default-context-lines 0
619    "*Default number of context lines included around `list-matching-lines' matches.    "*Default number of context lines included around `list-matching-lines' matches.
# Line 617  If the value is nil, don't highlight the Line 673  If the value is nil, don't highlight the
673          (when current-prefix-arg          (when current-prefix-arg
674            (prefix-numeric-value current-prefix-arg))))            (prefix-numeric-value current-prefix-arg))))
675    
676    (defun occur-rename-buffer (&optional unique-p)
677      "Rename the current *Occur* buffer to *Occur: original-buffer-name*.
678    Here `original-buffer-name' is the buffer name were occur was originally run.
679    When given the prefix argument, the renaming will not clobber the existing
680    buffer(s) of that name, but use `generate-new-buffer-name' instead.
681    You can add this to `occur-hook' if you always want a separate *Occur*
682    buffer for each buffer where you invoke `occur'."
683      (interactive "P")
684      (with-current-buffer
685          (if (eq major-mode 'occur-mode) (current-buffer) (get-buffer "*Occur*"))
686        (rename-buffer (concat "*Occur: "
687                               (mapconcat #'buffer-name
688                                          (car (cddr occur-revert-arguments)) "/")
689                               "*")
690                       unique-p)))
691    
692  (defun occur (regexp &optional nlines)  (defun occur (regexp &optional nlines)
693    "Show all lines in the current buffer containing a match for REGEXP.    "Show all lines in the current buffer containing a match for REGEXP.
694    
# Line 642  This function acts on multiple buffers; Line 714  This function acts on multiple buffers;
714  `occur'."  `occur'."
715    (interactive    (interactive
716     (cons     (cons
717      (let ((bufs (list (read-buffer "First buffer to search: "      (let* ((bufs (list (read-buffer "First buffer to search: "
718                                     (current-buffer) t)))                                      (current-buffer) t)))
719            (buf nil))             (buf nil)
720               (ido-ignore-item-temp-list bufs))
721        (while (not (string-equal        (while (not (string-equal
722                     (setq buf (read-buffer "Next buffer to search (RET to end): "                     (setq buf (read-buffer
723                                            nil t))                                (if (eq read-buffer-function 'ido-read-buffer)
724                                      "Next buffer to search (C-j to end): "
725                                    "Next buffer to search (RET to end): ")
726                                  nil t))
727                     ""))                     ""))
728          (push buf bufs))          (add-to-list 'bufs buf)
729            (setq ido-ignore-item-temp-list bufs))
730        (nreverse (mapcar #'get-buffer bufs)))        (nreverse (mapcar #'get-buffer bufs)))
731      (occur-read-primary-args)))      (occur-read-primary-args)))
732    (occur-1 regexp nlines bufs))    (occur-1 regexp nlines bufs))
# Line 706  See also `multi-occur'." Line 783  See also `multi-occur'."
783                           (isearch-no-upper-case-p regexp t))                           (isearch-no-upper-case-p regexp t))
784                      list-matching-lines-buffer-name-face                      list-matching-lines-buffer-name-face
785                      nil list-matching-lines-face nil)))                      nil list-matching-lines-face nil)))
786          (let* ((diff (- (length bufs) (length active-bufs)))          (let* ((bufcount (length active-bufs))
787                 (bufcount (- (length bufs) diff))                 (diff (- (length bufs) bufcount)))
788                 (msg (concat            (message "Searched %d buffer%s%s; %s match%s for `%s'"
789                       (format "Searched %d buffer%s" bufcount (if (= bufcount 1) "" "s"))                     bufcount (if (= bufcount 1) "" "s")
790                       "%s; "                     (if (zerop diff) "" (format " (%d killed)" diff))
791                       (format "%s match%s for `%s'"                     (if (zerop count) "no" (format "%d" count))
792                               (if (zerop count)                     (if (= count 1) "" "es")
793                                   "no"                     regexp))
                                (format "%d" count))  
                              (if (= count 1)  
                                  ""  
                                "es")  
                              regexp))))  
           (message msg (if (zerop diff)  
                            ""  
                          (format " (%d killed)" diff))))  
794          ;; If we had to make a temporary buffer, make it the *Occur*          ;; If we had to make a temporary buffer, make it the *Occur*
795          ;; buffer now.          ;; buffer now.
796          (when made-temp-buf          (when made-temp-buf
# Line 732  See also `multi-occur'." Line 801  See also `multi-occur'."
801                buffer-read-only t)                buffer-read-only t)
802          (if (> count 0)          (if (> count 0)
803              (display-buffer occur-buf)              (display-buffer occur-buf)
804            (kill-buffer occur-buf))))))            (kill-buffer occur-buf)))
805          (run-hooks 'occur-hook))))
806    
807  (defun occur-engine-add-prefix (lines)  (defun occur-engine-add-prefix (lines)
808    (mapcar    (mapcar
809     #'(lambda (line)     #'(lambda (line)
810         (concat "      :" line "\n"))         (concat "       :" line "\n"))
811     lines))     lines))
812    
813  (defun occur-engine (regexp buffers out-buf nlines case-fold-search  (defun occur-engine (regexp buffers out-buf nlines case-fold-search
814                              title-face prefix-face match-face keep-props)                              title-face prefix-face match-face keep-props)
815    (with-current-buffer out-buf    (with-current-buffer out-buf
816      (setq buffer-read-only nil)      (setq buffer-read-only nil)
817      (let ((globalcount 0))      (let ((globalcount 0)
818              (coding nil))
819        ;; Map over all the buffers        ;; Map over all the buffers
820        (dolist (buf buffers)        (dolist (buf buffers)
821          (when (buffer-live-p buf)          (when (buffer-live-p buf)
# Line 760  See also `multi-occur'." Line 831  See also `multi-occur'."
831                  (headerpt (with-current-buffer out-buf (point))))                  (headerpt (with-current-buffer out-buf (point))))
832              (save-excursion              (save-excursion
833                (set-buffer buf)                (set-buffer buf)
834                  (or coding
835                      ;; Set CODING only if the current buffer locally
836                      ;; binds buffer-file-coding-system.
837                      (not (local-variable-p 'buffer-file-coding-system))
838                      (setq coding buffer-file-coding-system))
839                (save-excursion                (save-excursion
840                  (goto-char (point-min)) ;; begin searching in the buffer                  (goto-char (point-min)) ;; begin searching in the buffer
841                  (while (not (eobp))                  (while (not (eobp))
# Line 795  See also `multi-occur'." Line 871  See also `multi-occur'."
871                      ;; Generate the string to insert for this match                      ;; Generate the string to insert for this match
872                      (let* ((out-line                      (let* ((out-line
873                              (concat                              (concat
874                               (apply #'propertize (format "%6d:" lines)                               ;; Using 7 digits aligns tabs properly.
875                                 (apply #'propertize (format "%7d:" lines)
876                                      (append                                      (append
877                                       (when prefix-face                                       (when prefix-face
878                                         `(font-lock-face prefix-face))                                         `(font-lock-face prefix-face))
# Line 848  See also `multi-occur'." Line 925  See also `multi-occur'."
925                                            `(font-lock-face ,title-face))                                            `(font-lock-face ,title-face))
926                                          `(occur-title ,buf))))                                          `(occur-title ,buf))))
927                  (goto-char (point-min)))))))                  (goto-char (point-min)))))))
928          (if coding
929              ;; CODING is buffer-file-coding-system of the first buffer
930              ;; that locally binds it.  Let's use it also for the output
931              ;; buffer.
932              (set-buffer-file-coding-system coding))
933        ;; Return the number of matches        ;; Return the number of matches
934        globalcount)))        globalcount)))
935    
# Line 950  type them." Line 1032  type them."
1032            (aset data 2 (if (consp next) next (aref data 3))))))            (aset data 2 (if (consp next) next (aref data 3))))))
1033    (car (aref data 2)))    (car (aref data 2)))
1034    
1035  (defun perform-replace (from-string replacements  (defun perform-replace (from-string replacements
1036                          query-flag regexp-flag delimited-flag                          query-flag regexp-flag delimited-flag
1037                          &optional repeat-count map start end)                          &optional repeat-count map start end)
1038    "Subroutine of `query-replace'.  Its complexity handles interactive queries.    "Subroutine of `query-replace'.  Its complexity handles interactive queries.
# Line 1175  make, or the user didn't cancel the call Line 1257  make, or the user didn't cancel the call
1257                           (if (and regexp-flag nonempty-match)                           (if (and regexp-flag nonempty-match)
1258                               (setq match-again (and (looking-at search-string)                               (setq match-again (and (looking-at search-string)
1259                                                      (match-data)))))                                                      (match-data)))))
1260                          
1261                          ;; Edit replacement.                          ;; Edit replacement.
1262                          ((eq def 'edit-replacement)                          ((eq def 'edit-replacement)
1263                           (setq next-replacement                           (setq next-replacement
# Line 1184  make, or the user didn't cancel the call Line 1266  make, or the user didn't cancel the call
1266                           (or replaced                           (or replaced
1267                               (replace-match next-replacement nocasify literal))                               (replace-match next-replacement nocasify literal))
1268                           (setq done t))                           (setq done t))
1269                          
1270                          ((eq def 'delete-and-edit)                          ((eq def 'delete-and-edit)
1271                           (delete-region (match-beginning 0) (match-end 0))                           (delete-region (match-beginning 0) (match-end 0))
1272                           (set-match-data                           (set-match-data
# Line 1214  make, or the user didn't cancel the call Line 1296  make, or the user didn't cancel the call
1296        ;; beyond the last replacement.  Undo that.        ;; beyond the last replacement.  Undo that.
1297        (when (and regexp-flag (not match-again) (> replace-count 0))        (when (and regexp-flag (not match-again) (> replace-count 0))
1298          (backward-char 1))          (backward-char 1))
1299          
1300        (replace-dehighlight))        (replace-dehighlight))
1301      (or unread-command-events      (or unread-command-events
1302          (message "Replaced %d occurrence%s"          (message "Replaced %d occurrence%s"

Legend:
Removed from v.1.148  
changed lines
  Added in v.1.148.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26