aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Verona2013-08-21 00:26:48 +0200
committerJoakim Verona2013-08-21 00:26:48 +0200
commitbbe1d42d34353bae5379bcf462fba1b67a328e93 (patch)
tree1676e2c34e25aba6ee4574ce4687a01db248eed7
parentb657a571a916b158914f2a1e8bd8a5f1e7fa2872 (diff)
parentdbb0d3504311881c0a944855b54e3ef1fb301651 (diff)
downloademacs-bbe1d42d34353bae5379bcf462fba1b67a328e93.tar.gz
emacs-bbe1d42d34353bae5379bcf462fba1b67a328e93.zip
merge from trunk
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/align.el409
2 files changed, 203 insertions, 211 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d8c4797434e..8e33b30f697 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12013-08-20 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * align.el: Use lexical-binding.
4 (align-region): Simplify accordingly.
5
12013-08-20 Michael Albinus <michael.albinus@gmx.de> 62013-08-20 Michael Albinus <michael.albinus@gmx.de>
2 7
3 * minibuffer.el (completion--sifn-requote): Bind `non-essential'. 8 * minibuffer.el (completion--sifn-requote): Bind `non-essential'.
diff --git a/lisp/align.el b/lisp/align.el
index 3d2ca192245..6f55ac9faf1 100644
--- a/lisp/align.el
+++ b/lisp/align.el
@@ -1,4 +1,4 @@
1;;; align.el --- align text to a specific column, by regexp 1;;; align.el --- align text to a specific column, by regexp -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1999-2013 Free Software Foundation, Inc. 3;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
4 4
@@ -1325,7 +1325,7 @@ aligner would have dealt with are."
1325 (unless (or (and modes (not (memq major-mode 1325 (unless (or (and modes (not (memq major-mode
1326 (eval (cdr modes))))) 1326 (eval (cdr modes)))))
1327 (and run-if (not (funcall (cdr run-if))))) 1327 (and run-if (not (funcall (cdr run-if)))))
1328 (let* ((current-case-fold case-fold-search) 1328 (let* ((case-fold-search case-fold-search)
1329 (case-fold (assq 'case-fold rule)) 1329 (case-fold (assq 'case-fold rule))
1330 (regexp (cdr (assq 'regexp rule))) 1330 (regexp (cdr (assq 'regexp rule)))
1331 (regfunc (and (functionp regexp) regexp)) 1331 (regfunc (and (functionp regexp) regexp))
@@ -1403,215 +1403,202 @@ aligner would have dealt with are."
1403 ;; reports back that the region is ok, then align it. 1403 ;; reports back that the region is ok, then align it.
1404 (when (or (not func) 1404 (when (or (not func)
1405 (funcall func beg end rule)) 1405 (funcall func beg end rule))
1406 (unwind-protect 1406 (let (rule-beg exclude-areas)
1407 (let (rule-beg exclude-areas) 1407 ;; determine first of all where the exclusions
1408 ;; determine first of all where the exclusions 1408 ;; lie in this region
1409 ;; lie in this region 1409 (when exclude-rules
1410 (when exclude-rules 1410 (align-region
1411 ;; guard against a problem with recursion and 1411 beg end 'entire
1412 ;; dynamic binding vs. lexical binding, since 1412 exclude-rules nil
1413 ;; the call to `align-region' below will 1413 (lambda (b e mode)
1414 ;; re-enter this function, and rebind 1414 (or (and mode (listp mode))
1415 ;; `exclude-areas' 1415 (setq exclude-areas
1416 (set (setq exclude-areas 1416 (cons (cons b e)
1417 (make-symbol "align-exclude-areas")) 1417 exclude-areas)))))
1418 nil) 1418 (setq exclude-areas
1419 (align-region 1419 (nreverse
1420 beg end 'entire 1420 (sort exclude-areas #'car-less-than-car))))
1421 exclude-rules nil 1421
1422 `(lambda (b e mode) 1422 ;; set `case-fold-search' according to the
1423 (or (and mode (listp mode)) 1423 ;; (optional) `case-fold' property
1424 (set (quote ,exclude-areas) 1424 (and case-fold
1425 (cons (cons b e) 1425 (setq case-fold-search (cdr case-fold)))
1426 ,exclude-areas))))) 1426
1427 (setq exclude-areas 1427 ;; while we can find the rule in the alignment
1428 (sort (symbol-value exclude-areas) 1428 ;; region..
1429 (function 1429 (while (and (< (point) end-mark)
1430 (lambda (l r) 1430 (setq search-start (point))
1431 (>= (car l) (car r))))))) 1431 (if regfunc
1432 1432 (funcall regfunc end-mark nil)
1433 ;; set `case-fold-search' according to the 1433 (re-search-forward regexp
1434 ;; (optional) `case-fold' property 1434 end-mark t)))
1435 (and case-fold 1435
1436 (setq case-fold-search (cdr case-fold))) 1436 ;; give the user some indication of where we
1437 1437 ;; are, if it's a very large region being
1438 ;; while we can find the rule in the alignment 1438 ;; aligned
1439 ;; region.. 1439 (if report
1440 (while (and (< (point) end-mark) 1440 (let ((symbol (car rule)))
1441 (setq search-start (point)) 1441 (if (and symbol (symbolp symbol))
1442 (if regfunc 1442 (message
1443 (funcall regfunc end-mark nil) 1443 "Aligning `%s' (rule %d of %d) %d%%..."
1444 (re-search-forward regexp 1444 (symbol-name symbol) rule-index rule-count
1445 end-mark t))) 1445 (/ (* (- (point) real-beg) 100)
1446 1446 (- end-mark real-beg)))
1447 ;; give the user some indication of where we 1447 (message
1448 ;; are, if it's a very large region being 1448 "Aligning %d%%..."
1449 ;; aligned 1449 (/ (* (- (point) real-beg) 100)
1450 (if report 1450 (- end-mark real-beg))))))
1451 (let ((symbol (car rule))) 1451
1452 (if (and symbol (symbolp symbol)) 1452 ;; if the search ended us on the beginning of
1453 (message 1453 ;; the next line, move back to the end of the
1454 "Aligning `%s' (rule %d of %d) %d%%..." 1454 ;; previous line.
1455 (symbol-name symbol) rule-index rule-count 1455 (if (and (bolp) (> (point) search-start))
1456 (/ (* (- (point) real-beg) 100) 1456 (forward-char -1))
1457 (- end-mark real-beg))) 1457
1458 (message 1458 ;; lookup the `group' attribute the first time
1459 "Aligning %d%%..." 1459 ;; that we need it
1460 (/ (* (- (point) real-beg) 100) 1460 (unless group-c
1461 (- end-mark real-beg)))))) 1461 (setq groups (or (cdr (assq 'group rule)) 1))
1462 1462 (unless (listp groups)
1463 ;; if the search ended us on the beginning of 1463 (setq groups (list groups)))
1464 ;; the next line, move back to the end of the 1464 (setq first (car groups)))
1465 ;; previous line. 1465
1466 (if (and (bolp) (> (point) search-start)) 1466 (unless spacing-c
1467 (forward-char -1)) 1467 (setq spacing (cdr (assq 'spacing rule))
1468 1468 spacing-c t))
1469 ;; lookup the `group' attribute the first time 1469
1470 ;; that we need it 1470 (unless tab-stop-c
1471 (unless group-c 1471 (setq tab-stop
1472 (setq groups (or (cdr (assq 'group rule)) 1)) 1472 (let ((rule-ts (assq 'tab-stop rule)))
1473 (unless (listp groups) 1473 (cond (rule-ts
1474 (setq groups (list groups))) 1474 (cdr rule-ts))
1475 (setq first (car groups))) 1475 ((symbolp align-to-tab-stop)
1476 1476 (symbol-value align-to-tab-stop))
1477 (unless spacing-c 1477 (t
1478 (setq spacing (cdr (assq 'spacing rule)) 1478 align-to-tab-stop)))
1479 spacing-c t)) 1479 tab-stop-c t))
1480 1480
1481 (unless tab-stop-c 1481 ;; test whether we have found a match on the same
1482 (setq tab-stop 1482 ;; line as a previous match
1483 (let ((rule-ts (assq 'tab-stop rule))) 1483 (when (> (point) eol)
1484 (cond (rule-ts 1484 (setq same nil)
1485 (cdr rule-ts)) 1485 (align--set-marker eol (line-end-position)))
1486 ((symbolp align-to-tab-stop) 1486
1487 (symbol-value align-to-tab-stop)) 1487 ;; lookup the `repeat' attribute the first time
1488 (t 1488 (or repeat-c
1489 align-to-tab-stop))) 1489 (setq repeat (cdr (assq 'repeat rule))
1490 tab-stop-c t)) 1490 repeat-c t))
1491 1491
1492 ;; test whether we have found a match on the same 1492 ;; lookup the `valid' attribute the first time
1493 ;; line as a previous match 1493 (or valid-c
1494 (when (> (point) eol) 1494 (setq valid (assq 'valid rule)
1495 (setq same nil) 1495 valid-c t))
1496 (align--set-marker eol (line-end-position))) 1496
1497 1497 ;; remember the beginning position of this rule
1498 ;; lookup the `repeat' attribute the first time 1498 ;; match, and save the match-data, since either
1499 (or repeat-c 1499 ;; the `valid' form, or the code that searches for
1500 (setq repeat (cdr (assq 'repeat rule)) 1500 ;; section separation, might alter it
1501 repeat-c t)) 1501 (setq rule-beg (match-beginning first)
1502 1502 save-match-data (match-data))
1503 ;; lookup the `valid' attribute the first time 1503
1504 (or valid-c 1504 (or rule-beg
1505 (setq valid (assq 'valid rule) 1505 (error "No match for subexpression %s" first))
1506 valid-c t)) 1506
1507 1507 ;; unless the `valid' attribute is set, and tells
1508 ;; remember the beginning position of this rule 1508 ;; us that the rule is not valid at this point in
1509 ;; match, and save the match-data, since either 1509 ;; the code..
1510 ;; the `valid' form, or the code that searches for 1510 (unless (and valid (not (funcall (cdr valid))))
1511 ;; section separation, might alter it 1511
1512 (setq rule-beg (match-beginning first) 1512 ;; look to see if this match begins a new
1513 save-match-data (match-data)) 1513 ;; section. If so, we should align what we've
1514 1514 ;; collected so far, and then begin collecting
1515 (or rule-beg 1515 ;; anew for the next alignment section
1516 (error "No match for subexpression %s" first)) 1516 (when (and last-point
1517 1517 (align-new-section-p last-point rule-beg
1518 ;; unless the `valid' attribute is set, and tells 1518 thissep))
1519 ;; us that the rule is not valid at this point in 1519 (align-regions regions align-props rule func)
1520 ;; the code.. 1520 (setq regions nil)
1521 (unless (and valid (not (funcall (cdr valid)))) 1521 (setq align-props nil))
1522 1522 (align--set-marker last-point rule-beg t)
1523 ;; look to see if this match begins a new 1523
1524 ;; section. If so, we should align what we've 1524 ;; restore the match data
1525 ;; collected so far, and then begin collecting 1525 (set-match-data save-match-data)
1526 ;; anew for the next alignment section 1526
1527 (when (and last-point 1527 ;; check whether the region to be aligned
1528 (align-new-section-p last-point rule-beg 1528 ;; straddles an exclusion area
1529 thissep)) 1529 (let ((excls exclude-areas))
1530 (align-regions regions align-props rule func) 1530 (setq exclude-p nil)
1531 (setq regions nil) 1531 (while excls
1532 (setq align-props nil)) 1532 (if (and (< (match-beginning (car groups))
1533 (align--set-marker last-point rule-beg t) 1533 (cdar excls))
1534 1534 (> (match-end (car (last groups)))
1535 ;; restore the match data 1535 (caar excls)))
1536 (set-match-data save-match-data) 1536 (setq exclude-p t
1537 1537 excls nil)
1538 ;; check whether the region to be aligned 1538 (setq excls (cdr excls)))))
1539 ;; straddles an exclusion area 1539
1540 (let ((excls exclude-areas)) 1540 ;; go through the parenthesis groups
1541 (setq exclude-p nil) 1541 ;; matching whitespace to be contracted or
1542 (while excls 1542 ;; expanded (or possibly justified, if the
1543 (if (and (< (match-beginning (car groups)) 1543 ;; `justify' attribute was set)
1544 (cdar excls)) 1544 (unless exclude-p
1545 (> (match-end (car (last groups))) 1545 (dolist (g groups)
1546 (caar excls))) 1546 ;; We must use markers, since
1547 (setq exclude-p t 1547 ;; `align-areas' may modify the buffer.
1548 excls nil) 1548 ;; Avoid polluting the markers.
1549 (setq excls (cdr excls))))) 1549 (let* ((group-beg (copy-marker
1550 1550 (match-beginning g) t))
1551 ;; go through the parenthesis groups 1551 (group-end (copy-marker
1552 ;; matching whitespace to be contracted or 1552 (match-end g) t))
1553 ;; expanded (or possibly justified, if the 1553 (region (cons group-beg group-end))
1554 ;; `justify' attribute was set) 1554 (props (cons (if (listp spacing)
1555 (unless exclude-p 1555 (car spacing)
1556 (dolist (g groups) 1556 spacing)
1557 ;; We must use markers, since 1557 (if (listp tab-stop)
1558 ;; `align-areas' may modify the buffer. 1558 (car tab-stop)
1559 ;; Avoid polluting the markers. 1559 tab-stop))))
1560 (let* ((group-beg (copy-marker 1560 (push group-beg markers)
1561 (match-beginning g) t)) 1561 (push group-end markers)
1562 (group-end (copy-marker 1562 (setq index (if same (1+ index) 0))
1563 (match-end g) t)) 1563 (cond
1564 (region (cons group-beg group-end)) 1564 ((nth index regions)
1565 (props (cons (if (listp spacing) 1565 (setcar (nthcdr index regions)
1566 (car spacing) 1566 (cons region
1567 spacing) 1567 (nth index regions))))
1568 (if (listp tab-stop) 1568 (regions
1569 (car tab-stop) 1569 (nconc regions
1570 tab-stop)))) 1570 (list (list region)))
1571 (push group-beg markers) 1571 (nconc align-props (list props)))
1572 (push group-end markers) 1572 (t
1573 (setq index (if same (1+ index) 0)) 1573 (setq regions
1574 (cond 1574 (list (list region)))
1575 ((nth index regions) 1575 (setq align-props (list props)))))
1576 (setcar (nthcdr index regions) 1576 ;; If any further rule matches are found
1577 (cons region 1577 ;; before `eol', they are on the same
1578 (nth index regions)))) 1578 ;; line as this one; this can only
1579 (regions 1579 ;; happen if the `repeat' attribute is
1580 (nconc regions 1580 ;; non-nil.
1581 (list (list region))) 1581 (if (listp spacing)
1582 (nconc align-props (list props))) 1582 (setq spacing (cdr spacing)))
1583 (t 1583 (if (listp tab-stop)
1584 (setq regions 1584 (setq tab-stop (cdr tab-stop)))
1585 (list (list region))) 1585 (setq same t))
1586 (setq align-props (list props))))) 1586
1587 ;; If any further rule matches are found 1587 ;; if `repeat' has not been set, move to
1588 ;; before `eol', they are on the same 1588 ;; the next line; don't bother searching
1589 ;; line as this one; this can only 1589 ;; anymore on this one
1590 ;; happen if the `repeat' attribute is 1590 (if (and (not repeat) (not (bolp)))
1591 ;; non-nil. 1591 (forward-line))
1592 (if (listp spacing) 1592
1593 (setq spacing (cdr spacing))) 1593 ;; if the search did not change point,
1594 (if (listp tab-stop) 1594 ;; move forward to avoid an infinite loop
1595 (setq tab-stop (cdr tab-stop))) 1595 (if (= (point) search-start)
1596 (setq same t)) 1596 (forward-char)))))
1597 1597
1598 ;; if `repeat' has not been set, move to 1598 ;; when they are no more matches for this rule,
1599 ;; the next line; don't bother searching 1599 ;; align whatever was left over
1600 ;; anymore on this one 1600 (if regions
1601 (if (and (not repeat) (not (bolp))) 1601 (align-regions regions align-props rule func))))))))
1602 (forward-line))
1603
1604 ;; if the search did not change point,
1605 ;; move forward to avoid an infinite loop
1606 (if (= (point) search-start)
1607 (forward-char)))))
1608
1609 ;; when they are no more matches for this rule,
1610 ;; align whatever was left over
1611 (if regions
1612 (align-regions regions align-props rule func)))
1613
1614 (setq case-fold-search current-case-fold)))))))
1615 (setq rules (cdr rules) 1602 (setq rules (cdr rules)
1616 rule-index (1+ rule-index))) 1603 rule-index (1+ rule-index)))
1617 ;; This function can use a lot of temporary markers, so instead of 1604 ;; This function can use a lot of temporary markers, so instead of