all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Strange results from lwarn + match-string
@ 2008-02-19 18:20 Lennart Borgman (gmail)
  2008-02-19 20:51 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2008-02-19 18:20 UTC (permalink / raw)
  To: Emacs Devel

Can anyone see anything wrong with this line:

   (lwarn t :warning "1: %s" (match-string-no-properties 1))

I get some very strange result sometimes. If I use (message ...) instead 
the result looks ok.




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

* Re: Strange results from lwarn + match-string
  2008-02-19 18:20 Strange results from lwarn + match-string Lennart Borgman (gmail)
@ 2008-02-19 20:51 ` Andreas Schwab
  2008-02-19 21:15   ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2008-02-19 20:51 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> Can anyone see anything wrong with this line:
>
>   (lwarn t :warning "1: %s" (match-string-no-properties 1))
>
> I get some very strange result sometimes.

Please define "strange".

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




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

* Re: Strange results from lwarn + match-string
  2008-02-19 20:51 ` Andreas Schwab
@ 2008-02-19 21:15   ` Lennart Borgman (gmail)
  2008-02-19 22:08     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2008-02-19 21:15 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Emacs Devel

Andreas Schwab wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> 
>> Can anyone see anything wrong with this line:
>>
>>   (lwarn t :warning "1: %s" (match-string-no-properties 1))
>>
>> I get some very strange result sometimes.
> 
> Please define "strange".

I was running the function below (I am trying to export to FreeMind). I 
am in the .notes file buffer when I exectute the function. The first 
lines in this file contains

   * Notes
   ** Wed Oct 24 22:13:56 2007 (Output filter for Thunderbird?)

This is what I get:

   Warning (t): 0: * Notes
   Warning (t): 1: t 24
   Warning (t): 2: nil
   Warning (t): 3: nil


Below is the function. I also get some crashes, I believe that was when 
I had `anything' instead of `nonl' in the pattern. There was some other 
strange errors too, but maybe this is enough? I have tested this with 
unpatched Emacs too:

   GNU Emacs 23.0.50.1 (i386-mingw-nt5.1.2600) of 2008-01-27




(defun org2mm-buffer-to-freemind ()
   (interactive)
   (unless (derived-mode-p 'org-mode)
     (error "Not an org-mode buffer"))
   (save-match-data
     (let* ((default-mm-file (concat (file-name-sans-extension
                                      (file-name-nondirectory
                                       (buffer-file-name)))
                                     ".mm"))
            (mm-file (read-file-name "Output FreeMind file: " nil nil 
nil default-mm-file
                                     (lambda (fn)
                                       (string-match "^mm$"
 
(file-name-extension fn)))))
            (node-pattern (rx bol
                              (submatch (1+ "*"))
                              (1+ space)
                              (submatch (*? nonl))
                              eol)))
       (message "%s" mm-file)
       ;;(save-excursion
       (goto-char (point-min))
       (when (re-search-forward node-pattern)
         (lwarn t :warning "0: %s" (match-string-no-properties 0))
         (lwarn t :warning "1: %s" (match-string-no-properties 1))
         (lwarn t :warning "2: %s" (match-string-no-properties 2))
         (lwarn t :warning "3: %s" (match-string-no-properties 3))
         )
       ;;)
       )))




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

* Re: Strange results from lwarn + match-string
  2008-02-19 21:15   ` Lennart Borgman (gmail)
@ 2008-02-19 22:08     ` Stefan Monnier
  2008-02-19 22:22       ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2008-02-19 22:08 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Andreas Schwab, Emacs Devel

>         (lwarn t :warning "0: %s" (match-string-no-properties 0))
>         (lwarn t :warning "1: %s" (match-string-no-properties 1))
>         (lwarn t :warning "2: %s" (match-string-no-properties 2))
>         (lwarn t :warning "3: %s" (match-string-no-properties 3))

Since you don't know for a fact that lwarn is among the few functions
that do not affect match-data, you need to call all
4 `match-string-no-properties' before you call the 4 `lwarn'.


        Stefan




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

* Re: Strange results from lwarn + match-string
  2008-02-19 22:08     ` Stefan Monnier
@ 2008-02-19 22:22       ` Lennart Borgman (gmail)
  2008-02-20  3:39         ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2008-02-19 22:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Andreas Schwab, Emacs Devel

Stefan Monnier wrote:
>>         (lwarn t :warning "0: %s" (match-string-no-properties 0))
>>         (lwarn t :warning "1: %s" (match-string-no-properties 1))
>>         (lwarn t :warning "2: %s" (match-string-no-properties 2))
>>         (lwarn t :warning "3: %s" (match-string-no-properties 3))
> 
> Since you don't know for a fact that lwarn is among the few functions
> that do not affect match-data, you need to call all
> 4 `match-string-no-properties' before you call the 4 `lwarn'.

Hm. It cured the problem, but that was really a surprise.




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

* Re: Strange results from lwarn + match-string
  2008-02-19 22:22       ` Lennart Borgman (gmail)
@ 2008-02-20  3:39         ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2008-02-20  3:39 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Andreas Schwab, Emacs Devel

>>> (lwarn t :warning "0: %s" (match-string-no-properties 0))
>>> (lwarn t :warning "1: %s" (match-string-no-properties 1))
>>> (lwarn t :warning "2: %s" (match-string-no-properties 2))
>>> (lwarn t :warning "3: %s" (match-string-no-properties 3))
>> 
>> Since you don't know for a fact that lwarn is among the few functions
>> that do not affect match-data, you need to call all
>> 4 `match-string-no-properties' before you call the 4 `lwarn'.

> Hm. It cured the problem, but that was really a surprise.

There are very few functions which guarantee that they preserve
match-data, so if there's the slightest doubt, assume that match-data
will be destroyed,


        Stefan




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

end of thread, other threads:[~2008-02-20  3:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-19 18:20 Strange results from lwarn + match-string Lennart Borgman (gmail)
2008-02-19 20:51 ` Andreas Schwab
2008-02-19 21:15   ` Lennart Borgman (gmail)
2008-02-19 22:08     ` Stefan Monnier
2008-02-19 22:22       ` Lennart Borgman (gmail)
2008-02-20  3:39         ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.