(progn ,@body)
(mutex-unlock ,sym)))))
+\f
+;;; Apropos.
+
+(defun apropos-internal (regexp &optional predicate)
+ "Show all symbols whose names contain match for REGEXP.
+If optional 2nd arg PREDICATE is non-nil, (funcall PREDICATE SYMBOL) is done
+for each symbol and a symbol is mentioned only if that returns non-nil.
+Return list of symbols found."
+ (let (found)
+ (mapatoms (lambda (symbol)
+ (when (and (string-match regexp (symbol-name symbol))
+ (or (not predicate)
+ (funcall predicate symbol)))
+ (push symbol found))))
+ (sort found #'string-lessp)))
+
\f
;;; Misc.
}
}
\f
-/* Apropos - finding all symbols whose names match a regexp. */
-static Lisp_Object apropos_predicate;
-static Lisp_Object apropos_accumulate;
-
-static void
-apropos_accum (Lisp_Object symbol, Lisp_Object string)
-{
- register Lisp_Object tem;
-
- tem = Fstring_match (string, Fsymbol_name (symbol), Qnil);
- if (!NILP (tem) && !NILP (apropos_predicate))
- tem = call1 (apropos_predicate, symbol);
- if (!NILP (tem))
- apropos_accumulate = Fcons (symbol, apropos_accumulate);
-}
-
-DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0,
- doc: /* Show all symbols whose names contain match for REGEXP.
-If optional 2nd arg PREDICATE is non-nil, (funcall PREDICATE SYMBOL) is done
-for each symbol and a symbol is mentioned only if that returns non-nil.
-Return list of symbols found. */)
- (Lisp_Object regexp, Lisp_Object predicate)
-{
- Lisp_Object tem;
- CHECK_STRING (regexp);
- apropos_predicate = predicate;
- apropos_accumulate = Qnil;
- map_obarray (Vobarray, apropos_accum, regexp);
- tem = Fsort (apropos_accumulate, Qstring_lessp);
- apropos_accumulate = Qnil;
- apropos_predicate = Qnil;
- return tem;
-}
-\f
void
syms_of_keymap (void)
{
DEFSYM (Qkeymap, "keymap");
DEFSYM (Qdescribe_map_tree, "describe-map-tree");
- staticpro (&apropos_predicate);
- staticpro (&apropos_accumulate);
- apropos_predicate = Qnil;
- apropos_accumulate = Qnil;
DEFSYM (Qkeymap_canonicalize, "keymap-canonicalize");
defsubr (&Stext_char_description);
defsubr (&Swhere_is_internal);
defsubr (&Sdescribe_buffer_bindings);
- defsubr (&Sapropos_internal);
}
void
(undo-boundary)
(undo)
(should (equal (buffer-string) ""))))
+\f
+;;; Apropos.
+
+(ert-deftest apropos-apropos-internal ()
+ (should (equal (apropos-internal "^next-line$") '(next-line)))
+ (should (>= (length (apropos-internal "^help")) 100))
+ (should-not (apropos-internal "^test-a-missing-symbol-foo-bar-zot$")))
+
+(ert-deftest apropos-apropos-internal/predicate ()
+ (should (equal (apropos-internal "^next-line$" #'commandp) '(next-line)))
+ (should (>= (length (apropos-internal "^help" #'commandp)) 15))
+ (should-not (apropos-internal "^next-line$" #'keymapp)))
(provide 'subr-tests)
;;; subr-tests.el ends here
0 .. 3 foo
")))))
-\f
-;;;; apropos-internal
-
-(ert-deftest keymap-apropos-internal ()
- (should (equal (apropos-internal "^next-line$") '(next-line)))
- (should (>= (length (apropos-internal "^help")) 100))
- (should-not (apropos-internal "^test-a-missing-symbol-foo-bar-zut$")))
-
-(ert-deftest keymap-apropos-internal/predicate ()
- (should (equal (apropos-internal "^next-line$" #'commandp) '(next-line)))
- (should (>= (length (apropos-internal "^help" #'commandp)) 15))
- (should-not (apropos-internal "^next-line$" #'keymapp)))
-
(provide 'keymap-tests)
;;; keymap-tests.el ends here