This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

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

3 posts · 5150 views

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:
find-coding-systems-region: Wrong type argument: integer-or-marker-p, nil
Here's the code:
(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)))

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

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
(defun save-in-other-file (new-filename)
  (interactive "FFilename:")
  (write-region (point-min) (point-max) new-filename))

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

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.