]> git.eshelyaron.com Git - emacs.git/commitdiff
(looking-back): New function to check for regular expression before point.
authorJuanma Barranquero <lekktu@gmail.com>
Fri, 30 May 2003 23:11:35 +0000 (23:11 +0000)
committerJuanma Barranquero <lekktu@gmail.com>
Fri, 30 May 2003 23:11:35 +0000 (23:11 +0000)
lisp/subr.el

index c03b2ff0a9880a118a709dbcc92c90a34606009b..2ca79e54b76f5704730a9d0178204ad82fa6693a 100644 (file)
@@ -1820,6 +1820,19 @@ STRING should be given if the last search was by `string-match' on STRING."
        (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'.