all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* eval: (search-forward)
@ 2004-10-09 12:48 Albert Reiner
  2004-10-10 12:33 ` Oliver Scholz
  0 siblings, 1 reply; 10+ messages in thread
From: Albert Reiner @ 2004-10-09 12:48 UTC (permalink / raw)


Hi,

I am working with a file that gets carried around a lot, changes names
etc., so that I (think I) cannot use bookmarks to mark the place where
I was working.  So instead I put some mark, e.g., `%%WORK%%' into the
file at the position where I want to go on working.  Instead of doing
C-s % % W O R K % % every time I open the document, I wanted to have
this done automatically.  My attempt was to use the file local
variables section with an entry

    eval: (search-forward "%%WORK%%")

When I open the file, I am asked whether I want to evaluate the
`eval', but still I do not end up at the marked position.

Any clarifications on why that does not work, and on how to make it
work, would be most welcome!

TIA,

Albert.

P.S.: Current solution is to have the (search-forward ...) in the
      first line and do C-e C-x C-e.

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

* Re: eval: (search-forward)
  2004-10-09 12:48 eval: (search-forward) Albert Reiner
@ 2004-10-10 12:33 ` Oliver Scholz
  2004-10-10 14:48   ` Albert Reiner
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Scholz @ 2004-10-10 12:33 UTC (permalink / raw)


Albert Reiner <areiner@tph.tuwien.ac.at> writes:

> Hi,
>
> I am working with a file that gets carried around a lot, changes names
> etc., so that I (think I) cannot use bookmarks to mark the place where
> I was working.  So instead I put some mark, e.g., `%%WORK%%' into the
> file at the position where I want to go on working.  Instead of doing
> C-s % % W O R K % % every time I open the document, I wanted to have
> this done automatically.  My attempt was to use the file local
> variables section with an entry
>
>     eval: (search-forward "%%WORK%%")
>
> When I open the file, I am asked whether I want to evaluate the
> `eval', but still I do not end up at the marked position.
>
> Any clarifications on why that does not work, and on how to make it
> work, would be most welcome!

At the time the form is evaluated, the buffer is narrowed to the
local variables section.  That's all there is to it.  Try this:

Local Variables:
eval: (add-hook 'find-file-hook (lambda () (goto-char (point-min))
(search-forward "%%WORK%%")) t t)
End:


    Oliver
-- 
19 Vendémiaire an 213 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: eval: (search-forward)
  2004-10-10 12:33 ` Oliver Scholz
@ 2004-10-10 14:48   ` Albert Reiner
  2004-10-11  7:59     ` Joakim Hove
  2004-10-11  9:40     ` eval: (search-forward) Oliver Scholz
  0 siblings, 2 replies; 10+ messages in thread
From: Albert Reiner @ 2004-10-10 14:48 UTC (permalink / raw)


Thanks for your reply!

[Oliver Scholz <alkibiades@gmx.de>, Sun, 10 Oct 2004 14:33:54 +0200]:
> >     eval: (search-forward "%%WORK%%")
> >
> > When I open the file, I am asked whether I want to evaluate the
> > `eval', but still I do not end up at the marked position.

> At the time the form is evaluated, the buffer is narrowed to the
> local variables section.  That's all there is to it.  Try this:

Ah, I see.  

> Local Variables:
> eval: (add-hook 'find-file-hook (lambda () (goto-char (point-min))
> (search-forward "%%WORK%%")) t t)
> End:

Unfortunately this does not seem to work here - I still end up at the
top of the file.  Inserting a couple of (message) calls, I see that
the eval is evaluated but the (lambda) never run.

Thanks again,

Albert.

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

* Re: eval: (search-forward)
  2004-10-10 14:48   ` Albert Reiner
@ 2004-10-11  7:59     ` Joakim Hove
  2004-10-11 10:16       ` Albert Reiner
  2004-10-12 13:57       ` Albert Reiner
  2004-10-11  9:40     ` eval: (search-forward) Oliver Scholz
  1 sibling, 2 replies; 10+ messages in thread
From: Joakim Hove @ 2004-10-11  7:59 UTC (permalink / raw)



Albert Reiner <areiner@tph.tuwien.ac.at> writes:


>> Local Variables:
>> eval: (add-hook 'find-file-hook (lambda () (goto-char (point-min))
>> (search-forward "%%WORK%%")) t t)
>> End:

I thought the hook was called find-file-hooks. The following works for
me:                                         ^  

1. Define the local variable work-string (or whatever) *as a
   string*, in the relevant file.

2. The following function in .emacs or somewhere:

(defun goto-work ()
     (if (boundp 'work-string)
      (progn
	(goto-char (point-min))
	(unless (search-forward work-string (point-max) 't)
	  (message (format "Could not find \"%s\" in buffer" work-string))))))
	  
3. (add-hook 'find-file-hooks 'goto-work)

Your existing soultion might work by just changin find-file-hook ->
find-file-hooks though.

HTH - Joakim

-- 
Joakim Hove
hove AT ift uib no
+47 (55 5)8 27 90
http://www.ift.uib.no/~hove/

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

* Re: eval: (search-forward)
  2004-10-10 14:48   ` Albert Reiner
  2004-10-11  7:59     ` Joakim Hove
@ 2004-10-11  9:40     ` Oliver Scholz
  2004-10-11 10:09       ` Albert Reiner
  1 sibling, 1 reply; 10+ messages in thread
From: Oliver Scholz @ 2004-10-11  9:40 UTC (permalink / raw)


Albert Reiner <areiner@tph.tuwien.ac.at> writes:
[...]
> [Oliver Scholz <alkibiades@gmx.de>, Sun, 10 Oct 2004 14:33:54 +0200]:
[...]

>> Local Variables:
>> eval: (add-hook 'find-file-hook (lambda () (goto-char (point-min))
>> (search-forward "%%WORK%%")) t t)
>> End:
>
> Unfortunately this does not seem to work here - I still end up at the
> top of the file.  Inserting a couple of (message) calls, I see that
> the eval is evaluated but the (lambda) never run.

It seems that `find-file-hook' exists only in CVS Emacs. For Emacs
21.3 use `find-file-hooks' (note the "s") instead.

    Oliver
-- 
20 Vendémiaire an 213 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: eval: (search-forward)
  2004-10-11  9:40     ` eval: (search-forward) Oliver Scholz
@ 2004-10-11 10:09       ` Albert Reiner
  0 siblings, 0 replies; 10+ messages in thread
From: Albert Reiner @ 2004-10-11 10:09 UTC (permalink / raw)


> >> Local Variables:
> >> eval: (add-hook 'find-file-hook (lambda () (goto-char (point-min))
> >> (search-forward "%%WORK%%")) t t)
> >> End:
> 
> It seems that `find-file-hook' exists only in CVS Emacs. For Emacs
> 21.3 use `find-file-hooks' (note the "s") instead.

Indeed, that works.  Thanks again,

Albert.

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

* Re: eval: (search-forward)
  2004-10-11  7:59     ` Joakim Hove
@ 2004-10-11 10:16       ` Albert Reiner
  2004-10-12 13:57       ` Albert Reiner
  1 sibling, 0 replies; 10+ messages in thread
From: Albert Reiner @ 2004-10-11 10:16 UTC (permalink / raw)


> 1. Define the local variable work-string (or whatever) *as a
>    string*, in the relevant file.
> 
> 2. The following function in .emacs or somewhere:
> 
> (defun goto-work ()
>      (if (boundp 'work-string)
>       (progn
> 	(goto-char (point-min))
> 	(unless (search-forward work-string (point-max) 't)
> 	  (message (format "Could not find \"%s\" in buffer" work-string))))))
> 	  
> 3. (add-hook 'find-file-hooks 'goto-work)

Wonderful, works beautifully!

Thanks,

Albert.

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

* Re: eval: (search-forward)
  2004-10-11  7:59     ` Joakim Hove
  2004-10-11 10:16       ` Albert Reiner
@ 2004-10-12 13:57       ` Albert Reiner
  2004-10-18  7:02         ` Joakim Hove
  1 sibling, 1 reply; 10+ messages in thread
From: Albert Reiner @ 2004-10-12 13:57 UTC (permalink / raw)


[Joakim Hove <hove@ift.uib.no>, Mon, 11 Oct 2004 09:59:36 +0200]:
> 1. Define the local variable work-string (or whatever) *as a
>    string*, in the relevant file.
> 
> 2. The following function in .emacs or somewhere:
> 
> (defun goto-work ()
>      (if (boundp 'work-string)
>       (progn
> 	(goto-char (point-min))
> 	(unless (search-forward work-string (point-max) 't)
> 	  (message (format "Could not find \"%s\" in buffer" work-string))))))
> 	  
> 3. (add-hook 'find-file-hooks 'goto-work)

I have modified goto-work to be (interactive) and would have expected
that I could then use M-x goto-work to go to the current position of
work-string at any time.  But surprisingly, after the hook is run the
boundp test always fails, as if the buffer-local value went away after
initialization.  Any simple fix?

TIA,

Albert.

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

* Re: eval: (search-forward)
  2004-10-12 13:57       ` Albert Reiner
@ 2004-10-18  7:02         ` Joakim Hove
  2004-10-24 16:11           ` eval: (search-forward) (Solved) Albert Reiner
  0 siblings, 1 reply; 10+ messages in thread
From: Joakim Hove @ 2004-10-18  7:02 UTC (permalink / raw)



Albert Reiner <areiner@tph.tuwien.ac.at> writes:


> But surprisingly, after the hook is run the boundp test always
> fails, as if the buffer-local value went away after initialization.
> Any simple fix?

Maybe; I think local variables defined on the top of the file are
meant only for the initialization, maybe the go out of scope when the
initialization is complete. Try putting the relevant string *at the
bottom* of the file instead:elisp

;;; Local Variables: ***
;;; work-string: ";;; Start here" ***
;;; End: ***

Read more about File Variables in (info "(emacs) File Variables").

HTH - Joakim

-- 
Joakim Hoveelisp
hove AT ift uib no
+47 (55 5)8 27 90
http://www.ift.uib.no/~hove/

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

* Re: eval: (search-forward) (Solved)
  2004-10-18  7:02         ` Joakim Hove
@ 2004-10-24 16:11           ` Albert Reiner
  0 siblings, 0 replies; 10+ messages in thread
From: Albert Reiner @ 2004-10-24 16:11 UTC (permalink / raw)


Joakim,

thanks a lot for your reply:

[Joakim Hove <hove@ift.uib.no>, Mon, 18 Oct 2004 09:02:12 +0200]:
> Albert Reiner <areiner@tph.tuwien.ac.at> writes:
> 
> > But surprisingly, after the hook is run the boundp test always
> > fails, as if the buffer-local value went away after initialization.
> > Any simple fix?
> 
> Maybe; I think local variables defined on the top of the file are
> meant only for the initialization, maybe the go out of scope when the
> initialization is complete. Try putting the relevant string *at the
> bottom* of the file instead:elisp
> 
> ;;; Local Variables: ***
> ;;; work-string: ";;; Start here" ***
> ;;; End: ***
> 
> Read more about File Variables in (info "(emacs) File Variables").

(The variable settings were already at the end, and the info manual
does not seem to indicate a distinction between those on the top and
those at the bottom of the file.)

All of this turned out to be the result of testing this exclusively
with files in noweb major mode.  That mode does some mode changing
depending on where in the file point is, and apparently only those
variables where the permanent-local property is t are visible once
noweb-code-mode or noweb-doc-mode are in effect.

The simple solution is to add (put 'work-string 'permanent-local t) to
the defun; the correct thing would probably be to change noweb-mode.el
so that noweb-make-variable-permanent-local is mapped over all
file-local variables, i.e., to add something like (mapcar
'noweb-make-variable-permanent-local (mapcar 'car
(buffer-local-variables))) to the defun noweb-mode, but I do not
understand noweb-mode.el enough to know whether this is safe.

Thanks again for taking the time to answer,

Albert.

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

end of thread, other threads:[~2004-10-24 16:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-09 12:48 eval: (search-forward) Albert Reiner
2004-10-10 12:33 ` Oliver Scholz
2004-10-10 14:48   ` Albert Reiner
2004-10-11  7:59     ` Joakim Hove
2004-10-11 10:16       ` Albert Reiner
2004-10-12 13:57       ` Albert Reiner
2004-10-18  7:02         ` Joakim Hove
2004-10-24 16:11           ` eval: (search-forward) (Solved) Albert Reiner
2004-10-11  9:40     ` eval: (search-forward) Oliver Scholz
2004-10-11 10:09       ` Albert Reiner

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.