all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to set the initial point position when visit a file
@ 2007-10-14 13:53 moonrie
  2007-10-14 14:33 ` moonrie
  0 siblings, 1 reply; 5+ messages in thread
From: moonrie @ 2007-10-14 13:53 UTC (permalink / raw)
  To: help-gnu-emacs

usually i have some machine produced c++ files, each have a tag name
<StartPosition> marking the place to start coding.

so, i want the point in emacs go to <StartPosition> when i opened the
file with this tag.

anyone have the similar code for this?

thanks in advance,

- moonrie

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

* Re: how to set the initial point position when visit a file
  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
  0 siblings, 1 reply; 5+ messages in thread
From: moonrie @ 2007-10-14 14:33 UTC (permalink / raw)
  To: help-gnu-emacs

i googled goto-char point re-search-forward and match-beginning may be
helpful,

however, i do not know how to make it exactly.

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

* Re: how to set the initial point position when visit a file
  2007-10-14 14:33 ` moonrie
@ 2007-10-14 15:27   ` moonrie
  2007-10-15 14:58     ` Sebastian Tennant
  2007-10-15 15:36     ` Mathias Dahl
  0 siblings, 2 replies; 5+ messages in thread
From: moonrie @ 2007-10-14 15:27 UTC (permalink / raw)
  To: help-gnu-emacs

intuitively, i do it this way:

(search-forward "<TAG>")
(backward-delete-char (length "<TAG>"))

:P, dunno a better way?

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

* Re: how to set the initial point position when visit a file
  2007-10-14 15:27   ` moonrie
@ 2007-10-15 14:58     ` Sebastian Tennant
  2007-10-15 15:36     ` Mathias Dahl
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Tennant @ 2007-10-15 14:58 UTC (permalink / raw)
  To: help-gnu-emacs

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

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

* Re: how to set the initial point position when visit a file
  2007-10-14 15:27   ` moonrie
  2007-10-15 14:58     ` Sebastian Tennant
@ 2007-10-15 15:36     ` Mathias Dahl
  1 sibling, 0 replies; 5+ messages in thread
From: Mathias Dahl @ 2007-10-15 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

moonrie <moonrie@gmail.com> writes:

> intuitively, i do it this way:
>
> (search-forward "<TAG>")
> (backward-delete-char (length "<TAG>"))
>
> :P, dunno a better way?

You could make that into a command and bind it to a key and you could
even add it to a hook to be run when a file opens.

To make it into a command:

(defun jump-startpos ()
  (interactive)
  (let ((tag "<StartPosition>"))
    (search-forward tag)
    (backward-delete-char (length tag))))

(BTW, I did not bother to test the code above, or your original code.)

Bind the command to a key:

(global-set-key (kbd "[f5]") 'jump-startpos)

Place that into your .emacs and restart.

/Mathias

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

end of thread, other threads:[~2007-10-15 15:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-10-15 15:36     ` Mathias Dahl

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.