Custom 'save-a-copy-as' interactive function begins to error

Discussion of Emacs Lisp
Post Reply
Etrigan
Posts: 3
Joined: Mon Jul 07, 2008 8:18 am

Custom 'save-a-copy-as' interactive function begins to error

Post by Etrigan » Tue Jul 08, 2008 4:15 am

I wrote my own 'save-a-copy-as' function (how much does it suck that emacs doesn't ship with one?) which worked great until recently. I don't know what changed -- nothing, I would have said -- but now when I run it on Cygwin emacs 21.x, it errors:

Code: Select all

find-coding-systems-region: Wrong type argument: integer-or-marker-p, nil
Here's the code:

Code: Select all

(defun save-a-copy-as (file-or-directory)
  "Saves a copy of the current buffer in the given directory or file, leaving
   the original file in the buffer, and asking for confirmation before
   overwriting an existing file."
  (interactive "FSave a copy as file: ")
  (save-excursion
    (save-a-copy-as-confirming file-or-directory t)))

(defun save-a-copy-as-confirming (target-file-or-directory confirming)
  "Saves a copy of the current buffer in the given target directory or file,
   leaving the original file in the buffer.

   If argument confirming is nil, will overwrite any existing file with the same
   name; if confirming is anything else, will prompt the user first."
  (let ((target-file
         (concat target-file-or-directory
                 (when (string-match "/$" target-file-or-directory)
                   (buffer-name)))))
    (write-region nil nil target-file nil nil nil confirming)))

G-Brain
Posts: 16
Joined: Sat Jun 28, 2008 3:48 am
Contact:

Re: Custom 'save-a-copy-as' interactive function begins to error

Post by G-Brain » Tue Jul 08, 2008 8:28 am

C-x C-w works for me.

Edit: Okay, that switches to the newly saved file. My bad.

Edit2: Google-fu

C-x h (mark-whole-buffer)
M-x write-region

or

Code: Select all

(defun save-in-other-file (new-filename)
  (interactive "FFilename:")
  (write-region (point-min) (point-max) new-filename))

Etrigan
Posts: 3
Joined: Mon Jul 07, 2008 8:18 am

Re: Custom 'save-a-copy-as' interactive function begins to error

Post by Etrigan » Wed Jul 16, 2008 8:49 am

Hey, G-Brain. Thanks for posting.

The issue is not filling the gap in emacs' command set. My code does that. (So does yours)

The issue is that my code works fine on emacs 21 and 22, on three different linux distros on three different processor architectures, as well as on MacOS on two different processor architectures and on Solaris. Only on Cygwin do I have this problem.

What I'm looking for is someone to tell me what the error message quoted in the OP means and what if anything it tells me about how to fix the problem.

Post Reply