unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Sebastian Tennant <sebyte@smolny.plus.com>
To: help-gnu-emacs@gnu.org
Subject: Re: how to set the initial point position when visit a file
Date: Mon, 15 Oct 2007 17:58:26 +0300	[thread overview]
Message-ID: <874pgs4e7h.fsf@moley.moleskin.org> (raw)
In-Reply-To: 1192375674.871514.83460@i13g2000prf.googlegroups.com

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

  reply	other threads:[~2007-10-15 14:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-14 13:53 how to set the initial point position when visit a file moonrie
2007-10-14 14:33 ` moonrie
2007-10-14 15:27   ` moonrie
2007-10-15 14:58     ` Sebastian Tennant [this message]
2007-10-15 15:36     ` Mathias Dahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874pgs4e7h.fsf@moley.moleskin.org \
    --to=sebyte@smolny.plus.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).