aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/subr.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el61
1 files changed, 58 insertions, 3 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index b322bce3fb1..2b631b17e20 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -957,6 +957,43 @@ other hooks, such as major mode hooks, can do the job."
957 (append (symbol-value list-var) (list element)) 957 (append (symbol-value list-var) (list element))
958 (cons element (symbol-value list-var)))))) 958 (cons element (symbol-value list-var))))))
959 959
960
961(defun add-to-ordered-list (list-var element &optional order)
962 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
963The test for presence of ELEMENT is done with `equal'.
964
965The resulting list is reordered so that the elements are in the
966order given by each element's numeric list order. Elements which
967are not symbols, and symbol elements without a numeric list order
968are placed at the end of the list.
969
970If the third optional argument ORDER is non-nil and ELEMENT is
971a symbol, set the symbol's list order to the given value.
972
973The list order for each symbol is stored in LIST-VAR's
974`list-order' property.
975
976The return value is the new value of LIST-VAR."
977 (let* ((ordering (get list-var 'list-order))
978 (cur (and (symbolp element) (assq element ordering))))
979 (when order
980 (unless (symbolp element)
981 (error "cannot specify order for non-symbols"))
982 (if cur
983 (setcdr cur order)
984 (setq cur (cons element order))
985 (setq ordering (cons cur ordering))
986 (put list-var 'list-order ordering)))
987 (add-to-list list-var element)
988 (set list-var (sort (symbol-value list-var)
989 (lambda (a b)
990 (let ((oa (and (symbolp a) (assq a ordering)))
991 (ob (and (symbolp b) (assq b ordering))))
992 (cond
993 ((not oa) nil)
994 ((not ob) t)
995 (t (< (cdr oa) (cdr ob))))))))))
996
960 997
961;;; Load history 998;;; Load history
962 999
@@ -1561,7 +1598,7 @@ Strip text properties from the inserted text according to
1561`yank-excluded-properties'. Otherwise just like (insert STRING). 1598`yank-excluded-properties'. Otherwise just like (insert STRING).
1562 1599
1563If STRING has a non-nil `yank-handler' property on the first character, 1600If STRING has a non-nil `yank-handler' property on the first character,
1564the normal insert behaviour is modified in various ways. The value of 1601the normal insert behavior is modified in various ways. The value of
1565the yank-handler property must be a list with one to five elements 1602the yank-handler property must be a list with one to five elements
1566with the following format: (FUNCTION PARAM NOEXCLUDE UNDO). 1603with the following format: (FUNCTION PARAM NOEXCLUDE UNDO).
1567When FUNCTION is present and non-nil, it is called instead of `insert' 1604When FUNCTION is present and non-nil, it is called instead of `insert'
@@ -1935,6 +1972,7 @@ entered.
1935The result of the `dynamic-completion-table' form is a function 1972The result of the `dynamic-completion-table' form is a function
1936that can be used as the ALIST argument to `try-completion' and 1973that can be used as the ALIST argument to `try-completion' and
1937`all-completion'. See Info node `(elisp)Programmed Completion'." 1974`all-completion'. See Info node `(elisp)Programmed Completion'."
1975 (declare (debug (lambda-expr)))
1938 (let ((win (make-symbol "window")) 1976 (let ((win (make-symbol "window"))
1939 (string (make-symbol "string")) 1977 (string (make-symbol "string"))
1940 (predicate (make-symbol "predicate")) 1978 (predicate (make-symbol "predicate"))
@@ -1956,12 +1994,29 @@ ARGS. FUN must return the completion table that will be stored in VAR.
1956If completion is requested in the minibuffer, FUN will be called in the buffer 1994If completion is requested in the minibuffer, FUN will be called in the buffer
1957from which the minibuffer was entered. The return value of 1995from which the minibuffer was entered. The return value of
1958`lazy-completion-table' must be used to initialize the value of VAR." 1996`lazy-completion-table' must be used to initialize the value of VAR."
1997 (declare (debug (symbol lambda-expr def-body)))
1959 (let ((str (make-symbol "string"))) 1998 (let ((str (make-symbol "string")))
1960 `(dynamic-completion-table 1999 `(dynamic-completion-table
1961 (lambda (,str) 2000 (lambda (,str)
1962 (unless (listp ,var) 2001 (unless (listp ,var)
1963 (setq ,var (funcall ',fun ,@args))) 2002 (setq ,var (,fun ,@args)))
1964 ,var)))) 2003 ,var))))
2004
2005(defmacro complete-in-turn (a b)
2006 "Create a completion table that first tries completion in A and then in B.
2007A and B should not be costly (or side-effecting) expressions."
2008 (declare (debug (def-form def-form)))
2009 `(lambda (string predicate mode)
2010 (cond
2011 ((eq mode t)
2012 (or (all-completions string ,a predicate)
2013 (all-completions string ,b predicate)))
2014 ((eq mode nil)
2015 (or (try-completion string ,a predicate)
2016 (try-completion string ,b predicate)))
2017 (t
2018 (or (test-completion string ,a predicate)
2019 (test-completion string ,b predicate))))))
1965 2020
1966;;; Matching and substitution 2021;;; Matching and substitution
1967 2022
@@ -1982,7 +2037,7 @@ The value returned is the value of the last form in BODY."
1982 '((save-match-data-internal (match-data))) 2037 '((save-match-data-internal (match-data)))
1983 (list 'unwind-protect 2038 (list 'unwind-protect
1984 (cons 'progn body) 2039 (cons 'progn body)
1985 '(set-match-data save-match-data-internal)))) 2040 '(set-match-data save-match-data-internal 'evaporate))))
1986 2041
1987(defun match-string (num &optional string) 2042(defun match-string (num &optional string)
1988 "Return string of text matched by last search. 2043 "Return string of text matched by last search.