all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why won't this command kill a buffer?
@ 2011-02-11 22:48 Joe Fineman
  2011-02-12  4:15 ` B. T. Raven
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Joe Fineman @ 2011-02-11 22:48 UTC (permalink / raw)
  To: help-gnu-emacs

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.

And, incidentally, is there any simpler way to tell Emacs to append a
character to a file?
-- 
---  Joe Fineman    joe_f@verizon.net

||:  In other words, uninteresting immature ideas undergo violent  :||
||:  conflict during their latency.                                :||


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-11 22:48 Why won't this command kill a buffer? Joe Fineman
@ 2011-02-12  4:15 ` B. T. Raven
  2011-02-12  4:19   ` B. T. Raven
  2011-02-12 22:50   ` Joe Fineman
  2011-02-12  7:47 ` Le Wang
       [not found] ` <mailman.1.1297496838.19060.help-gnu-emacs@gnu.org>
  2 siblings, 2 replies; 9+ messages in thread
From: B. T. Raven @ 2011-02-12  4:15 UTC (permalink / raw)
  To: help-gnu-emacs

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.
> 
> And, incidentally, is there any simpler way to tell Emacs to append a
> character to a file?

If you really mean "append" (put at the end) then this works
(on msw2000 with Emacs 22.3):

"
append-to-file is an interactive compiled Lisp function in `files.el'.
It is bound to <f4>.
(append-to-file START END FILENAME)

Append the contents of the region to the end of file FILENAME.
When called from a function, expects three arguments,
START, END and FILENAME.  START and END are buffer positions
saying what text to write.
"

Interactively I had bound this function to f4 in .emacs
(define-key global-map [f4] 'append-to-file)
I made a test file with a few chars in it and saved it.
Inserted backspace into buffer with C-q *backspacekey* and then made
that single character (shows as ^?) the region and pressed f4.
Inspection of the last character of the file appended to shows:

Char: DEL (127, #o177, #x7f) point=5 of 5 (80%) column=0

I assume that what can be done interactively can also be done
programmatically.

Ed



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-12  4:15 ` B. T. Raven
@ 2011-02-12  4:19   ` B. T. Raven
  2011-02-12 22:50   ` Joe Fineman
  1 sibling, 0 replies; 9+ messages in thread
From: B. T. Raven @ 2011-02-12  4:19 UTC (permalink / raw)
  To: help-gnu-emacs

Oops! Same thing should work with backslash rather than backspace. It's
even easier to append a non control character.

B. T. Raven wrote:
> 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.
>>
>> And, incidentally, is there any simpler way to tell Emacs to append a
>> character to a file?
> 
> If you really mean "append" (put at the end) then this works
> (on msw2000 with Emacs 22.3):
> 
> "
> append-to-file is an interactive compiled Lisp function in `files.el'.
> It is bound to <f4>.
> (append-to-file START END FILENAME)
> 
> Append the contents of the region to the end of file FILENAME.
> When called from a function, expects three arguments,
> START, END and FILENAME.  START and END are buffer positions
> saying what text to write.
> "
> 
> Interactively I had bound this function to f4 in .emacs
> (define-key global-map [f4] 'append-to-file)
> I made a test file with a few chars in it and saved it.
> Inserted backspace into buffer with C-q *backspacekey* and then made
> that single character (shows as ^?) the region and pressed f4.
> Inspection of the last character of the file appended to shows:
> 
> Char: DEL (127, #o177, #x7f) point=5 of 5 (80%) column=0
> 
> I assume that what can be done interactively can also be done
> programmatically.
> 
> Ed
> 


-- 
Certa igitur cum illo qui a te totus diversus est. [Cic. Acad. 2.32]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-11 22:48 Why won't this command kill a buffer? Joe Fineman
  2011-02-12  4:15 ` B. T. Raven
@ 2011-02-12  7:47 ` Le Wang
       [not found] ` <mailman.1.1297496838.19060.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: Le Wang @ 2011-02-12  7:47 UTC (permalink / raw)
  To: Joe Fineman; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1691 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3008 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-12  4:15 ` B. T. Raven
  2011-02-12  4:19   ` B. T. Raven
@ 2011-02-12 22:50   ` Joe Fineman
  2011-02-15  2:23     ` B. T. Raven
  1 sibling, 1 reply; 9+ messages in thread
From: Joe Fineman @ 2011-02-12 22:50 UTC (permalink / raw)
  To: help-gnu-emacs

"B. T. Raven" <nihil@nihilo.net> writes:

> If you really mean "append" (put at the end) then this works
> (on msw2000 with Emacs 22.3):
>
> "
> append-to-file is an interactive compiled Lisp function in `files.el'.
> It is bound to <f4>.
> (append-to-file START END FILENAME)
>
> Append the contents of the region to the end of file FILENAME.
> When called from a function, expects three arguments,
> START, END and FILENAME.  START and END are buffer positions
> saying what text to write.
> "
>
> Interactively I had bound this function to f4 in .emacs
> (define-key global-map [f4] 'append-to-file)
> I made a test file with a few chars in it and saved it.
> Inserted backspace into buffer with C-q *backspacekey* and then made
> that single character (shows as ^?) the region and pressed f4.
> Inspection of the last character of the file appended to shows:
>
> Char: DEL (127, #o177, #x7f) point=5 of 5 (80%) column=0
>
> I assume that what can be done interactively can also be done
> programmatically.

Thank you.  I will give that a try.  It may turn out to be a nuisance,
tho, that it requires inserting the character in the current buffer &
then deleting it.  The function I defined is usually run in the
background, and it might cause confusion in that it would cause the
current buffer to be marked as modified, and might interact oddly with
my keying.  What I would really like is an append-to-file command that
takes as its argument an arbitrary character or string, rather than a
substring of the current buffer.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  What's wrong with the world?  I am.  :||


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
       [not found] ` <mailman.1.1297496838.19060.help-gnu-emacs@gnu.org>
@ 2011-02-12 23:05   ` Joe Fineman
  2011-02-13  7:07     ` Le Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Joe Fineman @ 2011-02-12 23:05 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-12 23:05   ` Joe Fineman
@ 2011-02-13  7:07     ` Le Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Le Wang @ 2011-02-13  7:07 UTC (permalink / raw)
  To: Joe Fineman; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 640 bytes --]

On Sun, Feb 13, 2011 at 7:05 AM, Joe Fineman <joe_f@verizon.net> wrote:

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


You'll have to debug your own program.  Start with "emacs -Q" to remove any
effects your customizations have on emacs.  Off the top of my head, it looks
like "dir" may not be 15 characters long, and an exception is raised before
the buffer is killed.

see: http://www.emacswiki.org/emacs/SourceLevelDebugger

also `toggle-debug-on-error'
-- 
Le

[-- Attachment #2: Type: text/html, Size: 1041 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-12 22:50   ` Joe Fineman
@ 2011-02-15  2:23     ` B. T. Raven
  2011-02-16 14:27       ` B. T. Raven
  0 siblings, 1 reply; 9+ messages in thread
From: B. T. Raven @ 2011-02-15  2:23 UTC (permalink / raw)
  To: help-gnu-emacs

Joe Fineman wrote:
> "B. T. Raven" <nihil@nihilo.net> writes:
> 
>> If you really mean "append" (put at the end) then this works
>> (on msw2000 with Emacs 22.3):
>>
>> "
>> append-to-file is an interactive compiled Lisp function in `files.el'.
>> It is bound to <f4>.
>> (append-to-file START END FILENAME)
>>
>> Append the contents of the region to the end of file FILENAME.
>> When called from a function, expects three arguments,
>> START, END and FILENAME.  START and END are buffer positions
>> saying what text to write.
>> "
>>
>> Interactively I had bound this function to f4 in .emacs
>> (define-key global-map [f4] 'append-to-file)
>> I made a test file with a few chars in it and saved it.
>> Inserted backspace into buffer with C-q *backspacekey* and then made
>> that single character (shows as ^?) the region and pressed f4.
>> Inspection of the last character of the file appended to shows:
>>
>> Char: DEL (127, #o177, #x7f) point=5 of 5 (80%) column=0
>>
>> I assume that what can be done interactively can also be done
>> programmatically.
> 
> Thank you.  I will give that a try.  It may turn out to be a nuisance,
> tho, that it requires inserting the character in the current buffer &
> then deleting it.  The function I defined is usually run in the
> background, and it might cause confusion in that it would cause the
> current buffer to be marked as modified, and might interact oddly with
> my keying.  What I would really like is an append-to-file command that
> takes as its argument an arbitrary character or string, rather than a
> substring of the current buffer.


It looks like Emacs sees such a procedure as too low-level. Since it
operates on files in buffers you would have to do
find-file-other-window, select-window, (goto-char (point-max)) and then
insert the char. I haven't been able to insert \ via elisp though. All
the functions produce 92, \nil, or "\\" or worse. I thought of creating
a file with only backslash in it and then running (shell-command "cat
file bacsla >> file") but if you need the character parameterized then
you need to shell-command on a program that does fputc on the file
opened for append.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Why won't this command kill a buffer?
  2011-02-15  2:23     ` B. T. Raven
@ 2011-02-16 14:27       ` B. T. Raven
  0 siblings, 0 replies; 9+ messages in thread
From: B. T. Raven @ 2011-02-16 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

B. T. Raven wrote:
> Joe Fineman wrote:
>> "B. T. Raven" <nihil@nihilo.net> writes:
>>
>>> If you really mean "append" (put at the end) then this works
>>> (on msw2000 with Emacs 22.3):
>>>
>>> "
>>> append-to-file is an interactive compiled Lisp function in `files.el'.
>>> It is bound to <f4>.
>>> (append-to-file START END FILENAME)
>>>
>>> Append the contents of the region to the end of file FILENAME.
>>> When called from a function, expects three arguments,
>>> START, END and FILENAME.  START and END are buffer positions
>>> saying what text to write.
>>> "
>>>
>>> Interactively I had bound this function to f4 in .emacs
>>> (define-key global-map [f4] 'append-to-file)
>>> I made a test file with a few chars in it and saved it.
>>> Inserted backspace into buffer with C-q *backspacekey* and then made
>>> that single character (shows as ^?) the region and pressed f4.
>>> Inspection of the last character of the file appended to shows:
>>>
>>> Char: DEL (127, #o177, #x7f) point=5 of 5 (80%) column=0
>>>
>>> I assume that what can be done interactively can also be done
>>> programmatically.
>> Thank you.  I will give that a try.  It may turn out to be a nuisance,
>> tho, that it requires inserting the character in the current buffer &
>> then deleting it.  The function I defined is usually run in the
>> background, and it might cause confusion in that it would cause the
>> current buffer to be marked as modified, and might interact oddly with
>> my keying.  What I would really like is an append-to-file command that
>> takes as its argument an arbitrary character or string, rather than a
>> substring of the current buffer.
> 
> 
> It looks like Emacs sees such a procedure as too low-level. Since it
> operates on files in buffers you would have to do
> find-file-other-window, select-window, (goto-char (point-max)) and then
> insert the char. I haven't been able to insert \ via elisp though. All
> the functions produce 92, \nil, or "\\" or worse. I thought of creating
> a file with only backslash in it and then running (shell-command "cat
> file bacsla >> file") but if you need the character parameterized then
> you need to shell-command on a program that does fputc on the file
> opened for append.


On w32 (shell-command "echo \\ >> test") appends a backslash to file "test".


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-02-16 14:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-11 22:48 Why won't this command kill a buffer? Joe Fineman
2011-02-12  4:15 ` B. T. Raven
2011-02-12  4:19   ` B. T. Raven
2011-02-12 22:50   ` Joe Fineman
2011-02-15  2:23     ` B. T. Raven
2011-02-16 14:27       ` B. T. Raven
2011-02-12  7:47 ` Le Wang
     [not found] ` <mailman.1.1297496838.19060.help-gnu-emacs@gnu.org>
2011-02-12 23:05   ` Joe Fineman
2011-02-13  7:07     ` Le Wang

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.