aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/byte-opt.el106
-rw-r--r--lisp/emacs-lisp/cl-extra.el9
-rw-r--r--lisp/emacs-lisp/cl-loaddefs.el2
-rw-r--r--lisp/minibuffer.el174
4 files changed, 109 insertions, 182 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index e415b5edde2..b08fc3d708a 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -186,8 +186,10 @@
186(eval-when-compile (require 'cl)) 186(eval-when-compile (require 'cl))
187 187
188(defun byte-compile-log-lap-1 (format &rest args) 188(defun byte-compile-log-lap-1 (format &rest args)
189;; (if (aref byte-code-vector 0) 189 ;; Newer byte codes for stack-ref make the slot 0 non-nil again.
190;; (error "The old version of the disassembler is loaded. Reload new-bytecomp as well")) 190 ;; But the "old disassembler" is *really* ancient by now.
191 ;; (if (aref byte-code-vector 0)
192 ;; (error "The old version of the disassembler is loaded. Reload new-bytecomp as well"))
191 (byte-compile-log-1 193 (byte-compile-log-1
192 (apply 'format format 194 (apply 'format format
193 (let (c a) 195 (let (c a)
@@ -1512,50 +1514,12 @@
1512;; The variable `byte-boolean-vars' is now primitive and updated 1514;; The variable `byte-boolean-vars' is now primitive and updated
1513;; automatically by DEFVAR_BOOL. 1515;; automatically by DEFVAR_BOOL.
1514 1516
1515(defmacro byte-opt-update-stack-params (stack-adjust stack-depth lap0 rest lap)
1516 "...macro used by byte-optimize-lapcode..."
1517 `(progn
1518 (byte-compile-log-lap "Before %s [depth = %s]" ,lap0 ,stack-depth)
1519 (cond ((eq (car ,lap0) 'TAG)
1520 ;; A tag can encode the expected stack depth.
1521 (when (cddr ,lap0)
1522 ;; First, check to see if our notion of the current stack
1523 ;; depth agrees with this tag. We don't check at the
1524 ;; beginning of the function, because the presence of
1525 ;; lexical arguments means the first tag will have a
1526 ;; non-zero offset.
1527 (when (and (not (eq ,rest ,lap)) ; not at first insn
1528 ,stack-depth ; not just after a goto
1529 (not (= (cddr ,lap0) ,stack-depth)))
1530 (error "Compiler error: optimizer is confused about %s:
1531 %s != %s at lapcode %s" ',stack-depth (cddr ,lap0) ,stack-depth ,lap0))
1532 ;; Now set out current depth from this tag
1533 (setq ,stack-depth (cddr ,lap0)))
1534 (setq ,stack-adjust 0))
1535 ((memq (car ,lap0) '(byte-goto byte-return))
1536 ;; These insns leave us in an unknown state
1537 (setq ,stack-adjust nil))
1538 ((car ,lap0)
1539 ;; Not a no-op, set ,stack-adjust for lap0. ,stack-adjust will
1540 ;; be added to ,stack-depth at the end of the loop, so any code
1541 ;; that modifies the instruction sequence must adjust this too.
1542 (setq ,stack-adjust
1543 (byte-compile-stack-adjustment (car ,lap0) (cdr ,lap0)))))
1544 (byte-compile-log-lap "Before %s [depth => %s, adj = %s]" ,lap0 ,stack-depth ,stack-adjust)
1545 ))
1546
1547(defun byte-optimize-lapcode (lap &optional for-effect) 1517(defun byte-optimize-lapcode (lap &optional for-effect)
1548 "Simple peephole optimizer. LAP is both modified and returned. 1518 "Simple peephole optimizer. LAP is both modified and returned.
1549If FOR-EFFECT is non-nil, the return value is assumed to be of no importance." 1519If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1550 (let (lap0 1520 (let (lap0
1551 lap1 1521 lap1
1552 lap2 1522 lap2
1553 stack-adjust
1554 stack-depth
1555 (initial-stack-depth
1556 (if (and lap (eq (car (car lap)) 'TAG))
1557 (cdr (cdr (car lap)))
1558 0))
1559 (keep-going 'first-time) 1523 (keep-going 'first-time)
1560 (add-depth 0) 1524 (add-depth 0)
1561 rest tmp tmp2 tmp3 1525 rest tmp tmp2 tmp3
@@ -1566,15 +1530,12 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1566 (or (eq keep-going 'first-time) 1530 (or (eq keep-going 'first-time)
1567 (byte-compile-log-lap " ---- next pass")) 1531 (byte-compile-log-lap " ---- next pass"))
1568 (setq rest lap 1532 (setq rest lap
1569 stack-depth initial-stack-depth
1570 keep-going nil) 1533 keep-going nil)
1571 (while rest 1534 (while rest
1572 (setq lap0 (car rest) 1535 (setq lap0 (car rest)
1573 lap1 (nth 1 rest) 1536 lap1 (nth 1 rest)
1574 lap2 (nth 2 rest)) 1537 lap2 (nth 2 rest))
1575 1538
1576 (byte-opt-update-stack-params stack-adjust stack-depth lap0 rest lap)
1577
1578 ;; You may notice that sequences like "dup varset discard" are 1539 ;; You may notice that sequences like "dup varset discard" are
1579 ;; optimized but sequences like "dup varset TAG1: discard" are not. 1540 ;; optimized but sequences like "dup varset TAG1: discard" are not.
1580 ;; You may be tempted to change this; resist that temptation. 1541 ;; You may be tempted to change this; resist that temptation.
@@ -1588,22 +1549,22 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1588 ((and (eq 'byte-discard (car lap1)) 1549 ((and (eq 'byte-discard (car lap1))
1589 (memq (car lap0) side-effect-free)) 1550 (memq (car lap0) side-effect-free))
1590 (setq keep-going t) 1551 (setq keep-going t)
1552 (setq tmp (aref byte-stack+-info (symbol-value (car lap0))))
1591 (setq rest (cdr rest)) 1553 (setq rest (cdr rest))
1592 (cond ((= stack-adjust 1) 1554 (cond ((= tmp 1)
1593 (byte-compile-log-lap 1555 (byte-compile-log-lap
1594 " %s discard\t-->\t<deleted>" lap0) 1556 " %s discard\t-->\t<deleted>" lap0)
1595 (setq lap (delq lap0 (delq lap1 lap)))) 1557 (setq lap (delq lap0 (delq lap1 lap))))
1596 ((= stack-adjust 0) 1558 ((= tmp 0)
1597 (byte-compile-log-lap 1559 (byte-compile-log-lap
1598 " %s discard\t-->\t<deleted> discard" lap0) 1560 " %s discard\t-->\t<deleted> discard" lap0)
1599 (setq lap (delq lap0 lap))) 1561 (setq lap (delq lap0 lap)))
1600 ((= stack-adjust -1) 1562 ((= tmp -1)
1601 (byte-compile-log-lap 1563 (byte-compile-log-lap
1602 " %s discard\t-->\tdiscard discard" lap0) 1564 " %s discard\t-->\tdiscard discard" lap0)
1603 (setcar lap0 'byte-discard) 1565 (setcar lap0 'byte-discard)
1604 (setcdr lap0 0)) 1566 (setcdr lap0 0))
1605 ((error "Optimizer error: too much on the stack"))) 1567 ((error "Optimizer error: too much on the stack"))))
1606 (setq stack-adjust (1- stack-adjust)))
1607 ;; 1568 ;;
1608 ;; goto*-X X: --> X: 1569 ;; goto*-X X: --> X:
1609 ;; 1570 ;;
@@ -1673,8 +1634,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1673 byte-stack-set))) 1634 byte-stack-set)))
1674 (byte-compile-log-lap " dup %s discard\t-->\t%s" lap1 lap1) 1635 (byte-compile-log-lap " dup %s discard\t-->\t%s" lap1 lap1)
1675 (setq keep-going t 1636 (setq keep-going t
1676 rest (cdr rest) 1637 rest (cdr rest))
1677 stack-adjust -1)
1678 (if (eq 'byte-stack-set (car lap1)) (decf (cdr lap1))) 1638 (if (eq 'byte-stack-set (car lap1)) (decf (cdr lap1)))
1679 (setq lap (delq lap0 (delq lap2 lap)))) 1639 (setq lap (delq lap0 (delq lap2 lap))))
1680 ;; 1640 ;;
@@ -1697,8 +1657,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1697 'byte-goto-if-not-nil 1657 'byte-goto-if-not-nil
1698 'byte-goto-if-nil)) 1658 'byte-goto-if-nil))
1699 (setq lap (delq lap0 lap)) 1659 (setq lap (delq lap0 lap))
1700 (setq keep-going t 1660 (setq keep-going t))
1701 stack-adjust 0))
1702 ;; 1661 ;;
1703 ;; goto-X-if-nil goto-Y X: --> goto-Y-if-non-nil X: 1662 ;; goto-X-if-nil goto-Y X: --> goto-Y-if-non-nil X:
1704 ;; goto-X-if-non-nil goto-Y X: --> goto-Y-if-nil X: 1663 ;; goto-X-if-non-nil goto-Y X: --> goto-Y-if-nil X:
@@ -1714,8 +1673,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1714 (byte-compile-log-lap " %s %s %s:\t-->\t%s %s:" 1673 (byte-compile-log-lap " %s %s %s:\t-->\t%s %s:"
1715 lap0 lap1 lap2 1674 lap0 lap1 lap2
1716 (cons inverse (cdr lap1)) lap2) 1675 (cons inverse (cdr lap1)) lap2)
1717 (setq lap (delq lap0 lap) 1676 (setq lap (delq lap0 lap))
1718 stack-adjust 0)
1719 (setcar lap1 inverse) 1677 (setcar lap1 inverse)
1720 (setq keep-going t))) 1678 (setq keep-going t)))
1721 ;; 1679 ;;
@@ -1738,8 +1696,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1738 (when (memq (car lap1) byte-goto-always-pop-ops) 1696 (when (memq (car lap1) byte-goto-always-pop-ops)
1739 (setq lap (delq lap0 lap))) 1697 (setq lap (delq lap0 lap)))
1740 (setcar lap1 'byte-goto))) 1698 (setcar lap1 'byte-goto)))
1741 (setq keep-going t 1699 (setq keep-going t))
1742 stack-adjust 0))
1743 ;; 1700 ;;
1744 ;; varref-X varref-X --> varref-X dup 1701 ;; varref-X varref-X --> varref-X dup
1745 ;; varref-X [dup ...] varref-X --> varref-X [dup ...] dup 1702 ;; varref-X [dup ...] varref-X --> varref-X [dup ...] dup
@@ -1772,8 +1729,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1772 (setq keep-going t) 1729 (setq keep-going t)
1773 (setcar (car tmp) 'byte-dup) 1730 (setcar (car tmp) 'byte-dup)
1774 (setcdr (car tmp) 0) 1731 (setcdr (car tmp) 0)
1775 (setq rest tmp 1732 (setq rest tmp))
1776 stack-adjust (+ 2 tmp2)))
1777 ;; 1733 ;;
1778 ;; TAG1: TAG2: --> TAG1: <deleted> 1734 ;; TAG1: TAG2: --> TAG1: <deleted>
1779 ;; (and other references to TAG2 are replaced with TAG1) 1735 ;; (and other references to TAG2 are replaced with TAG1)
@@ -1840,8 +1796,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1840 (byte-compile-log-lap " %s %s\t-->\t%s %s" lap0 lap1 lap1 lap0) 1796 (byte-compile-log-lap " %s %s\t-->\t%s %s" lap0 lap1 lap1 lap0)
1841 (setcar rest lap1) 1797 (setcar rest lap1)
1842 (setcar (cdr rest) lap0) 1798 (setcar (cdr rest) lap0)
1843 (setq keep-going t 1799 (setq keep-going t))
1844 stack-adjust 0))
1845 ;; 1800 ;;
1846 ;; varbind-X unbind-N --> discard unbind-(N-1) 1801 ;; varbind-X unbind-N --> discard unbind-(N-1)
1847 ;; save-excursion unbind-N --> unbind-(N-1) 1802 ;; save-excursion unbind-N --> unbind-(N-1)
@@ -1943,8 +1898,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1943 (cdr tmp)))) 1898 (cdr tmp))))
1944 (setcdr lap1 (car (cdr tmp))) 1899 (setcdr lap1 (car (cdr tmp)))
1945 (setq lap (delq lap0 lap)))) 1900 (setq lap (delq lap0 lap))))
1946 (setq keep-going t 1901 (setq keep-going t))
1947 stack-adjust 0))
1948 ;; 1902 ;;
1949 ;; X: varref-Y ... varset-Y goto-X --> 1903 ;; X: varref-Y ... varset-Y goto-X -->
1950 ;; X: varref-Y Z: ... dup varset-Y goto-Z 1904 ;; X: varref-Y Z: ... dup varset-Y goto-Z
@@ -1960,12 +1914,9 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
1960 (eq (car lap2) 'byte-goto) 1914 (eq (car lap2) 'byte-goto)
1961 (not (memq (cdr lap2) rest)) ;Backwards jump 1915 (not (memq (cdr lap2) rest)) ;Backwards jump
1962 (eq (car (car (setq tmp (cdr (memq (cdr lap2) lap))))) 1916 (eq (car (car (setq tmp (cdr (memq (cdr lap2) lap)))))
1963 (if (eq (car lap1) 'byte-varset) 'byte-varref 1917 'byte-varref)
1964 ;; 'byte-stack-ref
1965 ))
1966 (eq (cdr (car tmp)) (cdr lap1)) 1918 (eq (cdr (car tmp)) (cdr lap1))
1967 (not (and (eq (car lap1) 'byte-varref) 1919 (not (memq (car (cdr lap1)) byte-boolean-vars)))
1968 (memq (car (cdr lap1)) byte-boolean-vars))))
1969 ;;(byte-compile-log-lap " Pulled %s to end of loop" (car tmp)) 1920 ;;(byte-compile-log-lap " Pulled %s to end of loop" (car tmp))
1970 (let ((newtag (byte-compile-make-tag))) 1921 (let ((newtag (byte-compile-make-tag)))
1971 (byte-compile-log-lap 1922 (byte-compile-log-lap
@@ -2022,15 +1973,10 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2022 byte-goto-if-not-nil 1973 byte-goto-if-not-nil
2023 byte-goto byte-goto)))) 1974 byte-goto byte-goto))))
2024 ) 1975 )
2025 (setq keep-going t 1976 (setq keep-going t))
2026 stack-adjust (and (not (eq (car lap0) 'byte-goto)) -1)))
2027 ) 1977 )
2028
2029 (setq stack-depth
2030 (and stack-depth stack-adjust (+ stack-depth stack-adjust)))
2031 (setq rest (cdr rest))) 1978 (setq rest (cdr rest)))
2032 ) 1979 )
2033
2034 ;; Cleanup stage: 1980 ;; Cleanup stage:
2035 ;; Rebuild byte-compile-constants / byte-compile-variables. 1981 ;; Rebuild byte-compile-constants / byte-compile-variables.
2036 ;; Simple optimizations that would inhibit other optimizations if they 1982 ;; Simple optimizations that would inhibit other optimizations if they
@@ -2038,13 +1984,11 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2038 ;; need to do more than once. 1984 ;; need to do more than once.
2039 (setq byte-compile-constants nil 1985 (setq byte-compile-constants nil
2040 byte-compile-variables nil) 1986 byte-compile-variables nil)
2041 (setq rest lap 1987 (setq rest lap)
2042 stack-depth initial-stack-depth)
2043 (byte-compile-log-lap " ---- final pass") 1988 (byte-compile-log-lap " ---- final pass")
2044 (while rest 1989 (while rest
2045 (setq lap0 (car rest) 1990 (setq lap0 (car rest)
2046 lap1 (nth 1 rest)) 1991 lap1 (nth 1 rest))
2047 (byte-opt-update-stack-params stack-adjust stack-depth lap0 rest lap)
2048 (if (memq (car lap0) byte-constref-ops) 1992 (if (memq (car lap0) byte-constref-ops)
2049 (if (or (eq (car lap0) 'byte-constant) 1993 (if (or (eq (car lap0) 'byte-constant)
2050 (eq (car lap0) 'byte-constant2)) 1994 (eq (car lap0) 'byte-constant2))
@@ -2127,7 +2071,6 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2127 'byte-discardN)) 2071 'byte-discardN))
2128 (setcdr lap1 (1+ tmp3)) 2072 (setcdr lap1 (1+ tmp3))
2129 (setcdr (cdr rest) tmp) 2073 (setcdr (cdr rest) tmp)
2130 (setq stack-adjust 0)
2131 (byte-compile-log-lap " %s [discard/discardN]...\t-->\t%s" 2074 (byte-compile-log-lap " %s [discard/discardN]...\t-->\t%s"
2132 lap0 lap1)) 2075 lap0 lap1))
2133 2076
@@ -2148,8 +2091,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2148 (if (eq (car lap1) 'byte-discard) 1 (cdr lap1)))) 2091 (if (eq (car lap1) 'byte-discard) 1 (cdr lap1))))
2149 (setcdr lap1 (+ (if (eq (car lap0) 'byte-discard) 1 (cdr lap0)) 2092 (setcdr lap1 (+ (if (eq (car lap0) 'byte-discard) 1 (cdr lap0))
2150 (if (eq (car lap1) 'byte-discard) 1 (cdr lap1)))) 2093 (if (eq (car lap1) 'byte-discard) 1 (cdr lap1))))
2151 (setcar lap1 'byte-discardN) 2094 (setcar lap1 'byte-discardN))
2152 (setq stack-adjust 0))
2153 2095
2154 ;; 2096 ;;
2155 ;; discardN-preserve-tos-X discardN-preserve-tos-Y --> 2097 ;; discardN-preserve-tos-X discardN-preserve-tos-Y -->
@@ -2159,7 +2101,6 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2159 (eq (car lap1) 'byte-discardN-preserve-tos)) 2101 (eq (car lap1) 'byte-discardN-preserve-tos))
2160 (setq lap (delq lap0 lap)) 2102 (setq lap (delq lap0 lap))
2161 (setcdr lap1 (+ (cdr lap0) (cdr lap1))) 2103 (setcdr lap1 (+ (cdr lap0) (cdr lap1)))
2162 (setq stack-adjust 0)
2163 (byte-compile-log-lap " %s %s\t-->\t%s" lap0 lap1 (car rest))) 2104 (byte-compile-log-lap " %s %s\t-->\t%s" lap0 lap1 (car rest)))
2164 2105
2165 ;; 2106 ;;
@@ -2174,14 +2115,9 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance."
2174 ;; The byte-code interpreter will pop the stack for us, so 2115 ;; The byte-code interpreter will pop the stack for us, so
2175 ;; we can just leave stuff on it. 2116 ;; we can just leave stuff on it.
2176 (setq lap (delq lap0 lap)) 2117 (setq lap (delq lap0 lap))
2177 (setq stack-adjust 0)
2178 (byte-compile-log-lap " %s %s\t-->\t%s" lap0 lap1 lap1)) 2118 (byte-compile-log-lap " %s %s\t-->\t%s" lap0 lap1 lap1))
2179 ) 2119 )
2180
2181 (setq stack-depth
2182 (and stack-depth stack-adjust (+ stack-depth stack-adjust)))
2183 (setq rest (cdr rest))) 2120 (setq rest (cdr rest)))
2184
2185 (setq byte-compile-maxdepth (+ byte-compile-maxdepth add-depth))) 2121 (setq byte-compile-maxdepth (+ byte-compile-maxdepth add-depth)))
2186 lap) 2122 lap)
2187 2123
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 885424ec726..12dafe274b9 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -771,10 +771,11 @@ This also does some trivial optimizations to make the form prettier."
771 (sublis sub (nreverse decls)) 771 (sublis sub (nreverse decls))
772 (list 772 (list
773 (list* 'list '(quote apply) 773 (list* 'list '(quote apply)
774 (list 'function 774 (list 'quote
775 (list* 'lambda 775 (list 'function
776 (append new (cadadr form)) 776 (list* 'lambda
777 (sublis sub body))) 777 (append new (cadadr form))
778 (sublis sub body))))
778 (nconc (mapcar (function 779 (nconc (mapcar (function
779 (lambda (x) 780 (lambda (x)
780 (list 'list '(quote quote) x))) 781 (list 'list '(quote quote) x)))
diff --git a/lisp/emacs-lisp/cl-loaddefs.el b/lisp/emacs-lisp/cl-loaddefs.el
index a13e46ccc59..4f2d5df1f54 100644
--- a/lisp/emacs-lisp/cl-loaddefs.el
+++ b/lisp/emacs-lisp/cl-loaddefs.el
@@ -10,7 +10,7 @@
10;;;;;; ceiling* floor* isqrt lcm gcd cl-progv-before cl-set-frame-visible-p 10;;;;;; ceiling* floor* isqrt lcm gcd cl-progv-before cl-set-frame-visible-p
11;;;;;; cl-map-overlays cl-map-intervals cl-map-keymap-recursively 11;;;;;; cl-map-overlays cl-map-intervals cl-map-keymap-recursively
12;;;;;; notevery notany every some mapcon mapcan mapl maplist map 12;;;;;; notevery notany every some mapcon mapcan mapl maplist map
13;;;;;; cl-mapcar-many equalp coerce) "cl-extra" "cl-extra.el" "60f6b85256416c5f2a0a3954a11523b6") 13;;;;;; cl-mapcar-many equalp coerce) "cl-extra" "cl-extra.el" "2bfbae6523c842d511b8c8d88658825a")
14;;; Generated autoloads from cl-extra.el 14;;; Generated autoloads from cl-extra.el
15 15
16(autoload 'coerce "cl-extra" "\ 16(autoload 'coerce "cl-extra" "\
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 1b42ee1f2ce..94ba46069d5 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1,4 +1,4 @@
1;;; minibuffer.el --- Minibuffer completion functions 1;;; minibuffer.el --- Minibuffer completion functions -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 2008-2011 Free Software Foundation, Inc. 3;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
4 4
@@ -133,8 +133,8 @@ the closest directory separators."
133 "Apply FUN to each element of XS in turn. 133 "Apply FUN to each element of XS in turn.
134Return the first non-nil returned value. 134Return the first non-nil returned value.
135Like CL's `some'." 135Like CL's `some'."
136 (lexical-let ((firsterror nil) 136 (let ((firsterror nil)
137 res) 137 res)
138 (while (and (not res) xs) 138 (while (and (not res) xs)
139 (condition-case err 139 (condition-case err
140 (setq res (funcall fun (pop xs))) 140 (setq res (funcall fun (pop xs)))
@@ -171,12 +171,11 @@ FUN will be called in the buffer from which the minibuffer was entered.
171The result of the `completion-table-dynamic' form is a function 171The result of the `completion-table-dynamic' form is a function
172that can be used as the COLLECTION argument to `try-completion' and 172that can be used as the COLLECTION argument to `try-completion' and
173`all-completions'. See Info node `(elisp)Programmed Completion'." 173`all-completions'. See Info node `(elisp)Programmed Completion'."
174 (lexical-let ((fun fun)) 174 (lambda (string pred action)
175 (lambda (string pred action) 175 (with-current-buffer (let ((win (minibuffer-selected-window)))
176 (with-current-buffer (let ((win (minibuffer-selected-window))) 176 (if (window-live-p win) (window-buffer win)
177 (if (window-live-p win) (window-buffer win) 177 (current-buffer)))
178 (current-buffer))) 178 (complete-with-action action (funcall fun string) string pred))))
179 (complete-with-action action (funcall fun string) string pred)))))
180 179
181(defmacro lazy-completion-table (var fun) 180(defmacro lazy-completion-table (var fun)
182 "Initialize variable VAR as a lazy completion table. 181 "Initialize variable VAR as a lazy completion table.
@@ -201,19 +200,18 @@ You should give VAR a non-nil `risky-local-variable' property."
201 ;; Notice that `pred' may not be a function in some abusive cases. 200 ;; Notice that `pred' may not be a function in some abusive cases.
202 (when (functionp pred) 201 (when (functionp pred)
203 (setq pred 202 (setq pred
204 (lexical-let ((pred pred)) 203 ;; Predicates are called differently depending on the nature of
205 ;; Predicates are called differently depending on the nature of 204 ;; the completion table :-(
206 ;; the completion table :-( 205 (cond
207 (cond 206 ((vectorp table) ;Obarray.
208 ((vectorp table) ;Obarray. 207 (lambda (sym) (funcall pred (concat prefix (symbol-name sym)))))
209 (lambda (sym) (funcall pred (concat prefix (symbol-name sym))))) 208 ((hash-table-p table)
210 ((hash-table-p table) 209 (lambda (s v) (funcall pred (concat prefix s))))
211 (lambda (s v) (funcall pred (concat prefix s)))) 210 ((functionp table)
212 ((functionp table) 211 (lambda (s) (funcall pred (concat prefix s))))
213 (lambda (s) (funcall pred (concat prefix s)))) 212 (t ;Lists and alists.
214 (t ;Lists and alists. 213 (lambda (s)
215 (lambda (s) 214 (funcall pred (concat prefix (if (consp s) (car s) s))))))))
216 (funcall pred (concat prefix (if (consp s) (car s) s)))))))))
217 (if (eq (car-safe action) 'boundaries) 215 (if (eq (car-safe action) 'boundaries)
218 (let* ((len (length prefix)) 216 (let* ((len (length prefix))
219 (bound (completion-boundaries string table pred (cdr action)))) 217 (bound (completion-boundaries string table pred (cdr action))))
@@ -288,11 +286,10 @@ Note: TABLE needs to be a proper completion table which obeys predicates."
288 (t 286 (t
289 (or (complete-with-action action table string 287 (or (complete-with-action action table string
290 (if (null pred2) pred1 288 (if (null pred2) pred1
291 (lexical-let ((pred1 pred2) (pred2 pred2)) 289 (lambda (x)
292 (lambda (x) 290 ;; Call `pred1' first, so that `pred2'
293 ;; Call `pred1' first, so that `pred2' 291 ;; really can't tell that `x' is in table.
294 ;; really can't tell that `x' is in table. 292 (if (funcall pred1 x) (funcall pred2 x)))))
295 (if (funcall pred1 x) (funcall pred2 x))))))
296 ;; If completion failed and we're not applying pred1 strictly, try 293 ;; If completion failed and we're not applying pred1 strictly, try
297 ;; again without pred1. 294 ;; again without pred1.
298 (and (not strict) 295 (and (not strict)
@@ -302,11 +299,10 @@ Note: TABLE needs to be a proper completion table which obeys predicates."
302 "Create a completion table that tries each table in TABLES in turn." 299 "Create a completion table that tries each table in TABLES in turn."
303 ;; FIXME: the boundaries may come from TABLE1 even when the completion list 300 ;; FIXME: the boundaries may come from TABLE1 even when the completion list
304 ;; is returned by TABLE2 (because TABLE1 returned an empty list). 301 ;; is returned by TABLE2 (because TABLE1 returned an empty list).
305 (lexical-let ((tables tables)) 302 (lambda (string pred action)
306 (lambda (string pred action) 303 (completion--some (lambda (table)
307 (completion--some (lambda (table) 304 (complete-with-action action table string pred))
308 (complete-with-action action table string pred)) 305 tables)))
309 tables))))
310 306
311;; (defmacro complete-in-turn (a b) `(completion-table-in-turn ,a ,b)) 307;; (defmacro complete-in-turn (a b) `(completion-table-in-turn ,a ,b))
312;; (defmacro dynamic-completion-table (fun) `(completion-table-dynamic ,fun)) 308;; (defmacro dynamic-completion-table (fun) `(completion-table-dynamic ,fun))
@@ -548,16 +544,15 @@ E = after completion we now have an Exact match.
548 101 5 ??? impossible 544 101 5 ??? impossible
549 110 6 some completion happened 545 110 6 some completion happened
550 111 7 completed to an exact completion" 546 111 7 completed to an exact completion"
551 (lexical-let* 547 (let* ((beg (field-beginning))
552 ((beg (field-beginning)) 548 (end (field-end))
553 (end (field-end)) 549 (string (buffer-substring beg end))
554 (string (buffer-substring beg end)) 550 (comp (funcall (or try-completion-function
555 (comp (funcall (or try-completion-function 551 'completion-try-completion)
556 'completion-try-completion) 552 string
557 string 553 minibuffer-completion-table
558 minibuffer-completion-table 554 minibuffer-completion-predicate
559 minibuffer-completion-predicate 555 (- (point) beg))))
560 (- (point) beg))))
561 (cond 556 (cond
562 ((null comp) 557 ((null comp)
563 (minibuffer-hide-completions) 558 (minibuffer-hide-completions)
@@ -572,13 +567,12 @@ E = after completion we now have an Exact match.
572 ;; `completed' should be t if some completion was done, which doesn't 567 ;; `completed' should be t if some completion was done, which doesn't
573 ;; include simply changing the case of the entered string. However, 568 ;; include simply changing the case of the entered string. However,
574 ;; for appearance, the string is rewritten if the case changes. 569 ;; for appearance, the string is rewritten if the case changes.
575 (lexical-let* 570 (let* ((comp-pos (cdr comp))
576 ((comp-pos (cdr comp)) 571 (completion (car comp))
577 (completion (car comp)) 572 (completed (not (eq t (compare-strings completion nil nil
578 (completed (not (eq t (compare-strings completion nil nil 573 string nil nil t))))
579 string nil nil t)))) 574 (unchanged (eq t (compare-strings completion nil nil
580 (unchanged (eq t (compare-strings completion nil nil 575 string nil nil nil))))
581 string nil nil nil))))
582 (if unchanged 576 (if unchanged
583 (goto-char end) 577 (goto-char end)
584 ;; Insert in minibuffer the chars we got. 578 ;; Insert in minibuffer the chars we got.
@@ -759,8 +753,8 @@ If `minibuffer-completion-confirm' is `confirm-after-completion',
759 `minibuffer-confirm-exit-commands', and accept the input 753 `minibuffer-confirm-exit-commands', and accept the input
760 otherwise." 754 otherwise."
761 (interactive) 755 (interactive)
762 (lexical-let ((beg (field-beginning)) 756 (let ((beg (field-beginning))
763 (end (field-end))) 757 (end (field-end)))
764 (cond 758 (cond
765 ;; Allow user to specify null string 759 ;; Allow user to specify null string
766 ((= beg end) (exit-minibuffer)) 760 ((= beg end) (exit-minibuffer))
@@ -1137,14 +1131,14 @@ variables.")
1137 "Display a list of possible completions of the current minibuffer contents." 1131 "Display a list of possible completions of the current minibuffer contents."
1138 (interactive) 1132 (interactive)
1139 (message "Making completion list...") 1133 (message "Making completion list...")
1140 (lexical-let* ((start (field-beginning)) 1134 (let* ((start (field-beginning))
1141 (end (field-end)) 1135 (end (field-end))
1142 (string (field-string)) 1136 (string (field-string))
1143 (completions (completion-all-completions 1137 (completions (completion-all-completions
1144 string 1138 string
1145 minibuffer-completion-table 1139 minibuffer-completion-table
1146 minibuffer-completion-predicate 1140 minibuffer-completion-predicate
1147 (- (point) (field-beginning))))) 1141 (- (point) (field-beginning)))))
1148 (message nil) 1142 (message nil)
1149 (if (and completions 1143 (if (and completions
1150 (or (consp (cdr completions)) 1144 (or (consp (cdr completions))
@@ -1619,8 +1613,8 @@ and `read-file-name-function'."
1619 ;; just use `default-directory', but in order to avoid 1613 ;; just use `default-directory', but in order to avoid
1620 ;; changing `default-directory' in the current buffer, 1614 ;; changing `default-directory' in the current buffer,
1621 ;; we don't let-bind it. 1615 ;; we don't let-bind it.
1622 (lexical-let ((dir (file-name-as-directory 1616 (let ((dir (file-name-as-directory
1623 (expand-file-name dir)))) 1617 (expand-file-name dir))))
1624 (minibuffer-with-setup-hook 1618 (minibuffer-with-setup-hook
1625 (lambda () 1619 (lambda ()
1626 (setq default-directory dir) 1620 (setq default-directory dir)
@@ -1719,7 +1713,7 @@ and `read-file-name-function'."
1719 "Perform completion on all buffers excluding BUFFER. 1713 "Perform completion on all buffers excluding BUFFER.
1720BUFFER nil or omitted means use the current buffer. 1714BUFFER nil or omitted means use the current buffer.
1721Like `internal-complete-buffer', but removes BUFFER from the completion list." 1715Like `internal-complete-buffer', but removes BUFFER from the completion list."
1722 (lexical-let ((except (if (stringp buffer) buffer (buffer-name buffer)))) 1716 (let ((except (if (stringp buffer) buffer (buffer-name buffer))))
1723 (apply-partially 'completion-table-with-predicate 1717 (apply-partially 'completion-table-with-predicate
1724 'internal-complete-buffer 1718 'internal-complete-buffer
1725 (lambda (name) 1719 (lambda (name)
@@ -1791,10 +1785,9 @@ Return the new suffix."
1791 (substring afterpoint 0 (cdr bounds))))) 1785 (substring afterpoint 0 (cdr bounds)))))
1792 1786
1793(defun completion-basic-try-completion (string table pred point) 1787(defun completion-basic-try-completion (string table pred point)
1794 (lexical-let* 1788 (let* ((beforepoint (substring string 0 point))
1795 ((beforepoint (substring string 0 point)) 1789 (afterpoint (substring string point))
1796 (afterpoint (substring string point)) 1790 (bounds (completion-boundaries beforepoint table pred afterpoint)))
1797 (bounds (completion-boundaries beforepoint table pred afterpoint)))
1798 (if (zerop (cdr bounds)) 1791 (if (zerop (cdr bounds))
1799 ;; `try-completion' may return a subtly different result 1792 ;; `try-completion' may return a subtly different result
1800 ;; than `all+merge', so try to use it whenever possible. 1793 ;; than `all+merge', so try to use it whenever possible.
@@ -1805,30 +1798,28 @@ Return the new suffix."
1805 (concat completion 1798 (concat completion
1806 (completion--merge-suffix completion point afterpoint)) 1799 (completion--merge-suffix completion point afterpoint))
1807 (length completion)))) 1800 (length completion))))
1808 (lexical-let* 1801 (let* ((suffix (substring afterpoint (cdr bounds)))
1809 ((suffix (substring afterpoint (cdr bounds))) 1802 (prefix (substring beforepoint 0 (car bounds)))
1810 (prefix (substring beforepoint 0 (car bounds))) 1803 (pattern (delete
1811 (pattern (delete 1804 "" (list (substring beforepoint (car bounds))
1812 "" (list (substring beforepoint (car bounds)) 1805 'point
1813 'point 1806 (substring afterpoint 0 (cdr bounds)))))
1814 (substring afterpoint 0 (cdr bounds))))) 1807 (all (completion-pcm--all-completions prefix pattern table pred)))
1815 (all (completion-pcm--all-completions prefix pattern table pred)))
1816 (if minibuffer-completing-file-name 1808 (if minibuffer-completing-file-name
1817 (setq all (completion-pcm--filename-try-filter all))) 1809 (setq all (completion-pcm--filename-try-filter all)))
1818 (completion-pcm--merge-try pattern all prefix suffix))))) 1810 (completion-pcm--merge-try pattern all prefix suffix)))))
1819 1811
1820(defun completion-basic-all-completions (string table pred point) 1812(defun completion-basic-all-completions (string table pred point)
1821 (lexical-let* 1813 (let* ((beforepoint (substring string 0 point))
1822 ((beforepoint (substring string 0 point)) 1814 (afterpoint (substring string point))
1823 (afterpoint (substring string point)) 1815 (bounds (completion-boundaries beforepoint table pred afterpoint))
1824 (bounds (completion-boundaries beforepoint table pred afterpoint)) 1816 (suffix (substring afterpoint (cdr bounds)))
1825 (suffix (substring afterpoint (cdr bounds))) 1817 (prefix (substring beforepoint 0 (car bounds)))
1826 (prefix (substring beforepoint 0 (car bounds))) 1818 (pattern (delete
1827 (pattern (delete 1819 "" (list (substring beforepoint (car bounds))
1828 "" (list (substring beforepoint (car bounds)) 1820 'point
1829 'point 1821 (substring afterpoint 0 (cdr bounds)))))
1830 (substring afterpoint 0 (cdr bounds))))) 1822 (all (completion-pcm--all-completions prefix pattern table pred)))
1831 (all (completion-pcm--all-completions prefix pattern table pred)))
1832 (completion-hilit-commonality all point (car bounds)))) 1823 (completion-hilit-commonality all point (car bounds))))
1833 1824
1834;;; Partial-completion-mode style completion. 1825;;; Partial-completion-mode style completion.
@@ -1991,13 +1982,12 @@ POINT is a position inside STRING.
1991FILTER is a function applied to the return value, that can be used, e.g. to 1982FILTER is a function applied to the return value, that can be used, e.g. to
1992filter out additional entries (because TABLE migth not obey PRED)." 1983filter out additional entries (because TABLE migth not obey PRED)."
1993 (unless filter (setq filter 'identity)) 1984 (unless filter (setq filter 'identity))
1994 (lexical-let* 1985 (let* ((beforepoint (substring string 0 point))
1995 ((beforepoint (substring string 0 point)) 1986 (afterpoint (substring string point))
1996 (afterpoint (substring string point)) 1987 (bounds (completion-boundaries beforepoint table pred afterpoint))
1997 (bounds (completion-boundaries beforepoint table pred afterpoint)) 1988 (prefix (substring beforepoint 0 (car bounds)))
1998 (prefix (substring beforepoint 0 (car bounds))) 1989 (suffix (substring afterpoint (cdr bounds)))
1999 (suffix (substring afterpoint (cdr bounds))) 1990 firsterror)
2000 firsterror)
2001 (setq string (substring string (car bounds) (+ point (cdr bounds)))) 1991 (setq string (substring string (car bounds) (+ point (cdr bounds))))
2002 (let* ((relpoint (- point (car bounds))) 1992 (let* ((relpoint (- point (car bounds)))
2003 (pattern (completion-pcm--string->pattern string relpoint)) 1993 (pattern (completion-pcm--string->pattern string relpoint))