[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to set the initial point position when visit a file
From: |
Sebastian Tennant |
Subject: |
Re: how to set the initial point position when visit a file |
Date: |
Mon, 15 Oct 2007 17:58:26 +0300 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) |
Quoth moonrie <moonrie@gmail.com>:
> intuitively, i do it this way:
>
> (search-forward "<TAG>")
> (backward-delete-char (length "<TAG>"))
>
> :P, dunno a better way?
Nothing wrong with that. You don't want to cause an error if <TAG> is
not found, so it's better to say:
(search-forward "<TAG>" nil t)
and you don't want to delete any characters if <TAG> is not found, so
make it conditional:
(when (search-forward "<TAG>" nil t)
(backward-delete-char (length "<TAG>")))
Finally, why not add this to c++-mode-hook, by putting the following in
your ~/.emacs init file:
(add-hook 'c++-mode-hook
(lambda ()
(when (search-forward "<TAG>" nil t)
(backward-delete-char (length "<TAG>")))))
This tag search will now be performed every time a buffer enters
c++-mode.
You can ensure a file always enters a certain mode by specifying the
mode in the first line, like so:
# -*- mode: c++ -*-
#
# ~/c++/test.c
#
<TAG>
Good luck.
Sebastian