aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2005-05-29 08:34:46 +0000
committerRichard M. Stallman2005-05-29 08:34:46 +0000
commit46065dd4a54fa1a056ab4c86f754d0f99aa9be4e (patch)
tree0062432140aa30598486c675a88355c0743f922e
parentc1b1a4f3ef3bbe140ad4db7568e82814f81e2e2e (diff)
downloademacs-46065dd4a54fa1a056ab4c86f754d0f99aa9be4e.tar.gz
emacs-46065dd4a54fa1a056ab4c86f754d0f99aa9be4e.zip
(looking-back): New argument GREEDY.
-rw-r--r--lisp/subr.el30
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.
2001Like `looking-at' except matches before point, and is slower. 2001Like `looking-at' except matches before point, and is slower.
2002LIMIT if non-nil speeds up the search by specifying how far back the 2002LIMIT if non-nil speeds up the search by specifying how far back the
2003match can start." 2003match can start.
2004 (not (null 2004
2005 (save-excursion 2005If GREEDY is non-nil, extend the match backwards as far as possible,
2006 (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))) 2006stopping when a single additional previous character cannot be part
2007of 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'.