diff options
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/whitespace.el | 208 |
2 files changed, 123 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 055e6b473ae..3e75e2a720a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -40,6 +40,15 @@ | |||
| 40 | in a highlighted region: indent each line in region according to | 40 | in a highlighted region: indent each line in region according to |
| 41 | mode. Supply this so it works in XEmacs and older Emacs. | 41 | mode. Supply this so it works in XEmacs and older Emacs. |
| 42 | 42 | ||
| 43 | 2008-09-05 Vinicius Jose Latorre <viniciusjl@ig.com.br> | ||
| 44 | |||
| 45 | * whitespace.el: Fix auto-cleanup on kill prevents killing read-only | ||
| 46 | buffers (bug#360). New version 11.2.1. | ||
| 47 | (whitespace-action): New value `warn-read-only' to give a warning when | ||
| 48 | buffer is read-only and whitespace action is cleanup or auto-cleanup. | ||
| 49 | (whitespace-cleanup, whitespace-cleanup-region): Code fix. | ||
| 50 | (whitespace-warn-read-only): New fun. | ||
| 51 | |||
| 43 | 2008-09-05 Chong Yidong <cyd@stupidchicken.com> | 52 | 2008-09-05 Chong Yidong <cyd@stupidchicken.com> |
| 44 | 53 | ||
| 45 | * international/quail.el: Require help-mode. | 54 | * international/quail.el: Require help-mode. |
diff --git a/lisp/whitespace.el b/lisp/whitespace.el index 41f0af600dd..59da0469be3 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> | 6 | ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
| 7 | ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> | 7 | ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
| 8 | ;; Keywords: data, wp | 8 | ;; Keywords: data, wp |
| 9 | ;; Version: 11.2 | 9 | ;; Version: 11.2.1 |
| 10 | ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre | 10 | ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre |
| 11 | 11 | ||
| 12 | ;; This file is part of GNU Emacs. | 12 | ;; This file is part of GNU Emacs. |
| @@ -989,6 +989,10 @@ It's a list containing some or all of the following values: | |||
| 989 | abort-on-bogus abort if there is any bogus whitespace and the | 989 | abort-on-bogus abort if there is any bogus whitespace and the |
| 990 | buffer is written or killed. | 990 | buffer is written or killed. |
| 991 | 991 | ||
| 992 | warn-read-only give a warning if `cleanup' or `auto-cleanup' | ||
| 993 | is included in `whitespace-action' and the | ||
| 994 | buffer is read-only. | ||
| 995 | |||
| 992 | Any other value is treated as nil." | 996 | Any other value is treated as nil." |
| 993 | :type '(choice :tag "Actions" | 997 | :type '(choice :tag "Actions" |
| 994 | (const :tag "None" nil) | 998 | (const :tag "None" nil) |
| @@ -997,7 +1001,8 @@ Any other value is treated as nil." | |||
| 997 | (const :tag "Cleanup When On" cleanup) | 1001 | (const :tag "Cleanup When On" cleanup) |
| 998 | (const :tag "Report On Bogus" report-on-bogus) | 1002 | (const :tag "Report On Bogus" report-on-bogus) |
| 999 | (const :tag "Auto Cleanup" auto-cleanup) | 1003 | (const :tag "Auto Cleanup" auto-cleanup) |
| 1000 | (const :tag "Abort On Bogus" abort-on-bogus)))) | 1004 | (const :tag "Abort On Bogus" abort-on-bogus) |
| 1005 | (const :tag "Warn Read-Only" warn-read-only)))) | ||
| 1001 | :group 'whitespace) | 1006 | :group 'whitespace) |
| 1002 | 1007 | ||
| 1003 | 1008 | ||
| @@ -1428,18 +1433,23 @@ The problems cleaned up are: | |||
| 1428 | 1433 | ||
| 1429 | See `whitespace-style', `indent-tabs-mode' and `tab-width' for | 1434 | See `whitespace-style', `indent-tabs-mode' and `tab-width' for |
| 1430 | documentation." | 1435 | documentation." |
| 1431 | (interactive "@*") | 1436 | (interactive "@") |
| 1432 | (if (and (or transient-mark-mode | 1437 | (cond |
| 1433 | current-prefix-arg) | 1438 | ;; read-only buffer |
| 1434 | mark-active) | 1439 | (buffer-read-only |
| 1435 | ;; region active | 1440 | (whitespace-warn-read-only "cleanup")) |
| 1436 | ;; PROBLEMs 1 and 2 are not handled in region | 1441 | ;; region active |
| 1437 | ;; PROBLEM 3: 8 or more SPACEs at bol | 1442 | ((and (or transient-mark-mode |
| 1438 | ;; PROBLEM 4: SPACEs before TAB | 1443 | current-prefix-arg) |
| 1439 | ;; PROBLEM 5: SPACEs or TABs at eol | 1444 | mark-active) |
| 1440 | ;; PROBLEM 6: 8 or more SPACEs after TAB | 1445 | ;; PROBLEMs 1 and 2 are not handled in region |
| 1441 | (whitespace-cleanup-region (region-beginning) (region-end)) | 1446 | ;; PROBLEM 3: 8 or more SPACEs at bol |
| 1442 | ;; whole buffer | 1447 | ;; PROBLEM 4: SPACEs before TAB |
| 1448 | ;; PROBLEM 5: SPACEs or TABs at eol | ||
| 1449 | ;; PROBLEM 6: 8 or more SPACEs after TAB | ||
| 1450 | (whitespace-cleanup-region (region-beginning) (region-end))) | ||
| 1451 | ;; whole buffer | ||
| 1452 | (t | ||
| 1443 | (save-excursion | 1453 | (save-excursion |
| 1444 | (save-match-data | 1454 | (save-match-data |
| 1445 | ;; PROBLEM 1: empty lines at bob | 1455 | ;; PROBLEM 1: empty lines at bob |
| @@ -1458,7 +1468,7 @@ documentation." | |||
| 1458 | ;; PROBLEM 4: SPACEs before TAB | 1468 | ;; PROBLEM 4: SPACEs before TAB |
| 1459 | ;; PROBLEM 5: SPACEs or TABs at eol | 1469 | ;; PROBLEM 5: SPACEs or TABs at eol |
| 1460 | ;; PROBLEM 6: 8 or more SPACEs after TAB | 1470 | ;; PROBLEM 6: 8 or more SPACEs after TAB |
| 1461 | (whitespace-cleanup-region (point-min) (point-max)))) | 1471 | (whitespace-cleanup-region (point-min) (point-max))))) |
| 1462 | 1472 | ||
| 1463 | 1473 | ||
| 1464 | ;;;###autoload | 1474 | ;;;###autoload |
| @@ -1501,85 +1511,89 @@ The problems cleaned up are: | |||
| 1501 | 1511 | ||
| 1502 | See `whitespace-style', `indent-tabs-mode' and `tab-width' for | 1512 | See `whitespace-style', `indent-tabs-mode' and `tab-width' for |
| 1503 | documentation." | 1513 | documentation." |
| 1504 | (interactive "@*r") | 1514 | (interactive "@r") |
| 1505 | (let ((rstart (min start end)) | 1515 | (if buffer-read-only |
| 1506 | (rend (copy-marker (max start end))) | 1516 | ;; read-only buffer |
| 1507 | (indent-tabs-mode whitespace-indent-tabs-mode) | 1517 | (whitespace-warn-read-only "cleanup region") |
| 1508 | (tab-width whitespace-tab-width) | 1518 | ;; non-read-only buffer |
| 1509 | overwrite-mode ; enforce no overwrite | 1519 | (let ((rstart (min start end)) |
| 1510 | tmp) | 1520 | (rend (copy-marker (max start end))) |
| 1511 | (save-excursion | 1521 | (indent-tabs-mode whitespace-indent-tabs-mode) |
| 1512 | (save-match-data | 1522 | (tab-width whitespace-tab-width) |
| 1513 | ;; PROBLEM 1: 8 or more SPACEs at bol | 1523 | overwrite-mode ; enforce no overwrite |
| 1514 | (cond | 1524 | tmp) |
| 1515 | ;; ACTION: replace 8 or more SPACEs at bol by TABs, if | 1525 | (save-excursion |
| 1516 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by | 1526 | (save-match-data |
| 1517 | ;; SPACEs. | 1527 | ;; PROBLEM 1: 8 or more SPACEs at bol |
| 1518 | ((memq 'indentation whitespace-style) | 1528 | (cond |
| 1519 | (let ((regexp (whitespace-indentation-regexp))) | 1529 | ;; ACTION: replace 8 or more SPACEs at bol by TABs, if |
| 1520 | (goto-char rstart) | 1530 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs |
| 1521 | (while (re-search-forward regexp rend t) | 1531 | ;; by SPACEs. |
| 1522 | (setq tmp (current-indentation)) | 1532 | ((memq 'indentation whitespace-style) |
| 1523 | (goto-char (match-beginning 0)) | 1533 | (let ((regexp (whitespace-indentation-regexp))) |
| 1524 | (delete-horizontal-space) | 1534 | (goto-char rstart) |
| 1525 | (unless (eolp) | 1535 | (while (re-search-forward regexp rend t) |
| 1526 | (indent-to tmp))))) | 1536 | (setq tmp (current-indentation)) |
| 1527 | ;; ACTION: replace 8 or more SPACEs at bol by TABs. | 1537 | (goto-char (match-beginning 0)) |
| 1528 | ((memq 'indentation::tab whitespace-style) | 1538 | (delete-horizontal-space) |
| 1529 | (whitespace-replace-action | 1539 | (unless (eolp) |
| 1530 | 'tabify rstart rend | 1540 | (indent-to tmp))))) |
| 1531 | (whitespace-indentation-regexp 'tab) 0)) | 1541 | ;; ACTION: replace 8 or more SPACEs at bol by TABs. |
| 1532 | ;; ACTION: replace TABs by SPACEs. | 1542 | ((memq 'indentation::tab whitespace-style) |
| 1533 | ((memq 'indentation::space whitespace-style) | 1543 | (whitespace-replace-action |
| 1534 | (whitespace-replace-action | 1544 | 'tabify rstart rend |
| 1535 | 'untabify rstart rend | 1545 | (whitespace-indentation-regexp 'tab) 0)) |
| 1536 | (whitespace-indentation-regexp 'space) 0))) | 1546 | ;; ACTION: replace TABs by SPACEs. |
| 1537 | ;; PROBLEM 3: SPACEs or TABs at eol | 1547 | ((memq 'indentation::space whitespace-style) |
| 1538 | ;; ACTION: remove all SPACEs or TABs at eol | 1548 | (whitespace-replace-action |
| 1539 | (when (memq 'trailing whitespace-style) | 1549 | 'untabify rstart rend |
| 1540 | (whitespace-replace-action | 1550 | (whitespace-indentation-regexp 'space) 0))) |
| 1541 | 'delete-region rstart rend | 1551 | ;; PROBLEM 3: SPACEs or TABs at eol |
| 1542 | whitespace-trailing-regexp 1)) | 1552 | ;; ACTION: remove all SPACEs or TABs at eol |
| 1543 | ;; PROBLEM 4: 8 or more SPACEs after TAB | 1553 | (when (memq 'trailing whitespace-style) |
| 1544 | (cond | 1554 | (whitespace-replace-action |
| 1545 | ;; ACTION: replace 8 or more SPACEs by TABs, if | 1555 | 'delete-region rstart rend |
| 1546 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by | 1556 | whitespace-trailing-regexp 1)) |
| 1547 | ;; SPACEs. | 1557 | ;; PROBLEM 4: 8 or more SPACEs after TAB |
| 1548 | ((memq 'space-after-tab whitespace-style) | 1558 | (cond |
| 1549 | (whitespace-replace-action | 1559 | ;; ACTION: replace 8 or more SPACEs by TABs, if |
| 1550 | (if whitespace-indent-tabs-mode 'tabify 'untabify) | 1560 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs |
| 1551 | rstart rend (whitespace-space-after-tab-regexp) 1)) | 1561 | ;; by SPACEs. |
| 1552 | ;; ACTION: replace 8 or more SPACEs by TABs. | 1562 | ((memq 'space-after-tab whitespace-style) |
| 1553 | ((memq 'space-after-tab::tab whitespace-style) | 1563 | (whitespace-replace-action |
| 1554 | (whitespace-replace-action | 1564 | (if whitespace-indent-tabs-mode 'tabify 'untabify) |
| 1555 | 'tabify rstart rend | 1565 | rstart rend (whitespace-space-after-tab-regexp) 1)) |
| 1556 | (whitespace-space-after-tab-regexp 'tab) 1)) | 1566 | ;; ACTION: replace 8 or more SPACEs by TABs. |
| 1557 | ;; ACTION: replace TABs by SPACEs. | 1567 | ((memq 'space-after-tab::tab whitespace-style) |
| 1558 | ((memq 'space-after-tab::space whitespace-style) | 1568 | (whitespace-replace-action |
| 1559 | (whitespace-replace-action | 1569 | 'tabify rstart rend |
| 1560 | 'untabify rstart rend | 1570 | (whitespace-space-after-tab-regexp 'tab) 1)) |
| 1561 | (whitespace-space-after-tab-regexp 'space) 1))) | 1571 | ;; ACTION: replace TABs by SPACEs. |
| 1562 | ;; PROBLEM 2: SPACEs before TAB | 1572 | ((memq 'space-after-tab::space whitespace-style) |
| 1563 | (cond | 1573 | (whitespace-replace-action |
| 1564 | ;; ACTION: replace SPACEs before TAB by TABs, if | 1574 | 'untabify rstart rend |
| 1565 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by | 1575 | (whitespace-space-after-tab-regexp 'space) 1))) |
| 1566 | ;; SPACEs. | 1576 | ;; PROBLEM 2: SPACEs before TAB |
| 1567 | ((memq 'space-before-tab whitespace-style) | 1577 | (cond |
| 1568 | (whitespace-replace-action | 1578 | ;; ACTION: replace SPACEs before TAB by TABs, if |
| 1569 | (if whitespace-indent-tabs-mode 'tabify 'untabify) | 1579 | ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs |
| 1570 | rstart rend whitespace-space-before-tab-regexp | 1580 | ;; by SPACEs. |
| 1571 | (if whitespace-indent-tabs-mode 1 2))) | 1581 | ((memq 'space-before-tab whitespace-style) |
| 1572 | ;; ACTION: replace SPACEs before TAB by TABs. | 1582 | (whitespace-replace-action |
| 1573 | ((memq 'space-before-tab::tab whitespace-style) | 1583 | (if whitespace-indent-tabs-mode 'tabify 'untabify) |
| 1574 | (whitespace-replace-action | 1584 | rstart rend whitespace-space-before-tab-regexp |
| 1575 | 'tabify rstart rend | 1585 | (if whitespace-indent-tabs-mode 1 2))) |
| 1576 | whitespace-space-before-tab-regexp 1)) | 1586 | ;; ACTION: replace SPACEs before TAB by TABs. |
| 1577 | ;; ACTION: replace TABs by SPACEs. | 1587 | ((memq 'space-before-tab::tab whitespace-style) |
| 1578 | ((memq 'space-before-tab::space whitespace-style) | 1588 | (whitespace-replace-action |
| 1579 | (whitespace-replace-action | 1589 | 'tabify rstart rend |
| 1580 | 'untabify rstart rend | 1590 | whitespace-space-before-tab-regexp 1)) |
| 1581 | whitespace-space-before-tab-regexp 2))))) | 1591 | ;; ACTION: replace TABs by SPACEs. |
| 1582 | (set-marker rend nil))) ; point marker to nowhere | 1592 | ((memq 'space-before-tab::space whitespace-style) |
| 1593 | (whitespace-replace-action | ||
| 1594 | 'untabify rstart rend | ||
| 1595 | whitespace-space-before-tab-regexp 2))))) | ||
| 1596 | (set-marker rend nil)))) ; point marker to nowhere | ||
| 1583 | 1597 | ||
| 1584 | 1598 | ||
| 1585 | (defun whitespace-replace-action (action rstart rend regexp index) | 1599 | (defun whitespace-replace-action (action rstart rend regexp index) |
| @@ -2404,6 +2418,12 @@ Return t when the action should be aborted." | |||
| 2404 | (t | 2418 | (t |
| 2405 | nil))) | 2419 | nil))) |
| 2406 | 2420 | ||
| 2421 | |||
| 2422 | (defun whitespace-warn-read-only (msg) | ||
| 2423 | "Warn if buffer is read-only." | ||
| 2424 | (when (memq 'warn-read-only whitespace-action) | ||
| 2425 | (message "Can't %s: %s is read-only" msg (buffer-name)))) | ||
| 2426 | |||
| 2407 | 2427 | ||
| 2408 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2428 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2409 | 2429 | ||