diff options
| author | Juri Linkov | 2013-05-30 02:43:39 +0300 |
|---|---|---|
| committer | Juri Linkov | 2013-05-30 02:43:39 +0300 |
| commit | ac44d6c19fddcf20df723d94aa4f45641e0b55ed (patch) | |
| tree | 3e11abb18e54346298f53ac4fe5a9ec6d59c185a | |
| parent | 3c9c9d38d0335e5e8a904e4342838fdcdded870f (diff) | |
| download | emacs-ac44d6c19fddcf20df723d94aa4f45641e0b55ed.tar.gz emacs-ac44d6c19fddcf20df723d94aa4f45641e0b55ed.zip | |
* lisp/replace.el (occur-engine): Rename `globalcount' to `global-lines'
for total count of matching lines. Add `global-matches' for total
count of matches. Rename `matches' to `lines' for count of
matching lines. Add `matches' for count of matches.
Rename `lines' to `curr-line' for line count. Rename `prev-lines'
to `prev-line' for line number of prev match endpt.
Increment `matches' for every match. Print the number of
matching lines in the header.
(occur-context-lines): Rename `lines' to `curr-line'.
Rename `prev-lines' to `prev-line'.
Fixes: debbugs:14017
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/replace.el | 76 |
2 files changed, 58 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bcf8462d864..552af47db71 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,18 @@ | |||
| 1 | 2013-05-29 Juri Linkov <juri@jurta.org> | 1 | 2013-05-29 Juri Linkov <juri@jurta.org> |
| 2 | 2 | ||
| 3 | * replace.el (occur-engine): Rename `globalcount' to `global-lines' | ||
| 4 | for total count of matching lines. Add `global-matches' for total | ||
| 5 | count of matches. Rename `matches' to `lines' for count of | ||
| 6 | matching lines. Add `matches' for count of matches. | ||
| 7 | Rename `lines' to `curr-line' for line count. Rename `prev-lines' | ||
| 8 | to `prev-line' for line number of prev match endpt. | ||
| 9 | Increment `matches' for every match. Print the number of | ||
| 10 | matching lines in the header. | ||
| 11 | (occur-context-lines): Rename `lines' to `curr-line'. | ||
| 12 | Rename `prev-lines' to `prev-line'. (Bug#14017) | ||
| 13 | |||
| 14 | 2013-05-29 Juri Linkov <juri@jurta.org> | ||
| 15 | |||
| 3 | * replace.el (perform-replace): Add `skip-read-only-count', | 16 | * replace.el (perform-replace): Add `skip-read-only-count', |
| 4 | `skip-filtered-count', `skip-invisible-count' let-bound to 0. | 17 | `skip-filtered-count', `skip-invisible-count' let-bound to 0. |
| 5 | Increment them for corresponding conditions and report the number | 18 | Increment them for corresponding conditions and report the number |
diff --git a/lisp/replace.el b/lisp/replace.el index ae6622958d3..15d5f2694a8 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -1389,16 +1389,18 @@ See also `multi-occur'." | |||
| 1389 | (defun occur-engine (regexp buffers out-buf nlines case-fold | 1389 | (defun occur-engine (regexp buffers out-buf nlines case-fold |
| 1390 | title-face prefix-face match-face keep-props) | 1390 | title-face prefix-face match-face keep-props) |
| 1391 | (with-current-buffer out-buf | 1391 | (with-current-buffer out-buf |
| 1392 | (let ((globalcount 0) | 1392 | (let ((global-lines 0) ;; total count of matching lines |
| 1393 | (global-matches 0) ;; total count of matches | ||
| 1393 | (coding nil) | 1394 | (coding nil) |
| 1394 | (case-fold-search case-fold)) | 1395 | (case-fold-search case-fold)) |
| 1395 | ;; Map over all the buffers | 1396 | ;; Map over all the buffers |
| 1396 | (dolist (buf buffers) | 1397 | (dolist (buf buffers) |
| 1397 | (when (buffer-live-p buf) | 1398 | (when (buffer-live-p buf) |
| 1398 | (let ((matches 0) ;; count of matched lines | 1399 | (let ((lines 0) ;; count of matching lines |
| 1399 | (lines 1) ;; line count | 1400 | (matches 0) ;; count of matches |
| 1400 | (prev-after-lines nil) ;; context lines of prev match | 1401 | (curr-line 1) ;; line count |
| 1401 | (prev-lines nil) ;; line number of prev match endpt | 1402 | (prev-line nil) ;; line number of prev match endpt |
| 1403 | (prev-after-lines nil) ;; context lines of prev match | ||
| 1402 | (matchbeg 0) | 1404 | (matchbeg 0) |
| 1403 | (origpt nil) | 1405 | (origpt nil) |
| 1404 | (begpt nil) | 1406 | (begpt nil) |
| @@ -1419,7 +1421,7 @@ See also `multi-occur'." | |||
| 1419 | (while (not (eobp)) | 1421 | (while (not (eobp)) |
| 1420 | (setq origpt (point)) | 1422 | (setq origpt (point)) |
| 1421 | (when (setq endpt (re-search-forward regexp nil t)) | 1423 | (when (setq endpt (re-search-forward regexp nil t)) |
| 1422 | (setq matches (1+ matches)) ;; increment match count | 1424 | (setq lines (1+ lines)) ;; increment matching lines count |
| 1423 | (setq matchbeg (match-beginning 0)) | 1425 | (setq matchbeg (match-beginning 0)) |
| 1424 | ;; Get beginning of first match line and end of the last. | 1426 | ;; Get beginning of first match line and end of the last. |
| 1425 | (save-excursion | 1427 | (save-excursion |
| @@ -1428,7 +1430,7 @@ See also `multi-occur'." | |||
| 1428 | (goto-char endpt) | 1430 | (goto-char endpt) |
| 1429 | (setq endpt (line-end-position))) | 1431 | (setq endpt (line-end-position))) |
| 1430 | ;; Sum line numbers up to the first match line. | 1432 | ;; Sum line numbers up to the first match line. |
| 1431 | (setq lines (+ lines (count-lines origpt begpt))) | 1433 | (setq curr-line (+ curr-line (count-lines origpt begpt))) |
| 1432 | (setq marker (make-marker)) | 1434 | (setq marker (make-marker)) |
| 1433 | (set-marker marker matchbeg) | 1435 | (set-marker marker matchbeg) |
| 1434 | (setq curstring (occur-engine-line begpt endpt keep-props)) | 1436 | (setq curstring (occur-engine-line begpt endpt keep-props)) |
| @@ -1437,6 +1439,7 @@ See also `multi-occur'." | |||
| 1437 | (start 0)) | 1439 | (start 0)) |
| 1438 | (while (and (< start len) | 1440 | (while (and (< start len) |
| 1439 | (string-match regexp curstring start)) | 1441 | (string-match regexp curstring start)) |
| 1442 | (setq matches (1+ matches)) | ||
| 1440 | (add-text-properties | 1443 | (add-text-properties |
| 1441 | (match-beginning 0) (match-end 0) | 1444 | (match-beginning 0) (match-end 0) |
| 1442 | (append | 1445 | (append |
| @@ -1450,7 +1453,7 @@ See also `multi-occur'." | |||
| 1450 | ;; Generate the string to insert for this match | 1453 | ;; Generate the string to insert for this match |
| 1451 | (let* ((match-prefix | 1454 | (let* ((match-prefix |
| 1452 | ;; Using 7 digits aligns tabs properly. | 1455 | ;; Using 7 digits aligns tabs properly. |
| 1453 | (apply #'propertize (format "%7d:" lines) | 1456 | (apply #'propertize (format "%7d:" curr-line) |
| 1454 | (append | 1457 | (append |
| 1455 | (when prefix-face | 1458 | (when prefix-face |
| 1456 | `(font-lock-face ,prefix-face)) | 1459 | `(font-lock-face ,prefix-face)) |
| @@ -1490,7 +1493,7 @@ See also `multi-occur'." | |||
| 1490 | ;; The complex multi-line display style. | 1493 | ;; The complex multi-line display style. |
| 1491 | (setq ret (occur-context-lines | 1494 | (setq ret (occur-context-lines |
| 1492 | out-line nlines keep-props begpt endpt | 1495 | out-line nlines keep-props begpt endpt |
| 1493 | lines prev-lines prev-after-lines | 1496 | curr-line prev-line prev-after-lines |
| 1494 | prefix-face)) | 1497 | prefix-face)) |
| 1495 | ;; Set first elem of the returned list to `data', | 1498 | ;; Set first elem of the returned list to `data', |
| 1496 | ;; and the second elem to `prev-after-lines'. | 1499 | ;; and the second elem to `prev-after-lines'. |
| @@ -1503,28 +1506,34 @@ See also `multi-occur'." | |||
| 1503 | (if endpt | 1506 | (if endpt |
| 1504 | (progn | 1507 | (progn |
| 1505 | ;; Sum line numbers between first and last match lines. | 1508 | ;; Sum line numbers between first and last match lines. |
| 1506 | (setq lines (+ lines (count-lines begpt endpt) | 1509 | (setq curr-line (+ curr-line (count-lines begpt endpt) |
| 1507 | ;; Add 1 for empty last match line since | 1510 | ;; Add 1 for empty last match line since |
| 1508 | ;; count-lines returns 1 line less. | 1511 | ;; count-lines returns 1 line less. |
| 1509 | (if (and (bolp) (eolp)) 1 0))) | 1512 | (if (and (bolp) (eolp)) 1 0))) |
| 1510 | ;; On to the next match... | 1513 | ;; On to the next match... |
| 1511 | (forward-line 1)) | 1514 | (forward-line 1)) |
| 1512 | (goto-char (point-max))) | 1515 | (goto-char (point-max))) |
| 1513 | (setq prev-lines (1- lines))) | 1516 | (setq prev-line (1- curr-line))) |
| 1514 | ;; Flush remaining context after-lines. | 1517 | ;; Flush remaining context after-lines. |
| 1515 | (when prev-after-lines | 1518 | (when prev-after-lines |
| 1516 | (with-current-buffer out-buf | 1519 | (with-current-buffer out-buf |
| 1517 | (insert (apply #'concat (occur-engine-add-prefix | 1520 | (insert (apply #'concat (occur-engine-add-prefix |
| 1518 | prev-after-lines prefix-face))))))) | 1521 | prev-after-lines prefix-face))))))) |
| 1519 | (when (not (zerop matches)) ;; is the count zero? | 1522 | (when (not (zerop lines)) ;; is the count zero? |
| 1520 | (setq globalcount (+ globalcount matches)) | 1523 | (setq global-lines (+ global-lines lines) |
| 1524 | global-matches (+ global-matches matches)) | ||
| 1521 | (with-current-buffer out-buf | 1525 | (with-current-buffer out-buf |
| 1522 | (goto-char headerpt) | 1526 | (goto-char headerpt) |
| 1523 | (let ((beg (point)) | 1527 | (let ((beg (point)) |
| 1524 | end) | 1528 | end) |
| 1525 | (insert (propertize | 1529 | (insert (propertize |
| 1526 | (format "%d match%s%s in buffer: %s\n" | 1530 | (format "%d match%s%s%s in buffer: %s\n" |
| 1527 | matches (if (= matches 1) "" "es") | 1531 | matches (if (= matches 1) "" "es") |
| 1532 | ;; Don't display the same number of lines | ||
| 1533 | ;; and matches in case of 1 match per line. | ||
| 1534 | (if (= lines matches) | ||
| 1535 | "" (format " in %d line%s" | ||
| 1536 | lines (if (= lines 1) "" "s"))) | ||
| 1528 | ;; Don't display regexp for multi-buffer. | 1537 | ;; Don't display regexp for multi-buffer. |
| 1529 | (if (> (length buffers) 1) | 1538 | (if (> (length buffers) 1) |
| 1530 | "" (format " for \"%s\"" | 1539 | "" (format " for \"%s\"" |
| @@ -1539,12 +1548,17 @@ See also `multi-occur'." | |||
| 1539 | `(occur-title ,buf)))) | 1548 | `(occur-title ,buf)))) |
| 1540 | (goto-char (point-min))))))) | 1549 | (goto-char (point-min))))))) |
| 1541 | ;; Display total match count and regexp for multi-buffer. | 1550 | ;; Display total match count and regexp for multi-buffer. |
| 1542 | (when (and (not (zerop globalcount)) (> (length buffers) 1)) | 1551 | (when (and (not (zerop global-lines)) (> (length buffers) 1)) |
| 1543 | (goto-char (point-min)) | 1552 | (goto-char (point-min)) |
| 1544 | (let ((beg (point)) | 1553 | (let ((beg (point)) |
| 1545 | end) | 1554 | end) |
| 1546 | (insert (format "%d match%s total for \"%s\":\n" | 1555 | (insert (format "%d match%s%s total for \"%s\":\n" |
| 1547 | globalcount (if (= globalcount 1) "" "es") | 1556 | global-matches (if (= global-matches 1) "" "es") |
| 1557 | ;; Don't display the same number of lines | ||
| 1558 | ;; and matches in case of 1 match per line. | ||
| 1559 | (if (= global-lines global-matches) | ||
| 1560 | "" (format " in %d line%s" | ||
| 1561 | global-lines (if (= global-lines 1) "" "s"))) | ||
| 1548 | (query-replace-descr regexp))) | 1562 | (query-replace-descr regexp))) |
| 1549 | (setq end (point)) | 1563 | (setq end (point)) |
| 1550 | (add-text-properties beg end (when title-face | 1564 | (add-text-properties beg end (when title-face |
| @@ -1556,7 +1570,7 @@ See also `multi-occur'." | |||
| 1556 | ;; buffer. | 1570 | ;; buffer. |
| 1557 | (set-buffer-file-coding-system coding)) | 1571 | (set-buffer-file-coding-system coding)) |
| 1558 | ;; Return the number of matches | 1572 | ;; Return the number of matches |
| 1559 | globalcount))) | 1573 | global-matches))) |
| 1560 | 1574 | ||
| 1561 | (defun occur-engine-line (beg end &optional keep-props) | 1575 | (defun occur-engine-line (beg end &optional keep-props) |
| 1562 | (if (and keep-props (if (boundp 'jit-lock-mode) jit-lock-mode) | 1576 | (if (and keep-props (if (boundp 'jit-lock-mode) jit-lock-mode) |
| @@ -1599,13 +1613,13 @@ See also `multi-occur'." | |||
| 1599 | ;; Generate context display for occur. | 1613 | ;; Generate context display for occur. |
| 1600 | ;; OUT-LINE is the line where the match is. | 1614 | ;; OUT-LINE is the line where the match is. |
| 1601 | ;; NLINES and KEEP-PROPS are args to occur-engine. | 1615 | ;; NLINES and KEEP-PROPS are args to occur-engine. |
| 1602 | ;; LINES is line count of the current match, | 1616 | ;; CURR-LINE is line count of the current match, |
| 1603 | ;; PREV-LINES is line count of the previous match, | 1617 | ;; PREV-LINE is line count of the previous match, |
| 1604 | ;; PREV-AFTER-LINES is a list of after-context lines of the previous match. | 1618 | ;; PREV-AFTER-LINES is a list of after-context lines of the previous match. |
| 1605 | ;; Generate a list of lines, add prefixes to all but OUT-LINE, | 1619 | ;; Generate a list of lines, add prefixes to all but OUT-LINE, |
| 1606 | ;; then concatenate them all together. | 1620 | ;; then concatenate them all together. |
| 1607 | (defun occur-context-lines (out-line nlines keep-props begpt endpt | 1621 | (defun occur-context-lines (out-line nlines keep-props begpt endpt |
| 1608 | lines prev-lines prev-after-lines | 1622 | curr-line prev-line prev-after-lines |
| 1609 | &optional prefix-face) | 1623 | &optional prefix-face) |
| 1610 | ;; Find after- and before-context lines of the current match. | 1624 | ;; Find after- and before-context lines of the current match. |
| 1611 | (let ((before-lines | 1625 | (let ((before-lines |
| @@ -1621,22 +1635,22 @@ See also `multi-occur'." | |||
| 1621 | 1635 | ||
| 1622 | (when prev-after-lines | 1636 | (when prev-after-lines |
| 1623 | ;; Don't overlap prev after-lines with current before-lines. | 1637 | ;; Don't overlap prev after-lines with current before-lines. |
| 1624 | (if (>= (+ prev-lines (length prev-after-lines)) | 1638 | (if (>= (+ prev-line (length prev-after-lines)) |
| 1625 | (- lines (length before-lines))) | 1639 | (- curr-line (length before-lines))) |
| 1626 | (setq prev-after-lines | 1640 | (setq prev-after-lines |
| 1627 | (butlast prev-after-lines | 1641 | (butlast prev-after-lines |
| 1628 | (- (length prev-after-lines) | 1642 | (- (length prev-after-lines) |
| 1629 | (- lines prev-lines (length before-lines) 1)))) | 1643 | (- curr-line prev-line (length before-lines) 1)))) |
| 1630 | ;; Separate non-overlapping context lines with a dashed line. | 1644 | ;; Separate non-overlapping context lines with a dashed line. |
| 1631 | (setq separator "-------\n"))) | 1645 | (setq separator "-------\n"))) |
| 1632 | 1646 | ||
| 1633 | (when prev-lines | 1647 | (when prev-line |
| 1634 | ;; Don't overlap current before-lines with previous match line. | 1648 | ;; Don't overlap current before-lines with previous match line. |
| 1635 | (if (<= (- lines (length before-lines)) | 1649 | (if (<= (- curr-line (length before-lines)) |
| 1636 | prev-lines) | 1650 | prev-line) |
| 1637 | (setq before-lines | 1651 | (setq before-lines |
| 1638 | (nthcdr (- (length before-lines) | 1652 | (nthcdr (- (length before-lines) |
| 1639 | (- lines prev-lines 1)) | 1653 | (- curr-line prev-line 1)) |
| 1640 | before-lines)) | 1654 | before-lines)) |
| 1641 | ;; Separate non-overlapping before-context lines. | 1655 | ;; Separate non-overlapping before-context lines. |
| 1642 | (unless (> nlines 0) | 1656 | (unless (> nlines 0) |