* Return to Marker
@ 2003-01-30 17:38 CarlC
2003-01-30 18:23 ` Jesper Harder
0 siblings, 1 reply; 5+ messages in thread
From: CarlC @ 2003-01-30 17:38 UTC (permalink / raw)
I have a function that inserts some strings of text. Under normal
circumstances, I want point to be back at the original position. My problem
is that it only works part of the time, depending on where the original
point was. When it fails, it puts me at a point towards the end of the
buffer. I can't figure out why it works in some places and not in others. I
have tried save-excusion and get the same results. The real clincher, is
that it always works when I am debugging. I can press "c" as soon as I enter
the debugger, and it still works. The line of code is "(goto-char
custom-marker))" near the bottom of the function. It always seems to make it
to this code with the correct value of custom-marker. I am running GNU Emacs
21.2.1. Everything else in the function works great. Thanks for any help on
this.
(defun insert-cobol-file (file-id)
"Insert COBOL file into source."
(interactive "sFile id: ")
(let ((searches (list
"DATA DIVISION."
"WORKING-STORAGE SECTION."
"SCREEN SECTION."
"PROCEDURE DIVISION"
"MAS-ERR SECTION."
"END.DC"
"PERFORM FILE-INIT"))
(custom-marker (point-marker))
(initwarn nil))
(unwind-protect
(progn
(beginning-of-buffer)
(let (err)
(dolist (search searches err)
(if (not (search-forward search nil t))
(error "Search failed: %s" search))))
(beginning-of-buffer)
(search-forward (pop searches))
(previous-line 1)
(beginning-of-line)
(insert (format "\tCOPY \"UCOPY:%sFILE.SL\".\n" file-id))
(search-forward (pop searches))
(previous-line 1)
(beginning-of-line)
(insert (format "\tCOPY \"UCOPY:%sFILE.FD\".\n" file-id))
(search-forward (pop searches))
(previous-line 2)
(beginning-of-line)
(search-backward ".WS")
(next-line 1)
(beginning-of-line)
(insert (format "\tCOPY \"UCOPY:%sFILE.WS\".\n" file-id))
(search-forward (pop searches))
(previous-line 1)
(beginning-of-line)
(insert (format "\tCOPY \"UCOPY:%sFILE.SS\".\n" file-id))
(search-forward (pop searches))
(search-forward ".")
(backward-char)
(insert (format ", %sFILE" file-id))
(if (> (current-column) 79)
(progn
(backward-word 1)
(delete-backward-char 1)
(insert "\n\t\t")))
(search-forward (pop searches))
(previous-line 1)
(beginning-of-line)
(insert (format "\tCOPY \"UCOPY:%sFILE.DC\".\n" file-id))
(search-forward (pop searches))
(if (not (char-equal (following-char) ?\.))
(setq initwarn (point)))
(beginning-of-line)
(if (char-equal (following-char) ?\*)
(progn
(setq initwarn (point))
(forward-char 1)))
(let ((temp (point)))
(next-line 1)
(beginning-of-line)
(copy-region-as-kill temp (point))
(yank)
(previous-line 1)
(search-forward "FILE")
(delete-backward-char 4)
(insert file-id))
(end-of-buffer)
(previous-line 1)
(beginning-of-line)
;(debug)
(insert (format "\tCOPY \"UCOPY:%sFILE.OP\".\n" file-id)))
(goto-char custom-marker))
(if initwarn
(progn
(set-mark custom-marker)
(goto-char initwarn)
(message "** WARNING ** FILE-INIT is not standard")))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Return to Marker
2003-01-30 17:38 Return to Marker CarlC
@ 2003-01-30 18:23 ` Jesper Harder
2003-01-30 19:48 ` CarlC
0 siblings, 1 reply; 5+ messages in thread
From: Jesper Harder @ 2003-01-30 18:23 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> (beginning-of-buffer)
Don't use `beginning-of-buffer' in Lisp code, it'll cause the type of
problem you describe. Use (goto-char (point-min)) instead. The same
applies to `end-of-buffer'.
> (previous-line 1)
You usually don't want `previous-line' in Lisp programs -- use
(forward-line -1) instead. Ditto for `next-line'.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Return to Marker
2003-01-30 18:23 ` Jesper Harder
@ 2003-01-30 19:48 ` CarlC
2003-01-30 20:44 ` Jesper Harder
0 siblings, 1 reply; 5+ messages in thread
From: CarlC @ 2003-01-30 19:48 UTC (permalink / raw)
"Jesper Harder" <harder@myrealbox.com> wrote in message
news:m3d6mea441.fsf@defun.localdomain...
> "CarlC" <carlc@snowbd.com> writes:
>
> Don't use `beginning-of-buffer' in Lisp code, it'll cause the type of
> problem you describe. Use (goto-char (point-min)) instead. The same
> applies to `end-of-buffer'.
>
Thanks, Jesper. Problem solved. Seems like this is something that should be
"fixed".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Return to Marker
2003-01-30 19:48 ` CarlC
@ 2003-01-30 20:44 ` Jesper Harder
0 siblings, 0 replies; 5+ messages in thread
From: Jesper Harder @ 2003-01-30 20:44 UTC (permalink / raw)
"CarlC" <carlc@snowbd.com> writes:
> "Jesper Harder" <harder@myrealbox.com> wrote...
>>
>> Don't use `beginning-of-buffer' in Lisp code, it'll cause the type of
>> problem you describe. Use (goto-char (point-min)) instead.
>
> Thanks, Jesper. Problem solved. Seems like this is something that
> should be "fixed".
It isn't really a bug. It's just that some functions are designed as
user-level interactive commands -- they do more than you want when you
use them in a program.
You're not the first to hit this problem :-) and the docstring for
`beginning-of-buffer' does warn about it :
| Don't use this command in Lisp programs!
| (goto-char (point-min)) is faster and avoids clobbering the mark.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Return to Marker
@ 2003-01-30 20:35 Bingham, Jay
0 siblings, 0 replies; 5+ messages in thread
From: Bingham, Jay @ 2003-01-30 20:35 UTC (permalink / raw)
On Thursday, January 30, 2003 1:49 PM CarlC wrote:
>"Jesper Harder" <harder@myrealbox.com> wrote in message
>news:m3d6mea441.fsf@defun.localdomain...
>> "CarlC" <carlc@snowbd.com> writes:
>>
>> Don't use `beginning-of-buffer' in Lisp code, it'll cause the type of
>> problem you describe. Use (goto-char (point-min)) instead. The same
>> applies to `end-of-buffer'.
>>
>
>Thanks, Jesper. Problem solved. Seems like this is something that
should be
>"fixed".
Why do you want to fix something that is not broken? The elisp manual
specifically and clearly states that beginning-of-buffer and
end-of-buffer were designed for interactive use and that the goto-char
construct is the proper way to move to the ends of the buffer in elsip
programs. The reason for this is that the of-buffer functions "set the
mark and display messages in the echo area." You can read all about it
in the "Motion to an End of the Buffer" section of the elisp manual at:
http://www.gnu.org/manual/elisp-manual-21-2.8/html_mono/elisp.html.
Regards,
-_
J_)
C_)ingham
. HP - NonStop Austin Software & Services - Software Quality
Assurance
. Austin, TX
. "Language is the apparel in which your thoughts parade in public.
. Never clothe them in vulgar and shoddy attire." -Dr. George W.
Crane-
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-01-30 20:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-30 17:38 Return to Marker CarlC
2003-01-30 18:23 ` Jesper Harder
2003-01-30 19:48 ` CarlC
2003-01-30 20:44 ` Jesper Harder
-- strict thread matches above, loose matches on Subject: below --
2003-01-30 20:35 Bingham, Jay
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.