[comp.emacs] Modifying point automatically on editing file 'x'

randy@ncifcrf.UUCP (07/13/87)

    I have a question for the assembled intellects of the net.  I want
  to have point moved to a specific point within a file automatically
  upon editing the given file (specifically to the end of the first
  line).  I thought I could do this through a modification of
  auto-mode-alist, but apparently modifications to point are not
  effective when called through this mechanism.  Specifically, I
  created a function 'mh-compose-mode which put me into Text mode, set
  the fill prefix, moved to the beginning of the buffer and then to
  the end of the line.  I then cons'ed '("draft" . mh-compose-mode) to
  auto-mode-alist and setq'd the result to auto-mode-alist again in my
  .emacs file.  I'm sure I got the basic technique of modifying
  auto-mode-alist right, because I end up in text mode with the fill
  prefix set appropriately.  However, point is at the beginning of the
  buffer, not the end of the first line.

    This is obviously a minor problem (a single keystroke puts me
  where I want to be) but I got curious as to why my method didn't
  work.  Checking the source (files.el) indicate the the
  auto-mode-alist function is called after the file is found, so it's
  not a simple case of manipulating point on an empty scratch buffer.
  Anybody hacked gnumacs enough to know what's up?  Thanks for any and
  all replies.

					-- Randy Smith

  Randy Smith    @	NCI Supercomputer Facility
  c/o PRI, Inc.		
  PO Box B, Bldng. 430  Phone: (301) 698-5660                  
  Frederick, MD 21701  	Uucp: ...!seismo!elsie!ncifcrf!randy

matt@oddjob.UChicago.EDU (I am not a Grook) (07/14/87)

Randy T. F. Smith (RTFS?) writes:
)   I want to have point moved to a specific point within a file
) automatically upon editing the given file.  I thought I could
) do this through a modification of auto-mode-alist, ...
) However, point is at the beginning of the buffer, not the end
) of the first line.

)   Checking the source (files.el) indicate the the
)   auto-mode-alist function is called after the file is found,
)   so it's not a simple case of manipulating point on an empty
)   scratch buffer.

Check more closely ... All the work of auto-modes is done by
after-find-file which is called from inside a (save-excursion ...).
I had a similar problem trying to get my c-mode-hook to do a
(setq case-fold-search nil).  The hooks were run from inside a
(let ((case-fold-search t)) ...).  I sent this in as a bug and
it was change many releases ago.

There is a reason for the save-excursion in find-file-noselect
(the contents may be read in again if the buffer exists and the
file has been altered on disk), but I don't see that the reason
extends to protecting the call to after-find-file.

There's another save-excursion inside set-auto-mode which is
needed because that function searches for a -*-MODENAME-*- in
the buffer.  A little rearrangement can bring the line
	  (funcall (intern (concat (downcase mode) "-mode")))
and the subsequent scan of auto-mode-alist outside of the
save-excursion.

I think that the above changes should be made.  I'm sure some
FSF GNUmaster is watching.  Taking care of a local "variable" of
"mode" or "eval" I leave as an exercise for said master!
________________________________________________________
Matt	     University		matt@oddjob.uchicago.edu
Crawford     of Chicago          {hao,ihnp4}!oddjob!matt
	Yow!  I threw up on my window!