help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why won't this command kill a buffer?


From: Joe Fineman
Subject: Re: Why won't this command kill a buffer?
Date: Sat, 12 Feb 2011 18:05:33 -0500
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (windows-nt)

Le Wang <l26wang@gmail.com> writes:

> On Sat, Feb 12, 2011 at 6:48 AM, Joe Fineman <joe_f@verizon.net> 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.

It gets called by another function every 6 min.  Thus, it records in a
file called Log the number of tenths of an hour I have spent connected
to the current directory.  I massage the Log files in various ways and
use them for collecting usage statistics for various purposes.
 
>  Maybe you can come up with minimum set of steps that repros what
> you're seeing.   

I made up a new directory, ~/logtest.  I opened a buffer in it, and
typed a word.  Then I did M-x marklog.  The Log buffer then existed,
with a backslash in it.  The last line in the defun had failed to kill
it.

>     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))))))

I'll give this a try, but I suspect that kill-this-buffer will once
again fail to work.

Thank you for your attention.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  Hope is the last refuge of the incompetent.  :||


reply via email to

[Prev in Thread] Current Thread [Next in Thread]