Mercurial > hg > xemacs-beta
comparison lisp/subr.el @ 5488:1e544fd7be12
Import looking-back from GNU Emacs.
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2011-04-30 Didier Verna <didier@xemacs.org>
* subr.el (looking-back): New function.
author | Didier Verna <didier@lrde.epita.fr> |
---|---|
date | Sat, 30 Apr 2011 17:38:35 +0200 |
parents | ac37a5f7e5be |
children | d3e0482c7899 |
comparison
equal
deleted
inserted
replaced
5487:dc37764a105b | 5488:1e544fd7be12 |
---|---|
729 (substring string (match-beginning num) (match-end num)))) | 729 (substring string (match-beginning num) (match-end num)))) |
730 (set-text-properties 0 (length result) nil result) | 730 (set-text-properties 0 (length result) nil result) |
731 result) | 731 result) |
732 (buffer-substring-no-properties (match-beginning num) | 732 (buffer-substring-no-properties (match-beginning num) |
733 (match-end num))))) | 733 (match-end num))))) |
734 | |
735 ;; Imported from GNU Emacs 23.3.1 -- dvl | |
736 (defun looking-back (regexp &optional limit greedy) | |
737 "Return non-nil if text before point matches regular expression REGEXP. | |
738 Like `looking-at' except matches before point, and is slower. | |
739 LIMIT if non-nil speeds up the search by specifying a minimum | |
740 starting position, to avoid checking matches that would start | |
741 before LIMIT. | |
742 | |
743 If GREEDY is non-nil, extend the match backwards as far as | |
744 possible, stopping when a single additional previous character | |
745 cannot be part of a match for REGEXP. When the match is | |
746 extended, its starting position is allowed to occur before | |
747 LIMIT." | |
748 (let ((start (point)) | |
749 (pos | |
750 (save-excursion | |
751 (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t) | |
752 (point))))) | |
753 (if (and greedy pos) | |
754 (save-restriction | |
755 (narrow-to-region (point-min) start) | |
756 (while (and (> pos (point-min)) | |
757 (save-excursion | |
758 (goto-char pos) | |
759 (backward-char 1) | |
760 (looking-at (concat "\\(?:" regexp "\\)\\'")))) | |
761 (setq pos (1- pos))) | |
762 (save-excursion | |
763 (goto-char pos) | |
764 (looking-at (concat "\\(?:" regexp "\\)\\'"))))) | |
765 (not (null pos)))) | |
734 | 766 |
735 (defconst split-string-default-separators "[ \f\t\n\r\v]+" | 767 (defconst split-string-default-separators "[ \f\t\n\r\v]+" |
736 "The default value of separators for `split-string'. | 768 "The default value of separators for `split-string'. |
737 | 769 |
738 A regexp matching strings of whitespace. May be locale-dependent | 770 A regexp matching strings of whitespace. May be locale-dependent |