unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* what can I do with regexp match?
@ 2007-05-14 12:36 Seweryn Kokot
  2007-05-14 12:42 ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 12:36 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I would like to have a function that visits all the tex files included
in main.tex file. I wrote the following function:
(defun my-document-files ()
  "Open all document files"
  (interactive)
  (while (re-search-forward "\\\\include{\\(.*\\)}")
	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))

But it doesn't work since \\1 is not replaced by regexp match. The
result is that the function visits \1.tex file. The question is how to
process the regexp match to make it argument for find-file or more
general question how to save the match in a variable or list?

regards,
Seweryn Kokot

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

* Re: what can I do with regexp match?
  2007-05-14 12:36 what can I do with regexp match? Seweryn Kokot
@ 2007-05-14 12:42 ` Lennart Borgman (gmail)
  2007-05-14 13:17   ` Seweryn Kokot
  0 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2007-05-14 12:42 UTC (permalink / raw)
  To: Seweryn Kokot; +Cc: help-gnu-emacs

Seweryn Kokot wrote:
> Hello,
> 
> I would like to have a function that visits all the tex files included
> in main.tex file. I wrote the following function:
> (defun my-document-files ()
>   "Open all document files"
>   (interactive)
>   (while (re-search-forward "\\\\include{\\(.*\\)}")
> 	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))
> 
> But it doesn't work since \\1 is not replaced by regexp match. The
> result is that the function visits \1.tex file. The question is how to
> process the regexp match to make it argument for find-file or more
> general question how to save the match in a variable or list?


(match-string 1) ;; At least in Emacs 22

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

* Re: what can I do with regexp match?
  2007-05-14 12:42 ` Lennart Borgman (gmail)
@ 2007-05-14 13:17   ` Seweryn Kokot
  2007-05-14 15:09     ` Lennart Borgman (gmail)
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 13:17 UTC (permalink / raw)
  To: help-gnu-emacs

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

> Seweryn Kokot wrote:
>> Hello,
>>
>> I would like to have a function that visits all the tex files included
>> in main.tex file. I wrote the following function:
>> (defun my-document-files ()
>>   "Open all document files"
>>   (interactive)
>>   (while (re-search-forward "\\\\include{\\(.*\\)}")
>> 	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))
>>
>> But it doesn't work since \\1 is not replaced by regexp match. The
>> result is that the function visits \1.tex file. The question is how to
>> process the regexp match to make it argument for find-file or more
>> general question how to save the match in a variable or list?
>
>
> (match-string 1) ;; At least in Emacs 22
Thanks, the prolbem with \1 is solved but then the function only finds
first occurrence of \include{filename} and then I get in the echo buffer: 
while: Search failed: "\\\\include{\\(.*\\)}"

Now my function is:
(defun my-document-files ()
  "Open all document files"
  (interactive)
  (while (re-search-forward "\\\\include{\\(.*\\)}")
	 (find-file (concat "~/nauka/doktorat/thesis/" (match-string 1) ".tex"))))

why it failed although I have much more occurences of \include{...} in
the main.tex file? Any idea?

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

* Re: what can I do with regexp match?
  2007-05-14 13:17   ` Seweryn Kokot
@ 2007-05-14 15:09     ` Lennart Borgman (gmail)
  2007-05-14 17:07       ` Seweryn Kokot
  2007-05-14 15:36     ` Michaël Cadilhac
       [not found]     ` <mailman.649.1179157491.32220.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2007-05-14 15:09 UTC (permalink / raw)
  To: Seweryn Kokot; +Cc: help-gnu-emacs

Seweryn Kokot wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> 
>> Seweryn Kokot wrote:
>>> Hello,
>>>
>>> I would like to have a function that visits all the tex files included
>>> in main.tex file. I wrote the following function:
>>> (defun my-document-files ()
>>>   "Open all document files"
>>>   (interactive)
>>>   (while (re-search-forward "\\\\include{\\(.*\\)}")
>>> 	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))
>>>
>>> But it doesn't work since \\1 is not replaced by regexp match. The
>>> result is that the function visits \1.tex file. The question is how to
>>> process the regexp match to make it argument for find-file or more
>>> general question how to save the match in a variable or list?
>>
>> (match-string 1) ;; At least in Emacs 22
> Thanks, the prolbem with \1 is solved but then the function only finds
> first occurrence of \include{filename} and then I get in the echo buffer: 
> while: Search failed: "\\\\include{\\(.*\\)}"
> 
> Now my function is:
> (defun my-document-files ()
>   "Open all document files"
>   (interactive)
>   (while (re-search-forward "\\\\include{\\(.*\\)}")
> 	 (find-file (concat "~/nauka/doktorat/thesis/" (match-string 1) ".tex"))))
> 
> why it failed although I have much more occurences of \include{...} in
> the main.tex file? Any idea?

Read the documentation for find-file.

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

* Re: what can I do with regexp match?
  2007-05-14 13:17   ` Seweryn Kokot
  2007-05-14 15:09     ` Lennart Borgman (gmail)
@ 2007-05-14 15:36     ` Michaël Cadilhac
       [not found]     ` <mailman.649.1179157491.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Michaël Cadilhac @ 2007-05-14 15:36 UTC (permalink / raw)
  To: Seweryn Kokot; +Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 804 bytes --]

Seweryn Kokot <s.kokot@po.opole.pl> writes:

> Now my function is:
> (defun my-document-files ()
>   "Open all document files"
>   (interactive)
>   (while (re-search-forward "\\\\include{\\(.*\\)}")
> 	 (find-file (concat "~/nauka/doktorat/thesis/" (match-string 1) ".tex"))))
>
> why it failed although I have much more occurences of \include{...} in
> the main.tex file? Any idea?

See the documentation for `find-file', and maybe use
`save-window-excursion'.

-- 
 |   Michaël `Micha' Cadilhac       |  All your base are belong to us.       |
 |   http://michael.cadilhac.name   |    You have no chance to survive       |
 |   JID/MSN:                       |       make your time, hahaha.          |
 `----  michael.cadilhac@gmail.com  |       -- Zero Wings               -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: what can I do with regexp match?
  2007-05-14 15:09     ` Lennart Borgman (gmail)
@ 2007-05-14 17:07       ` Seweryn Kokot
  2007-05-14 17:14         ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 17:07 UTC (permalink / raw)
  To: help-gnu-emacs

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

>> Now my function is:
>> (defun my-document-files ()
>>   "Open all document files"
>>   (interactive)
>>   (while (re-search-forward "\\\\include{\\(.*\\)}")
>> 	 (find-file (concat "~/" (match-string 1) ".tex"))))
>>
>> why it failed although I have much more occurences of \include{...} in
>> the main.tex file? Any idea?
>
> Read the documentation for find-file.
Ok I see the problem I wonder if it would be better first to read a
buffer to a variable, then to search regexp, then assign matches to a
list and finally visit files from the list using dolist? But the problem
is how to create a list from regexp matches?

(defun my-document-files ()
  ""
  (interactive)
  (save-excursion
	 (let ((bufor (buffer-substring-no-properties (point-min) (point-max)))
			 pliki wartosc)
		(string-match "\\\\include{\\(.*?\\)}" bufor)
		(setq (match-string 0) pliki)
		(dolist (plik pliki wartosc)
		  (find-file (concat "~/foo/" plik ".tex"))))))

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

* Re: what can I do with regexp match?
  2007-05-14 17:07       ` Seweryn Kokot
@ 2007-05-14 17:14         ` Lennart Borgman (gmail)
  2007-05-14 17:46           ` Seweryn Kokot
  0 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2007-05-14 17:14 UTC (permalink / raw)
  To: Seweryn Kokot; +Cc: help-gnu-emacs

Seweryn Kokot wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> 
>>> Now my function is:
>>> (defun my-document-files ()
>>>   "Open all document files"
>>>   (interactive)
>>>   (while (re-search-forward "\\\\include{\\(.*\\)}")
>>> 	 (find-file (concat "~/" (match-string 1) ".tex"))))
>>>
>>> why it failed although I have much more occurences of \include{...} in
>>> the main.tex file? Any idea?
>> Read the documentation for find-file.
> Ok I see the problem I wonder if it would be better first to read a
> buffer to a variable, then to search regexp, then assign matches to a
> list and finally visit files from the list using dolist? But the problem
> is how to create a list from regexp matches?


It does not really matter if you use find-file-noselect or create a list 
for this particular problem. The most easy way to build a list is 
perhaps this:

   (add-to-list 'my-list (match-string 1))

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

* Re: what can I do with regexp match?
       [not found] <mailman.635.1179146680.32220.help-gnu-emacs@gnu.org>
@ 2007-05-14 17:38 ` David Kastrup
  2007-05-14 20:17   ` Seweryn Kokot
  2007-05-14 19:01 ` Ralf Angeli
  1 sibling, 1 reply; 14+ messages in thread
From: David Kastrup @ 2007-05-14 17:38 UTC (permalink / raw)
  To: help-gnu-emacs

Seweryn Kokot <skokot@po.opole.pl> writes:

> Hello,
>
> I would like to have a function that visits all the tex files included
> in main.tex file. I wrote the following function:
> (defun my-document-files ()
>   "Open all document files"
>   (interactive)
>   (while (re-search-forward "\\\\include{\\(.*\\)}")
> 	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))
>
> But it doesn't work since \\1 is not replaced by regexp match. The
> result is that the function visits \1.tex file. The question is how to
> process the regexp match to make it argument for find-file or more
> general question how to save the match in a variable or list?

You know
M-x reftex-query-replace-document RET ?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: what can I do with regexp match?
  2007-05-14 17:14         ` Lennart Borgman (gmail)
@ 2007-05-14 17:46           ` Seweryn Kokot
  0 siblings, 0 replies; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 17:46 UTC (permalink / raw)
  To: help-gnu-emacs

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> It does not really matter if you use find-file-noselect or create a
> list for this particular problem. The most easy way to build a list is
> perhaps this:
>
>   (add-to-list 'my-list (match-string 1))
In fact, both versions work.
Thanks a lot for help!

regards
Seweryn

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

* Re: what can I do with regexp match?
       [not found] <mailman.635.1179146680.32220.help-gnu-emacs@gnu.org>
  2007-05-14 17:38 ` David Kastrup
@ 2007-05-14 19:01 ` Ralf Angeli
  2007-05-14 20:06   ` Seweryn Kokot
  1 sibling, 1 reply; 14+ messages in thread
From: Ralf Angeli @ 2007-05-14 19:01 UTC (permalink / raw)
  To: help-gnu-emacs

* Seweryn Kokot (2007-05-14) writes:

> I would like to have a function that visits all the tex files included
> in main.tex file.

Why?

-- 
Ralf

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

* Re: what can I do with regexp match?
  2007-05-14 19:01 ` Ralf Angeli
@ 2007-05-14 20:06   ` Seweryn Kokot
  0 siblings, 0 replies; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 20:06 UTC (permalink / raw)
  To: help-gnu-emacs

Ralf Angeli <dev.null@caeruleus.net> writes:
> * Seweryn Kokot (2007-05-14) writes:
>
>> I would like to have a function that visits all the tex files included
>> in main.tex file.
>
> Why?
Because from time to time I need to check spelling of all document files with 
C-c C-c Spell and this requires all files visited.

Seweryn Kokot

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

* Re: what can I do with regexp match?
  2007-05-14 17:38 ` David Kastrup
@ 2007-05-14 20:17   ` Seweryn Kokot
  2007-05-14 20:33     ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 14+ messages in thread
From: Seweryn Kokot @ 2007-05-14 20:17 UTC (permalink / raw)
  To: help-gnu-emacs

David Kastrup <dak@gnu.org> writes:

> Seweryn Kokot <skokot@po.opole.pl> writes:
>
>> Hello,
>>
>> I would like to have a function that visits all the tex files included
>> in main.tex file. I wrote the following function:
>> (defun my-document-files ()
>>   "Open all document files"
>>   (interactive)
>>   (while (re-search-forward "\\\\include{\\(.*\\)}")
>> 	 (find-file (concat "~/nauka/doktorat/thesis/" "\\1" ".tex"))))
>>
>> But it doesn't work since \\1 is not replaced by regexp match. The
>> result is that the function visits \1.tex file. The question is how to
>> process the regexp match to make it argument for find-file or more
>> general question how to save the match in a variable or list?
>
> You know
> M-x reftex-query-replace-document RET ?

I'm a newbie with emacs lisp so I cannot see how it can apply to my
case. Writing an elisp function I'm learning elisp, but it seems that
reftex-query-replace-document is only interactive or am I wrong?

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

* Re: what can I do with regexp match?
  2007-05-14 20:17   ` Seweryn Kokot
@ 2007-05-14 20:33     ` Lennart Borgman (gmail)
  0 siblings, 0 replies; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2007-05-14 20:33 UTC (permalink / raw)
  To: Seweryn Kokot; +Cc: help-gnu-emacs

Seweryn Kokot wrote:

> I'm a newbie with emacs lisp so I cannot see how it can apply to my
> case. Writing an elisp function I'm learning elisp, but it seems that
> reftex-query-replace-document is only interactive or am I wrong?


I do not believe there are any functions that can be called only 
interactively in Emacs. You can call interactive functions like any 
other elisp functions.

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

* Re: what can I do with regexp match?
       [not found]     ` <mailman.649.1179157491.32220.help-gnu-emacs@gnu.org>
@ 2007-06-09 22:01       ` Stefan Monnier
  0 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2007-06-09 22:01 UTC (permalink / raw)
  To: help-gnu-emacs

> See the documentation for `find-file', and maybe use
> `save-window-excursion'.

Please not save-window-excursion.  If you don't want to change windows, then
just don't change them: saving&restoring them is asking for trouble.

`find-file' is an interactive function.  You should basically *never* call
it from elisp.  Always use find-file-noselect instead.


        Stefan

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

end of thread, other threads:[~2007-06-09 22:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-14 12:36 what can I do with regexp match? Seweryn Kokot
2007-05-14 12:42 ` Lennart Borgman (gmail)
2007-05-14 13:17   ` Seweryn Kokot
2007-05-14 15:09     ` Lennart Borgman (gmail)
2007-05-14 17:07       ` Seweryn Kokot
2007-05-14 17:14         ` Lennart Borgman (gmail)
2007-05-14 17:46           ` Seweryn Kokot
2007-05-14 15:36     ` Michaël Cadilhac
     [not found]     ` <mailman.649.1179157491.32220.help-gnu-emacs@gnu.org>
2007-06-09 22:01       ` Stefan Monnier
     [not found] <mailman.635.1179146680.32220.help-gnu-emacs@gnu.org>
2007-05-14 17:38 ` David Kastrup
2007-05-14 20:17   ` Seweryn Kokot
2007-05-14 20:33     ` Lennart Borgman (gmail)
2007-05-14 19:01 ` Ralf Angeli
2007-05-14 20:06   ` Seweryn Kokot

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).