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: Le Wang
Subject: Re: Why won't this command kill a buffer?
Date: Sat, 12 Feb 2011 15:47:11 +0800

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

reply via email to

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