* Problem using search-forward
@ 2012-10-05 17:46 Bob Shanley
2012-10-07 18:26 ` Tassilo Horn
0 siblings, 1 reply; 3+ messages in thread
From: Bob Shanley @ 2012-10-05 17:46 UTC (permalink / raw)
To: help-gnu-emacs
stringToFind("this is a string");
; Given the above string and point positioned at the beginning of the line
; I want to move point to right after the ";"
; These work:
; (search-forward ");")
; (let ( (n 34) ) (search-forward ");" n))
; These do not:
; (defun eol ( ) (end-of-line) (point))
; (search-forward ");" (eol))
; (let ( (n (eol)) ) (message "this is the value %d" n) (search-forward ");" n))
; They result in a Search failed: ");" and point moves to end of line
; What am I missing?
;
Thanks for the help
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem using search-forward
2012-10-05 17:46 Problem using search-forward Bob Shanley
@ 2012-10-07 18:26 ` Tassilo Horn
2012-10-08 4:10 ` Eric Abrahamsen
0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2012-10-07 18:26 UTC (permalink / raw)
To: help-gnu-emacs
Bob Shanley <rjshanley18@gmail.com> writes:
Hi Bob,
> ; These do not:
> ; (defun eol ( ) (end-of-line) (point))
> ; (search-forward ");" (eol))
> ; (let ( (n (eol)) ) (message "this is the value %d" n) (search-forward ");" n))
> ; They result in a Search failed: ");" and point moves to end of line
> ; What am I missing?
The `end-of-line' call already moves point to the end of line, thus you
bound the search to the same position where it starts. Try this
definition of `eol'.
(defun eol ()
(save-excursion
(end-of-line)
(point)))
,----[ C-h f save-excursion RET ]
| save-excursion is a special form in `C source code'.
|
| (save-excursion &rest BODY)
|
| Save point, mark, and current buffer; execute BODY; restore those things.
| Executes BODY just like `progn'.
| The values of point, mark and the current buffer are restored
| even in case of abnormal exit (throw or error).
| The state of activation of the mark is also restored.
|
| This construct does not save `deactivate-mark', and therefore
| functions that change the buffer will still cause deactivation
| of the mark at the end of the command. To prevent that, bind
| `deactivate-mark' with `let'.
|
| If you only want to save the current buffer but not point nor mark,
| then just use `save-current-buffer', or even `with-current-buffer'.
`----
Bye,
Tassilo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem using search-forward
2012-10-07 18:26 ` Tassilo Horn
@ 2012-10-08 4:10 ` Eric Abrahamsen
0 siblings, 0 replies; 3+ messages in thread
From: Eric Abrahamsen @ 2012-10-08 4:10 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, Oct 08 2012, Tassilo Horn wrote:
> Bob Shanley <rjshanley18@gmail.com> writes:
>
> Hi Bob,
>
>> ; These do not:
>> ; (defun eol ( ) (end-of-line) (point))
>> ; (search-forward ");" (eol))
>> ; (let ( (n (eol)) ) (message "this is the value %d" n) (search-forward ");" n))
>> ; They result in a Search failed: ");" and point moves to end of line
>> ; What am I missing?
>
> The `end-of-line' call already moves point to the end of line, thus you
> bound the search to the same position where it starts. Try this
> definition of `eol'.
>
> (defun eol ()
> (save-excursion
> (end-of-line)
> (point)))
I may be missing something here, but isn't this what (point-at-eol) does?
> ,----[ C-h f save-excursion RET ]
> | save-excursion is a special form in `C source code'.
> |
> | (save-excursion &rest BODY)
> |
> | Save point, mark, and current buffer; execute BODY; restore those things.
> | Executes BODY just like `progn'.
> | The values of point, mark and the current buffer are restored
> | even in case of abnormal exit (throw or error).
> | The state of activation of the mark is also restored.
> |
> | This construct does not save `deactivate-mark', and therefore
> | functions that change the buffer will still cause deactivation
> | of the mark at the end of the command. To prevent that, bind
> | `deactivate-mark' with `let'.
> |
> | If you only want to save the current buffer but not point nor mark,
> | then just use `save-current-buffer', or even `with-current-buffer'.
> `----
>
> Bye,
> Tassilo
>
>
>
--
GNU Emacs 24.2.50.1 (i686-pc-linux-gnu, GTK+ Version 3.4.4)
of 2012-10-03 on pellet
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-08 4:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-05 17:46 Problem using search-forward Bob Shanley
2012-10-07 18:26 ` Tassilo Horn
2012-10-08 4:10 ` Eric Abrahamsen
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).