• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/

Lines Matching +defs:string +defs:match

27 ;; This package supplies the string and regular-expression replace functions
45 "Non-nil means `query-replace' uses the last search string.
46 That becomes the \"string to replace\".")
79 When non-nil, all text in the buffer matching the current match
93 (defun query-replace-descr (string)
94 (mapconcat 'isearch-text-char-description string ""))
124 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
125 (let ((match (match-string 3 from)))
127 ((string= match "\\n")
128 (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead"))
129 ((string= match "\\t")
130 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
137 the original string if not."
139 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
143 (setq pos (match-end 0))
148 (push '(number-to-string replace-count) list))
150 (setq pos (read-from-string to))
160 (eq (string-match " " to (cdr pos))
165 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)))
167 (replace-match-string-symbols to)
197 (defun query-replace (from-string to-string &optional delimited start end)
199 As each match is found, the user must type a character saying
206 string is used as FROM-STRING--you don't have to specify it with the
236 (perform-replace from-string to-string t nil delimited nil nil start end))
240 (defun query-replace-regexp (regexp to-string &optional delimited start end)
242 As each match is found, the user must type a character saying
273 string. Inside of that expression, `\\&' is a string denoting the
274 whole match as a string, `\\N' for a partial match, `\\#&' and `\\#N'
275 for the whole or a partial match converted to a number with
276 `string-to-number', and `\\#' itself for the number of replacements
283 text, TO-STRING is actually made a list instead of a string.
300 (perform-replace regexp to-string t t delimited nil nil start end))
309 using `search-forward-regexp' and `replace-match' is preferred.
311 As each match is found, the user must type a character saying
316 If the result of TO-EXPR is not a string, it is converted to one using
317 `prin1-to-string' with the NOESCAPE argument (which see).
322 Use `\\#&' or `\\#N' if you want a number instead of a string.
351 ;; We make TO a list because replace-match-string-symbols requires one,
353 (replace-match-string-symbols to)
365 using `search-forward-regexp' and `replace-match' is preferred." "22.1")
373 successive replacement uses the next successive replacement string,
374 wrapping around from the last such string to the first.
384 A prefix argument N says to use each replacement string N times
409 (if (string-match " " to-strings)
413 (string-match " " to-strings))))
415 (1+ (string-match " " to-strings))))
420 (defun replace-string (from-string to-string &optional delimited start end)
422 Preserve case in each match if `case-replace' and `case-fold-search'
424 \(Preserving case means that if the string matched is all caps, or capitalized,
435 string is used as FROM-STRING--you don't have to specify it with the
441 (replace-match TO-STRING nil t))
443 \(You may need a more complex loop if FROM-STRING can match the null string
449 "Replace string in region"
450 "Replace string")
457 (perform-replace from-string to-string nil nil delimited nil nil start end))
459 (defun replace-regexp (regexp to-string &optional delimited start end)
461 Preserve case in each match if `case-replace' and `case-fold-search'
479 text. Inside of that expression, `\\&' is a string denoting the
480 whole match, `\\N' a partial match, `\\#&' and `\\#N' the respective
481 numeric values from `string-to-number', and `\\#' itself for
485 the replacement string would be interpreted as part of it, you
491 text, TO-STRING is actually made a list instead of a string.
500 (replace-match TO-STRING nil nil))
514 (perform-replace regexp to-string nil t delimited nil nil start end))
537 A match split across lines preserves all the lines it lies in.
555 This function starts looking for the next match from the end of
556 the previous match. Hence, it ignores matches that overlap
557 a previously found match."
562 (keep-lines-read-args "Keep lines (containing match for regexp): ")))
589 ;; Start is first char not preserved by previous match.
592 (let ((end (save-excursion (goto-char (match-beginning 0))
595 ;; Now end is first char preserved by the new match.
600 ;; If the match was empty, avoid matching again at same place.
602 (= (match-beginning 0) (match-end 0))
613 match for regexp starting after point.
620 they contain a match entirely contained in it.
628 If a match is split across lines, all the lines it lies in are deleted.
629 They are deleted _before_ looking for the next match. Hence, a match
630 starting on the same line at which another match ended is ignored."
635 (keep-lines-read-args "Flush lines (containing match for regexp): ")))
651 (delete-region (save-excursion (goto-char (match-beginning 0))
674 This function starts looking for the next match from the end of
675 the previous match. Hence, it ignores matches that overlap
676 a previously found match."
812 (defun occur-find-match (n search message)
816 (setq r (funcall search (point) 'occur-match))
818 (get-text-property r 'occur-match)
819 (setq r (funcall search r 'occur-match)))
826 "Move to the Nth (default 1) next match in an Occur mode buffer."
828 (occur-find-match n #'next-single-property-change "No more matches"))
831 "Move to the Nth (default 1) previous match in an Occur mode buffer."
833 (occur-find-match n #'previous-single-property-change "No earlier matches"))
836 "Move to the Nth (default 1) next match in an Occur mode buffer.
839 ;; we need to run occur-find-match from within the Occur buffer
852 (occur-find-match
864 (defface match
882 A negative number means to include that many lines before the match.
889 (defcustom list-matching-lines-face 'match
974 "Show all lines in the current buffer containing a match for REGEXP.
992 "Show all lines in buffers BUFS containing a match for REGEXP.
1002 (while (not (string-equal
1026 "List lines in buffers whose names match regexp: "
1027 "List lines in buffers whose filenames match regexp: ")
1041 (string-match bufregexp
1044 (string-match bufregexp
1082 (message "Searched %d buffer%s%s; %s match%s for `%s'"
1104 title-face prefix-face match-face keep-props)
1132 (setq matches (1+ matches)) ;; increment match count
1133 (setq matchbeg (match-beginning 0))
1156 (string-match regexp curstring start))
1158 (match-beginning 0) (match-end 0)
1160 `(occur-match t)
1161 (when match-face
1164 `(face ,match-face)))
1166 (setq start (match-end 0))))
1167 ;; Generate the string to insert for this match
1202 ;; Actually insert the match display data
1212 ;; On to the next match...
1221 (insert (format "%d match%s for \"%s\" in buffer: %s\n"
1244 "Type Space or `y' to replace one match, Delete or `n' to skip to next,
1245 RET or `q' to exit, Period to replace one match and exit,
1248 C-w to delete match and recursive edit,
1251 ^ to move point back to previous match,
1252 E to edit the replacement string"
1292 (defun replace-match-string-symbols (n)
1295 N (match-string N) (where N is a string of digits)
1296 #N (string-to-number (match-string N))
1297 & (match-string 0)
1298 #& (string-to-number (match-string 0))
1306 (replace-match-string-symbols (car n))) ;Process sub-list
1310 ((string-match "^[0-9]+$" name)
1311 (setcar n (list 'match-string (string-to-number name))))
1312 ((string-match "^#[0-9]+$" name)
1313 (setcar n (list 'string-to-number
1314 (list 'match-string
1315 (string-to-number (substring name 1))))))
1316 ((string= "&" name)
1317 (setcar n '(match-string 0)))
1318 ((string= "#&" name)
1319 (setcar n '(string-to-number (match-string 0))))
1320 ((string= "#" name)
1328 (prin1-to-string replacement t))))
1331 "Quote a replacement string.
1333 returns the resulting string. If REPLACEMENT is not
1334 a string, it is first passed through `prin1-to-string'
1337 `match-data' is preserved across the call."
1338 (save-match-data
1339 (replace-regexp-in-string "\\\\" "\\\\"
1342 (prin1-to-string replacement t))
1358 (defun replace-match-data (integers reuse &optional new)
1359 "Like `match-data', but markers in REUSE get invalidated.
1364 (set-match-data new)
1368 (match-data integers reuse t)))
1370 (defun replace-match-maybe-edit (newtext fixedcase literal noedit match-data)
1371 "Make a replacement with `replace-match', editing `\\?'.
1380 (while (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\\\?\\)"
1383 (read-string "Edit replacement string: "
1386 (replace-match "" t t newtext 3)
1387 (1+ (match-beginning 3)))
1388 (setq match-data
1389 (replace-match-data
1390 nil match-data match-data))))
1392 (set-match-data match-data)
1393 (replace-match newtext fixedcase literal)
1396 (defun perform-replace (from-string replacements
1404 (replace-match \"foobar\" nil nil))
1407 see the documentation of `replace-match' to find out how to simulate
1416 (string-equal from-string
1417 (downcase from-string)))))
1419 (string-equal from-string
1420 (downcase from-string))))
1423 (search-string from-string)
1424 (real-match-data nil) ; the match data for the current match
1432 (nonempty-match nil)
1437 ;; Data for the next match. If a cons, it has the same format as
1438 ;; (match-data); otherwise it is t if a match is possible at point.
1439 (match-again t)
1454 ;; REPLACEMENTS is either a string, a list of strings, or a cons cell
1458 ;; It must return a string.
1463 ((stringp (car replacements)) ; If it isn't a string, it must be a cons
1471 search-string (concat "\\b"
1472 (if regexp-flag from-string
1473 (regexp-quote from-string))
1476 (setq isearch-lazy-highlight-last-string nil))
1484 ;; Use the next match if it is already known;
1485 ;; otherwise, search for a match after moving forward
1487 (setq real-match-data
1488 (cond ((consp match-again)
1489 (goto-char (nth 1 match-again))
1490 (replace-match-data
1491 t real-match-data match-again))
1493 ;; adjacent match.
1494 (match-again
1496 (funcall search-function search-string
1500 (replace-match-data t real-match-data)))
1511 search-function search-string
1513 (replace-match-data
1514 t real-match-data)
1518 ;; Record whether the match is nonempty, to avoid an infinite loop
1519 ;; repeatedly matching the same empty string.
1520 (setq nonempty-match
1521 (/= (nth 0 real-match-data) (nth 1 real-match-data)))
1523 ;; If the match is empty, record that the next one can't be
1527 ;; match now, since the replacement for this match may
1528 ;; affect whether the next match is adjacent to this one.
1529 ;; If that match is empty, don't use it.
1530 (setq match-again
1531 (and nonempty-match
1533 (and (looking-at search-string)
1534 (let ((match (match-data)))
1535 (and (/= (nth 0 match) (nth 1 match))
1536 match))))))
1541 (nth 0 real-match-data) (nth 1 real-match-data)
1544 ;; Calculate the replacement string, if necessary.
1546 (set-match-data real-match-data)
1555 (nth 0 real-match-data) (nth 1 real-match-data)
1556 start end search-string
1559 (replace-match-maybe-edit
1561 noedit real-match-data)
1568 ;; leave behind proper match data for the stack.
1570 ;; `real-match-data'.
1572 (set-match-data real-match-data)
1574 (match-beginning 0) (match-end 0)
1575 start end search-string
1581 (query-replace-descr from-string)
1585 ;; that clobbers the match data.
1586 (set-match-data real-match-data)
1589 ;; Restore the match data while we process the command.
1595 from-string " with "
1609 real-match-data
1610 (replace-match-data
1611 t real-match-data
1613 (message "No previous match")
1619 (replace-match-maybe-edit
1621 noedit real-match-data)
1627 (replace-match-maybe-edit
1629 noedit real-match-data)
1636 (replace-match-maybe-edit
1638 noedit real-match-data)
1640 real-match-data (replace-match-data
1641 t real-match-data)
1646 (replace-match-maybe-edit
1648 noedit real-match-data)
1657 (setq real-match-data (replace-match-data
1658 nil real-match-data
1659 real-match-data))
1660 (goto-char (match-beginning 0))
1667 ;; decide whether the search string
1668 ;; can match again just after this match.
1669 (if (and regexp-flag nonempty-match)
1670 (setq match-again (and (looking-at search-string)
1671 (match-data)))))
1674 (setq real-match-data (replace-match-data
1675 nil real-match-data
1676 real-match-data)
1678 (read-string "Edit replacement string: "
1682 (set-match-data real-match-data)
1684 (replace-match-maybe-edit
1686 real-match-data)
1691 (replace-match "" t t)
1692 (setq real-match-data (replace-match-data
1693 nil real-match-data))
1710 (setq isearch-lazy-highlight-last-string nil))))
1712 ;; Change markers to numbers in the match data
1716 ;;; current match start and end. We could get this with a trivial
1717 ;;; match like
1718 ;;; (save-excursion (goto-char (match-beginning 0))
1719 ;;; (search-forward (match-string 0))
1720 ;;; (match-data t))
1721 ;;; if we really wanted to avoid manually constructing match data.
1722 ;;; Adding current-buffer is necessary so that match-data calls can
1726 (match-beginning 0)
1727 (match-end 0)
1729 (match-data t)))
1741 (defun replace-highlight (match-beg match-end range-beg range-end
1742 string regexp case-fold)
1745 (move-overlay replace-overlay match-beg match-end (current-buffer))
1746 (setq replace-overlay (make-overlay match-beg match-end))
1750 (let ((isearch-string string)
1761 (setq isearch-lazy-highlight-last-string nil)))