[Top][All Lists]

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

Re: undo in loaddefs.el buffer

From: Richard Stallman
Subject: Re: undo in loaddefs.el buffer
Date: Sun, 26 Dec 2004 23:09:30 -0500

    The question is asked after `decode-coding-region' is called from
    `decode-coding-inserted-region' from `jka-compr-insert-file-contents'.
    Perhaps undo should be disabled temporarily in 
    during visiting a gzipped file, but not permanently because buffers of
    gzipped files are editable.

Does this replacement function make it work right?
It is designed to make buffer-undo-list empty in the case of visiting
a file, and optimize it in the other case.

(defun decode-coding-inserted-region (from to filename
                                           &optional visit beg end replace)
  "Decode the region between FROM and TO as if it is read from file FILENAME.
Optional arguments VISIT, BEG, END, and REPLACE are the same as those
of the function `insert-file-contents'."
      (let ((coding coding-system-for-read)
        (if visit
            ;; Temporarily turn off undo recording, if we're decoding the
            ;; text of a visited file.
            (setq buffer-undo-list t)
          ;; Otherwise, if we can recognize the undo elt for the insertion,
          ;; remove it and get ready to replace it later.
          ;; In the mean time, turn off undo recording.
          (let ((last (car buffer-undo-list))) 
            (if (and (consp last) (eql (car last) from) (eql (cdr last) to))
                (setq undo-list-saved (cdr buffer-undo-list)
                      buffer-undo-list t))))
        (narrow-to-region from to)
        (goto-char (point-min))
        (or coding
            (setq coding (funcall set-auto-coding-function
                                  filename (- (point-max) (point-min)))))
        (or coding
            (setq coding (car (find-operation-coding-system
                               filename visit beg end replace))))
        (if (coding-system-p coding)
            (or enable-multibyte-characters
                (setq coding
                      (coding-system-change-text-conversion coding 'raw-text)))
          (setq coding nil))
        (if coding
            (decode-coding-region (point-min) (point-max) coding)
          (setq last-coding-system-used coding))
        ;; If we're decoding the text of a visited file,
        ;; the undo list should start out empty.
        (if visit
            (setq buffer-undo-list nil)
          ;; If we decided to replace the undo entry for the insertion,
          ;; do so now.
          (if undo-list-saved
              (setq buffer-undo-list
                    (cons (cons from (point-max)) undo-list-saved))))))))

reply via email to

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