# HG changeset patch # User Didier Verna # Date 1304177915 -7200 # Node ID 1e544fd7be12682d959a810d0970e29107669a3f # Parent dc37764a105b014b027ed314413c3aa4af74b722 Import looking-back from GNU Emacs. -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2011-04-30 Didier Verna * subr.el (looking-back): New function. diff -r dc37764a105b -r 1e544fd7be12 lisp/ChangeLog --- a/lisp/ChangeLog Sat Apr 30 17:29:47 2011 +0200 +++ b/lisp/ChangeLog Sat Apr 30 17:38:35 2011 +0200 @@ -1,3 +1,7 @@ +2011-04-30 Didier Verna + + * subr.el (looking-back): New function. + 2011-04-30 Didier Verna * special-mode.el: New file. diff -r dc37764a105b -r 1e544fd7be12 lisp/subr.el --- a/lisp/subr.el Sat Apr 30 17:29:47 2011 +0200 +++ b/lisp/subr.el Sat Apr 30 17:38:35 2011 +0200 @@ -732,6 +732,38 @@ (buffer-substring-no-properties (match-beginning num) (match-end num))))) +;; Imported from GNU Emacs 23.3.1 -- dvl +(defun looking-back (regexp &optional limit greedy) + "Return non-nil if text before point matches regular expression REGEXP. +Like `looking-at' except matches before point, and is slower. +LIMIT if non-nil speeds up the search by specifying a minimum +starting position, to avoid checking matches that would start +before LIMIT. + +If GREEDY is non-nil, extend the match backwards as far as +possible, stopping when a single additional previous character +cannot be part of a match for REGEXP. When the match is +extended, its starting position is allowed to occur before +LIMIT." + (let ((start (point)) + (pos + (save-excursion + (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t) + (point))))) + (if (and greedy pos) + (save-restriction + (narrow-to-region (point-min) start) + (while (and (> pos (point-min)) + (save-excursion + (goto-char pos) + (backward-char 1) + (looking-at (concat "\\(?:" regexp "\\)\\'")))) + (setq pos (1- pos))) + (save-excursion + (goto-char pos) + (looking-at (concat "\\(?:" regexp "\\)\\'"))))) + (not (null pos)))) + (defconst split-string-default-separators "[ \f\t\n\r\v]+" "The default value of separators for `split-string'.