changeset 51339:14976a545668

(looking-back): New function to check for regular expression before point.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 30 May 2003 23:11:35 +0000
parents 950cb49c5824
children bd66b46adcc8
files lisp/subr.el
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Fri May 30 22:00:20 2003 +0000
+++ b/lisp/subr.el	Fri May 30 23:11:35 2003 +0000
@@ -1820,6 +1820,19 @@
 	(buffer-substring-no-properties (match-beginning num)
 					(match-end num)))))
 
+(defun looking-back (regexp)
+  "Return t if text before point matches regular expression REGEXP.
+This function modifies the match data that `match-beginning',
+`match-end' and `match-data' access; save and restore the match
+data if you want to preserve them."
+  (save-excursion
+    (let ((beg (point)))
+      (if (re-search-backward regexp nil t)
+	  (if (= (match-end 0) beg)
+	      t
+	    nil)
+	nil))))
+
 (defconst split-string-default-separators "[ \f\t\n\r\v]+"
   "The default value of separators for `split-string'.