From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: Why won't this command kill a buffer? Date: Sat, 12 Feb 2011 15:47:11 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e657b670bf3ee4049c1105e8 X-Trace: dough.gmane.org 1297496877 10250 80.91.229.12 (12 Feb 2011 07:47:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 12 Feb 2011 07:47:57 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Joe Fineman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 12 08:47:49 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PoACq-0002vz-PB for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Feb 2011 08:47:49 +0100 Original-Received: from localhost ([127.0.0.1]:60039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PoACp-0003kK-Kt for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Feb 2011 02:47:47 -0500 Original-Received: from [140.186.70.92] (port=60349 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PoACI-0003hQ-UV for help-gnu-emacs@gnu.org; Sat, 12 Feb 2011 02:47:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PoACH-0008K4-Ew for help-gnu-emacs@gnu.org; Sat, 12 Feb 2011 02:47:14 -0500 Original-Received: from mail-fx0-f41.google.com ([209.85.161.41]:61285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PoACH-0008J5-2z for help-gnu-emacs@gnu.org; Sat, 12 Feb 2011 02:47:13 -0500 Original-Received: by fxm12 with SMTP id 12so3679596fxm.0 for ; Fri, 11 Feb 2011 23:47:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=xgpiReTtCR5X2McsxcKFgzJEUQ3smFsxP2TLXdA3WEM=; b=FyInbpU8EFL60EHUT/LS1t3+uhPNx8zcjvj+hI1sOFt6DXJl1HJDGvF4PJgoYb1jtM ElaAoT9JYfNCndrlrrM+ysHKhIyOCTnbkeZNvVs0Wr+Kk/CkP8a2S41OEVERmUwSvpha FHSAbDtvZj1CBg0pJOddwj434U17Hib3UuO00= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=J2dkwjlstAYgQh5KqOvmYsq1kA30ertCdEuSIgzP7WANswkljlRjPYjJiwb8tPHDTF 6bJi55uhqdewCqHIvj0KzsXJ4JutGReaBmAduSGVeM+5I5GN+NLUNkLUS2nTQnMwrEjG BpU7gXTJ+SVdqCj+lw0v54Tff5LlDeg723IkM= Original-Received: by 10.102.244.18 with SMTP id r18mr654811muh.5.1297496831638; Fri, 11 Feb 2011 23:47:11 -0800 (PST) Original-Received: by 10.103.138.16 with HTTP; Fri, 11 Feb 2011 23:47:11 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:79075 Archived-At: --0016e657b670bf3ee4049c1105e8 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Feb 12, 2011 at 6:48 AM, Joe Fineman wrote: > I am using Emacs 22.3.1 under Windows XP. I have used the following > kluge for many years: > > (defun marklog () > "Insert a backslash into the Log file for the current directory, and into > Today if it is in /b." > (interactive) > (save-window-excursion > (let ((dir default-directory) > (require-final-newline)) > (find-file "~/timing/Logmark") > (write-region 1 2 (concat dir "Log") t 0) > (if (equal (substring dir 0 15) "c:/usr/own/f/b/") > (write-region 1 2 "~/b/Today" t 0)) > (kill-this-buffer)) > )) > > The Logmark file consists of a single backslash. > > The command kill-this-buffer does not work, and neither do attempts to > use kill-buffer with an argument. The buffer hangs around and is > sometimes a nuisance. > I'm really not sure what the above is supposed to do. Maybe you can come up with minimum set of steps that repros what you're seeing. > And, incidentally, is there any simpler way to tell Emacs to append a > character to a file? > I don't think so. But you can come up with one easily: (defun append-str-to-file (str filename) "Append a string to the end of a file. If the file is being visited, don't save or kill it." (interactive "sstring: \nFfile: ") (let ((visiting-buffer (find-buffer-visiting filename)) require-final-newline) (with-current-buffer (or visiting-buffer (find-file-noselect filename)) (save-excursion (goto-char (point-max)) (insert str) (unless visiting-buffer (save-buffer) (kill-this-buffer)))))) -- Le --0016e657b670bf3ee4049c1105e8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
(defun append-str-to-file (str filename)
=A0=A0"Append a string to the= end of a file.
If the file is b= eing visited, don't save or kill it."
=A0=A0(interactive "sstring: \nF= file: ")
=A0=A0(let ((visit= ing-buffer (find-buffer-visiting filename))
=A0=A0 =A0 =A0 =A0require-final-newline)
=A0=A0 =A0(with-current-buffer (or visiting-buffer
=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 (find-file-noselect filename))
=A0=A0 =A0 =A0(save-excursion
=A0=A0 =A0 =A0 =A0(goto-char (point-max= ))
=A0=A0 =A0 =A0 =A0(insert str= )
=A0=A0 =A0 =A0 =A0(unless visiting-buffer
=A0=A0 =A0 =A0 =A0 =A0(save-buffer)
=A0=A0 =A0 =A0 =A0 =A0(kill-this-buffer))))))
=A0
--
Le
--0016e657b670bf3ee4049c1105e8--