From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Writing text to a dedicated buffer Date: Sun, 02 May 2021 16:23:27 +0200 Message-ID: <87lf8xkxoc.fsf@fastmail.fm> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20293"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.12; emacs 27.2 Cc: help-gnu-emacs@gnu.org To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 02 16:39:53 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldDGD-0005BB-El for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 02 May 2021 16:39:53 +0200 Original-Received: from localhost ([::1]:44220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldDGC-0008Bw-Ft for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 02 May 2021 10:39:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldDFi-0008Bh-L7 for help-gnu-emacs@gnu.org; Sun, 02 May 2021 10:39:22 -0400 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:38571) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldDFg-0001y5-7V for help-gnu-emacs@gnu.org; Sun, 02 May 2021 10:39:22 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8E4005C0103; Sun, 2 May 2021 10:39:19 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 02 May 2021 10:39:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=fm3; bh=P+cNC9Qy5nYBGl0il/CHsfftjJ n/o3MDYHC92vNftY0=; b=D0HMcOBrIrKVrZGSD0NnhAoBmgxR2v2FUDDY+qJG0j qI8uti2id3o7m7yG9pjzYWIin+E7Oj0bEwAP/cpJ1Q6AZCGoExXodjKD4uKOKt+n fG2RUox6wg+PJbFJlyYpy6dt49LuVxB6pXu2Lu0rYX6dVIxatBbQEOWNysryjokA UpXaJc/rXFtjCj6QhS9tXFIJTNL0K0ia4YGAlx8q9BMJRfn+Dihwu/N21byfCyRd Gqrb3WtLun6CRaTYBtrhknEbwRF9XLud5KkQ2HVbvhKRxq1wXKUeEeqyzRiZrWjK G9rsMNEqeuSvvXDyQCqajp3SlndQGXd5k58uLXSy75YA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=P+cNC9 Qy5nYBGl0il/CHsfftjJn/o3MDYHC92vNftY0=; b=qyzSRrvMNXXkQ/fXAO2Kr3 CIEypC7qtbJUvYTFv96/PkguO2BsAVTwNqTIDC562OkLvyJLwu5B2F72Oy0L5mtk 7x7hZStSPTjDbU+tUvBJ4bfispWVWrxjIpIJLUY2DPEMgpF7yTCaOEFzD/bbhZlN qLYV9nEgE42aGjv1yh3Jg522PQ4dRjvqgP3YQRG4SD2zftgJZpTDskCUS4JzpRl4 nKmxMMmhw0TGlQDWSzPnoQTBaYP8bhRocenmGxUZLMojj45JXxJ7DjlufuK/JJH7 7u78z/G6FuEuqzVRv/FPc/a5YOGCcZB7KYeBspG2W5gyqLuKQJ2z59Hj+mtpMmnw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdefuddgudeftdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvffuffgjkfggtgesthdtredttdertdenucfhrhhomheplfhoohhs thcumfhrvghmvghrshcuoehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrdhfmh eqnecuggftrfgrthhtvghrnhepvdeihfetueevkeduteehudeihedvlefgieejhedvteef geelleehhfejudeijeevnecukfhppeefuddrudejrddvhedurdduleelnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoohhsthhkrhgvmhgv rhhssehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from Lenovo.fastmail.com (ip1f11fbc7.dynamic.kabel-deutschland.de [31.17.251.199]) by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 2 May 2021 10:39:18 -0400 (EDT) In-reply-to: Received-SPF: pass client-ip=66.111.4.26; envelope-from=joostkremers@fastmail.fm; helo=out2-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129331 Archived-At: On Sun, May 02 2021, Christopher Dimech wrote: > I have done the writing to a dedicated buffer as follows, > using "gungadin-bufr-insert" for writing to the Gungadin buffer. > > -------- code -------- > > (setq gungadin-bufr (generate-new-buffer "*Gungadin*")) This should be a `defvar`. Personally, I would probably initialise it to `nil` and create a buffer on the first call to `gungadin-bufr-insert`. But more likely, I would probably do something like this: (defvar gungadin-buffer-name "*Gungadin*") (defun gungadin-buffer-insert (message) (with-current-buffer (get-buffer-create gungadin-buffer-name) ...)) There is no problem calling `get-buffer-create` on a buffer that already exists. Just make sure you pass it the name of the buffer, not the buffer object itself, because in the latter case you may get back a dead buffer which you cannot write to anymore. (You never know when a user accidentally kills the Gungadin buffer.) Do `C-h f get-buffer-create RET` for details. > (defun gungadin-bufr-insert (format-string) > "Display a message at the bottom of the Gungadin Buffer." > > (set-buffer gungadin-bufr) > (with-current-buffer gungadin-bufr > (insert format-string)) ) If you check the source code of `with-current-buffer`, you'll notice that it uses `set-buffer`. There is no need to call `set-buffer` if you're going to use `with-current-buffer`. (And you should be using `with-current-buffer`.) -- Joost Kremers Life has its moments