From: Ryan Yeske <rcyeske@gmail.com>
Subject: with-current-buffer mystery
Date: Thu, 25 Nov 2004 07:57:28 GMT [thread overview]
Message-ID: <87vfbufjqr.fsf@cut.hotdog.tmp> (raw)
Hello,
I'm writing some code that appends text from a process into a buffer.
I copied the filter code from the info node (elisp)Filter Functions:
(defun ordinary-insertion-filter (proc string)
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
;; Insert the text, advancing the process marker.
(goto-char (process-mark proc))
(insert string)
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc))))))
The text below this code fragment says:
The reason to use `with-current-buffer', rather than using
`save-excursion' to save and restore the current buffer, is so
as to preserve the change in point made by the second call to
`goto-char'.
Right. So `with-current-buffer' should preserve the current buffer,
but allow changes to the point?
When I eval the following expressions, I found that it seems to depend
on whether or not the buffer is visible.
;; create a dummy buffer with text
(progn
(pop-to-buffer (get-buffer-create "*dummy*"))
(erase-buffer)
(insert "1\n2\n3\n")
(goto-char (point-min)))
Notice point is at the beginning of buffer. Eval the next
expression with *dummy* still visible in other-window.
;; goto end of buffer and insert a 4, note where point is
(with-current-buffer (get-buffer-create "*dummy*")
(goto-char (point-max))
(insert "4")
(newline))
The 4 is inserted at the correct position, but point did not
permanently change. Switch to that buffer and check.
(pop-to-buffer "*dummy*")
So, maybe I'm misunderstanding `with-current-buffer'.
If you repeat the second step, but with *dummy* buried:
(delete-other-windows)
(with-current-buffer "*dummy*"
(goto-char (point-max))
(insert "5")
(newline))
(pop-to-buffer "*dummy*")
The 5 is in the right place, and the point is at the end.
What is going on?
Any help or explanations would be greatly appreciated.
Ryan
next reply other threads:[~2004-11-25 7:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-25 7:57 Ryan Yeske [this message]
2004-11-25 13:02 ` with-current-buffer mystery Johan Bockgård
2004-11-26 4:38 ` Ryan Yeske
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=87vfbufjqr.fsf@cut.hotdog.tmp \
--to=rcyeske@gmail.com \
/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).