diff options
| -rw-r--r-- | lisp/subr.el | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 63951b92bb2..45bcccbb6e5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1996,14 +1996,34 @@ STRING should be given if the last search was by `string-match' on STRING." | |||
| 1996 | (buffer-substring-no-properties (match-beginning num) | 1996 | (buffer-substring-no-properties (match-beginning num) |
| 1997 | (match-end num))))) | 1997 | (match-end num))))) |
| 1998 | 1998 | ||
| 1999 | (defun looking-back (regexp &optional limit) | 1999 | (defun looking-back (regexp &optional limit greedy) |
| 2000 | "Return non-nil if text before point matches regular expression REGEXP. | 2000 | "Return non-nil if text before point matches regular expression REGEXP. |
| 2001 | Like `looking-at' except matches before point, and is slower. | 2001 | Like `looking-at' except matches before point, and is slower. |
| 2002 | LIMIT if non-nil speeds up the search by specifying how far back the | 2002 | LIMIT if non-nil speeds up the search by specifying how far back the |
| 2003 | match can start." | 2003 | match can start. |
| 2004 | (not (null | 2004 | |
| 2005 | (save-excursion | 2005 | If GREEDY is non-nil, extend the match backwards as far as possible, |
| 2006 | (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))) | 2006 | stopping when a single additional previous character cannot be part |
| 2007 | of a match for REGEXP." | ||
| 2008 | (let ((start (point)) | ||
| 2009 | (pos | ||
| 2010 | (save-excursion | ||
| 2011 | (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t) | ||
| 2012 | (point))))) | ||
| 2013 | (if (and greedy pos) | ||
| 2014 | (save-restriction | ||
| 2015 | (narrow-to-region (point-min) start) | ||
| 2016 | (while (and (> pos (point-min)) | ||
| 2017 | (save-excursion | ||
| 2018 | (goto-char pos) | ||
| 2019 | (backward-char 1) | ||
| 2020 | (looking-at (concat "\\(?:" regexp "\\)\\'")))) | ||
| 2021 | (setq pos (1- pos))) | ||
| 2022 | (save-excursion | ||
| 2023 | (goto-char pos) | ||
| 2024 | (looking-at (concat "\\(?:" regexp "\\)\\'"))))) | ||
| 2025 | (not (null pos)))) | ||
| 2026 | |||
| 2007 | 2027 | ||
| 2008 | (defconst split-string-default-separators "[ \f\t\n\r\v]+" | 2028 | (defconst split-string-default-separators "[ \f\t\n\r\v]+" |
| 2009 | "The default value of separators for `split-string'. | 2029 | "The default value of separators for `split-string'. |