aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2016-12-24 09:41:46 -0500
committerNoam Postavsky2016-12-24 09:45:14 -0500
commitda52e939aa26b0fc241151ba554bdca6ea1ef38c (patch)
treef461809195b66583585e790678b11ddb961200ce
parentcf5417f02887d681923c7d23326916889ae4049a (diff)
downloademacs-da52e939aa26b0fc241151ba554bdca6ea1ef38c.tar.gz
emacs-da52e939aa26b0fc241151ba554bdca6ea1ef38c.zip
Remove redundant `save-match-data' in whitespace.el
* lisp/whitespace.el (whitespace-cleanup, whitespace-cleanup-region): (whitespace-report-region): Remove redundant `save-match-data' calls.
-rw-r--r--lisp/whitespace.el297
1 files changed, 147 insertions, 150 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index a15308c0bc8..231675407d1 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1398,18 +1398,17 @@ documentation."
1398 ;; whole buffer 1398 ;; whole buffer
1399 (t 1399 (t
1400 (save-excursion 1400 (save-excursion
1401 (save-match-data ;FIXME: Why? 1401 ;; PROBLEM 1: empty lines at bob
1402 ;; PROBLEM 1: empty lines at bob 1402 ;; PROBLEM 2: empty lines at eob
1403 ;; PROBLEM 2: empty lines at eob 1403 ;; ACTION: remove all empty lines at bob and/or eob
1404 ;; ACTION: remove all empty lines at bob and/or eob 1404 (when (memq 'empty whitespace-style)
1405 (when (memq 'empty whitespace-style) 1405 (let (overwrite-mode) ; enforce no overwrite
1406 (let (overwrite-mode) ; enforce no overwrite 1406 (goto-char (point-min))
1407 (goto-char (point-min)) 1407 (when (looking-at whitespace-empty-at-bob-regexp)
1408 (when (looking-at whitespace-empty-at-bob-regexp) 1408 (delete-region (match-beginning 1) (match-end 1)))
1409 (delete-region (match-beginning 1) (match-end 1))) 1409 (when (re-search-forward
1410 (when (re-search-forward 1410 whitespace-empty-at-eob-regexp nil t)
1411 whitespace-empty-at-eob-regexp nil t) 1411 (delete-region (match-beginning 1) (match-end 1))))))
1412 (delete-region (match-beginning 1) (match-end 1)))))))
1413 ;; PROBLEM 3: `tab-width' or more SPACEs at bol 1412 ;; PROBLEM 3: `tab-width' or more SPACEs at bol
1414 ;; PROBLEM 4: SPACEs before TAB 1413 ;; PROBLEM 4: SPACEs before TAB
1415 ;; PROBLEM 5: SPACEs or TABs at eol 1414 ;; PROBLEM 5: SPACEs or TABs at eol
@@ -1476,76 +1475,75 @@ documentation."
1476 overwrite-mode ; enforce no overwrite 1475 overwrite-mode ; enforce no overwrite
1477 tmp) 1476 tmp)
1478 (save-excursion 1477 (save-excursion
1479 (save-match-data ;FIXME: Why? 1478 ;; PROBLEM 1: `tab-width' or more SPACEs at bol
1480 ;; PROBLEM 1: `tab-width' or more SPACEs at bol 1479 (cond
1481 (cond 1480 ;; ACTION: replace `tab-width' or more SPACEs at bol by TABs, if
1482 ;; ACTION: replace `tab-width' or more SPACEs at bol by TABs, if 1481 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs
1483 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs 1482 ;; by SPACEs.
1484 ;; by SPACEs. 1483 ((memq 'indentation whitespace-style)
1485 ((memq 'indentation whitespace-style) 1484 (let ((regexp (whitespace-indentation-regexp)))
1486 (let ((regexp (whitespace-indentation-regexp))) 1485 (goto-char rstart)
1487 (goto-char rstart) 1486 (while (re-search-forward regexp rend t)
1488 (while (re-search-forward regexp rend t) 1487 (setq tmp (current-indentation))
1489 (setq tmp (current-indentation)) 1488 (goto-char (match-beginning 0))
1490 (goto-char (match-beginning 0)) 1489 (delete-horizontal-space)
1491 (delete-horizontal-space) 1490 (unless (eolp)
1492 (unless (eolp) 1491 (indent-to tmp)))))
1493 (indent-to tmp))))) 1492 ;; ACTION: replace `tab-width' or more SPACEs at bol by TABs.
1494 ;; ACTION: replace `tab-width' or more SPACEs at bol by TABs. 1493 ((memq 'indentation::tab whitespace-style)
1495 ((memq 'indentation::tab whitespace-style) 1494 (whitespace-replace-action
1496 (whitespace-replace-action 1495 'tabify rstart rend
1497 'tabify rstart rend 1496 (whitespace-indentation-regexp 'tab) 0))
1498 (whitespace-indentation-regexp 'tab) 0)) 1497 ;; ACTION: replace TABs by SPACEs.
1499 ;; ACTION: replace TABs by SPACEs. 1498 ((memq 'indentation::space whitespace-style)
1500 ((memq 'indentation::space whitespace-style) 1499 (whitespace-replace-action
1501 (whitespace-replace-action 1500 'untabify rstart rend
1502 'untabify rstart rend 1501 (whitespace-indentation-regexp 'space) 0)))
1503 (whitespace-indentation-regexp 'space) 0))) 1502 ;; PROBLEM 3: SPACEs or TABs at eol
1504 ;; PROBLEM 3: SPACEs or TABs at eol 1503 ;; ACTION: remove all SPACEs or TABs at eol
1505 ;; ACTION: remove all SPACEs or TABs at eol 1504 (when (memq 'trailing whitespace-style)
1506 (when (memq 'trailing whitespace-style) 1505 (whitespace-replace-action
1507 (whitespace-replace-action 1506 'delete-region rstart rend
1508 'delete-region rstart rend 1507 whitespace-trailing-regexp 1))
1509 whitespace-trailing-regexp 1)) 1508 ;; PROBLEM 4: `tab-width' or more SPACEs after TAB
1510 ;; PROBLEM 4: `tab-width' or more SPACEs after TAB 1509 (cond
1511 (cond 1510 ;; ACTION: replace `tab-width' or more SPACEs by TABs, if
1512 ;; ACTION: replace `tab-width' or more SPACEs by TABs, if 1511 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs
1513 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs 1512 ;; by SPACEs.
1514 ;; by SPACEs. 1513 ((memq 'space-after-tab whitespace-style)
1515 ((memq 'space-after-tab whitespace-style) 1514 (whitespace-replace-action
1516 (whitespace-replace-action 1515 (if whitespace-indent-tabs-mode 'tabify 'untabify)
1517 (if whitespace-indent-tabs-mode 'tabify 'untabify) 1516 rstart rend (whitespace-space-after-tab-regexp) 1))
1518 rstart rend (whitespace-space-after-tab-regexp) 1)) 1517 ;; ACTION: replace `tab-width' or more SPACEs by TABs.
1519 ;; ACTION: replace `tab-width' or more SPACEs by TABs. 1518 ((memq 'space-after-tab::tab whitespace-style)
1520 ((memq 'space-after-tab::tab whitespace-style) 1519 (whitespace-replace-action
1521 (whitespace-replace-action 1520 'tabify rstart rend
1522 'tabify rstart rend 1521 (whitespace-space-after-tab-regexp 'tab) 1))
1523 (whitespace-space-after-tab-regexp 'tab) 1)) 1522 ;; ACTION: replace TABs by SPACEs.
1524 ;; ACTION: replace TABs by SPACEs. 1523 ((memq 'space-after-tab::space whitespace-style)
1525 ((memq 'space-after-tab::space whitespace-style) 1524 (whitespace-replace-action
1526 (whitespace-replace-action 1525 'untabify rstart rend
1527 'untabify rstart rend 1526 (whitespace-space-after-tab-regexp 'space) 1)))
1528 (whitespace-space-after-tab-regexp 'space) 1))) 1527 ;; PROBLEM 2: SPACEs before TAB
1529 ;; PROBLEM 2: SPACEs before TAB 1528 (cond
1530 (cond 1529 ;; ACTION: replace SPACEs before TAB by TABs, if
1531 ;; ACTION: replace SPACEs before TAB by TABs, if 1530 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs
1532 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs 1531 ;; by SPACEs.
1533 ;; by SPACEs. 1532 ((memq 'space-before-tab whitespace-style)
1534 ((memq 'space-before-tab whitespace-style) 1533 (whitespace-replace-action
1535 (whitespace-replace-action 1534 (if whitespace-indent-tabs-mode 'tabify 'untabify)
1536 (if whitespace-indent-tabs-mode 'tabify 'untabify) 1535 rstart rend whitespace-space-before-tab-regexp
1537 rstart rend whitespace-space-before-tab-regexp 1536 (if whitespace-indent-tabs-mode 0 2)))
1538 (if whitespace-indent-tabs-mode 0 2))) 1537 ;; ACTION: replace SPACEs before TAB by TABs.
1539 ;; ACTION: replace SPACEs before TAB by TABs. 1538 ((memq 'space-before-tab::tab whitespace-style)
1540 ((memq 'space-before-tab::tab whitespace-style) 1539 (whitespace-replace-action
1541 (whitespace-replace-action 1540 'tabify rstart rend
1542 'tabify rstart rend 1541 whitespace-space-before-tab-regexp 0))
1543 whitespace-space-before-tab-regexp 0)) 1542 ;; ACTION: replace TABs by SPACEs.
1544 ;; ACTION: replace TABs by SPACEs. 1543 ((memq 'space-before-tab::space whitespace-style)
1545 ((memq 'space-before-tab::space whitespace-style) 1544 (whitespace-replace-action
1546 (whitespace-replace-action 1545 'untabify rstart rend
1547 'untabify rstart rend 1546 whitespace-space-before-tab-regexp 2))))
1548 whitespace-space-before-tab-regexp 2)))))
1549 (set-marker rend nil)))) ; point marker to nowhere 1547 (set-marker rend nil)))) ; point marker to nowhere
1550 1548
1551 1549
@@ -1710,74 +1708,73 @@ cleaning up these problems."
1710 (interactive "r") 1708 (interactive "r")
1711 (setq force (or current-prefix-arg force)) 1709 (setq force (or current-prefix-arg force))
1712 (save-excursion 1710 (save-excursion
1713 (save-match-data ;FIXME: Why? 1711 (let* ((has-bogus nil)
1714 (let* ((has-bogus nil) 1712 (rstart (min start end))
1715 (rstart (min start end)) 1713 (rend (max start end))
1716 (rend (max start end)) 1714 ;; Fall back to whitespace-style so we can run before
1717 ;; Fall back to whitespace-style so we can run before 1715 ;; before the mode is active.
1718 ;; before the mode is active. 1716 (style (copy-sequence
1719 (style (copy-sequence 1717 (or whitespace-active-style whitespace-style)))
1720 (or whitespace-active-style whitespace-style))) 1718 (bogus-list
1721 (bogus-list 1719 (mapcar
1722 (mapcar 1720 #'(lambda (option)
1723 #'(lambda (option) 1721 (when force
1724 (when force 1722 (add-to-list 'style (car option)))
1725 (add-to-list 'style (car option))) 1723 (goto-char rstart)
1726 (goto-char rstart) 1724 (let ((regexp
1727 (let ((regexp 1725 (cond
1728 (cond 1726 ((eq (car option) 'indentation)
1729 ((eq (car option) 'indentation) 1727 (whitespace-indentation-regexp))
1730 (whitespace-indentation-regexp)) 1728 ((eq (car option) 'indentation::tab)
1731 ((eq (car option) 'indentation::tab) 1729 (whitespace-indentation-regexp 'tab))
1732 (whitespace-indentation-regexp 'tab)) 1730 ((eq (car option) 'indentation::space)
1733 ((eq (car option) 'indentation::space) 1731 (whitespace-indentation-regexp 'space))
1734 (whitespace-indentation-regexp 'space)) 1732 ((eq (car option) 'space-after-tab)
1735 ((eq (car option) 'space-after-tab) 1733 (whitespace-space-after-tab-regexp))
1736 (whitespace-space-after-tab-regexp)) 1734 ((eq (car option) 'space-after-tab::tab)
1737 ((eq (car option) 'space-after-tab::tab) 1735 (whitespace-space-after-tab-regexp 'tab))
1738 (whitespace-space-after-tab-regexp 'tab)) 1736 ((eq (car option) 'space-after-tab::space)
1739 ((eq (car option) 'space-after-tab::space) 1737 (whitespace-space-after-tab-regexp 'space))
1740 (whitespace-space-after-tab-regexp 'space)) 1738 (t
1741 (t 1739 (cdr option)))))
1742 (cdr option))))) 1740 (when (re-search-forward regexp rend t)
1743 (when (re-search-forward regexp rend t) 1741 (unless has-bogus
1744 (unless has-bogus 1742 (setq has-bogus (memq (car option) style)))
1745 (setq has-bogus (memq (car option) style))) 1743 t)))
1746 t))) 1744 whitespace-report-list)))
1747 whitespace-report-list))) 1745 (when (pcase report-if-bogus (`nil t) (`never nil) (_ has-bogus))
1748 (when (pcase report-if-bogus (`nil t) (`never nil) (_ has-bogus)) 1746 (whitespace-kill-buffer whitespace-report-buffer-name)
1749 (whitespace-kill-buffer whitespace-report-buffer-name) 1747 ;; `whitespace-indent-tabs-mode' is local to current buffer
1750 ;; `whitespace-indent-tabs-mode' is local to current buffer 1748 ;; `whitespace-tab-width' is local to current buffer
1751 ;; `whitespace-tab-width' is local to current buffer 1749 (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode)
1752 (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode) 1750 (ws-tab-width whitespace-tab-width))
1753 (ws-tab-width whitespace-tab-width)) 1751 (with-current-buffer (get-buffer-create
1754 (with-current-buffer (get-buffer-create 1752 whitespace-report-buffer-name)
1755 whitespace-report-buffer-name) 1753 (erase-buffer)
1756 (erase-buffer) 1754 (insert (if ws-indent-tabs-mode
1757 (insert (if ws-indent-tabs-mode 1755 (car whitespace-report-text)
1758 (car whitespace-report-text) 1756 (cdr whitespace-report-text)))
1759 (cdr whitespace-report-text))) 1757 (goto-char (point-min))
1760 (goto-char (point-min)) 1758 (forward-line 3)
1761 (forward-line 3) 1759 (dolist (option whitespace-report-list)
1762 (dolist (option whitespace-report-list) 1760 (forward-line 1)
1763 (forward-line 1) 1761 (whitespace-mark-x
1764 (whitespace-mark-x 1762 27 (memq (car option) style))
1765 27 (memq (car option) style)) 1763 (whitespace-mark-x 7 (car bogus-list))
1766 (whitespace-mark-x 7 (car bogus-list)) 1764 (setq bogus-list (cdr bogus-list)))
1767 (setq bogus-list (cdr bogus-list))) 1765 (forward-line 1)
1768 (forward-line 1) 1766 (whitespace-insert-value ws-indent-tabs-mode)
1769 (whitespace-insert-value ws-indent-tabs-mode) 1767 (whitespace-insert-value ws-tab-width)
1770 (whitespace-insert-value ws-tab-width) 1768 (when has-bogus
1771 (when has-bogus 1769 (goto-char (point-max))
1772 (goto-char (point-max)) 1770 (insert (substitute-command-keys
1773 (insert (substitute-command-keys 1771 " Type `\\[whitespace-cleanup]'")
1774 " Type `\\[whitespace-cleanup]'") 1772 " to cleanup the buffer.\n\n"
1775 " to cleanup the buffer.\n\n" 1773 (substitute-command-keys
1776 (substitute-command-keys 1774 " Type `\\[whitespace-cleanup-region]'")
1777 " Type `\\[whitespace-cleanup-region]'") 1775 " to cleanup a region.\n\n"))
1778 " to cleanup a region.\n\n")) 1776 (whitespace-display-window (current-buffer)))))
1779 (whitespace-display-window (current-buffer))))) 1777 has-bogus)))
1780 has-bogus))))
1781 1778
1782 1779
1783;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1780;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;