unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5689: looking-back-p
@ 2010-03-06 18:29 Devon Sean McCullough
  2010-03-06 21:21 ` Stefan Monnier
  2010-03-07 12:17 ` Andreas Röhler
  0 siblings, 2 replies; 3+ messages in thread
From: Devon Sean McCullough @ 2010-03-06 18:29 UTC (permalink / raw)
  To: 5689

Please include the missing looking-back-p
either as a subst like looking-at-p and string-match-p

--- lisp/subr.el.~1.667.~	2009-11-24 22:59:23.000000000 -0500
+++ lisp/subr.el	2010-03-06 12:52:30.000000000 -0500
@@ -2984,6 +2984,12 @@
   (let ((inhibit-changing-match-data t))
     (looking-at regexp)))
 
+(defsubst looking-back-p (regexp &optional limit greedy)
+  "\
+Same as `looking-back' except this saves the match data."
+  (save-match-data
+    (looking-back regexp limit greedy)))
+
 (defsubst string-match-p (regexp string &optional start)
   "\
 Same as `string-match' except this function does not change the match data."

or as a macro like

--- lisp/subr.el.~1.667.~	2009-11-24 22:59:23.000000000 -0500
+++ lisp/subr.el	2010-03-06 13:18:53.000000000 -0500
@@ -2984,6 +2984,14 @@
   (let ((inhibit-changing-match-data t))
     (looking-at regexp)))
 
+(defmacro looking-back-p (&rest args)
+  "\
+Same as `looking-back' except this saves the match data.
+
+\(fn REGEXP &optional LIMIT GREEDY)"
+  `(save-match-data
+     (looking-back .,args)))
+
 (defsubst string-match-p (regexp string &optional start)
   "\
 Same as `string-match' except this function does not change the match data."





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#5689: looking-back-p
  2010-03-06 18:29 bug#5689: looking-back-p Devon Sean McCullough
@ 2010-03-06 21:21 ` Stefan Monnier
  2010-03-07 12:17 ` Andreas Röhler
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2010-03-06 21:21 UTC (permalink / raw)
  To: Devon Sean McCullough; +Cc: 5689

> Please include the missing looking-back-p

looking-back is a function that people should generally try to avoid,
because it's very costly and its behavior is not always as people
might expect.  So if anything, I'd rename it to
do-something-like-looking-at-but-going-backward and would definitely
refrain from providing a "-p" alternative that would make it sound like
"it's more lightweight" even tho it's actually even worse (tho
unnoticeably so).



        Stefan








^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#5689: looking-back-p
  2010-03-06 18:29 bug#5689: looking-back-p Devon Sean McCullough
  2010-03-06 21:21 ` Stefan Monnier
@ 2010-03-07 12:17 ` Andreas Röhler
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Röhler @ 2010-03-07 12:17 UTC (permalink / raw)
  To: Devon Sean McCullough; +Cc: 5689

Devon Sean McCullough wrote:
> Please include the missing looking-back-p
> either as a subst like looking-at-p and string-match-p
> 
> --- lisp/subr.el.~1.667.~	2009-11-24 22:59:23.000000000 -0500
> +++ lisp/subr.el	2010-03-06 12:52:30.000000000 -0500
> @@ -2984,6 +2984,12 @@
>    (let ((inhibit-changing-match-data t))
>      (looking-at regexp)))
>  
> +(defsubst looking-back-p (regexp &optional limit greedy)
> +  "\
> +Same as `looking-back' except this saves the match data."
> +  (save-match-data
> +    (looking-back regexp limit greedy)))
> +
>  (defsubst string-match-p (regexp string &optional start)
>    "\
>  Same as `string-match' except this function does not change the match data."
> 
> or as a macro like
> 
> --- lisp/subr.el.~1.667.~	2009-11-24 22:59:23.000000000 -0500
> +++ lisp/subr.el	2010-03-06 13:18:53.000000000 -0500
> @@ -2984,6 +2984,14 @@
>    (let ((inhibit-changing-match-data t))
>      (looking-at regexp)))
>  
> +(defmacro looking-back-p (&rest args)
> +  "\
> +Same as `looking-back' except this saves the match data.
> +
> +\(fn REGEXP &optional LIMIT GREEDY)"
> +  `(save-match-data
> +     (looking-back .,args)))
> +
>  (defsubst string-match-p (regexp string &optional start)
>    "\
>  Same as `string-match' except this function does not change the match data."
> 
> 
> 
> 


Hi Devon,

thanks a lot.

As a change usually has pros and cons, just my personal
view:

`save-match-data' changes the way of execution, I'd
like to see it expressingly.

Think code is pretty good readable as it's now.

Andreas







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-07 12:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-06 18:29 bug#5689: looking-back-p Devon Sean McCullough
2010-03-06 21:21 ` Stefan Monnier
2010-03-07 12:17 ` Andreas Röhler

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).