[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: insert-file-contents and format-decode
From: |
martin rudalics |
Subject: |
Re: insert-file-contents and format-decode |
Date: |
Mon, 02 Jul 2007 10:14:41 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
Finally, I'm completely uncertain what to do about `format-insert-file':
That function explicitly prompts for a format and does `format-decode'
after inserting the file and running any `after-insert-file-functions'.
Shall we treat this is as a sequence of
(insert-file-contents filename nil beg end)
(let ((format-alist nil))
(format-decode-region (point) (+ (point) size) format))
with _two_ `buffer-undo-list' entries and `after-change-functions'
calls?
No, I suggest making just one undo entry for the insertion
of the decoded text. Just as `insert-file-contents' would do.
I tried this in the attached patch.
*** format.el Tue Jan 23 06:40:02 2007
--- format.el Mon Jul 2 08:54:40 2007
***************
*** 429,441 ****
(fmt (format-read (format "Read file `%s' in format: "
(file-name-nondirectory file)))))
(list file fmt)))
! (let (value size)
! (let ((format-alist nil))
! (setq value (insert-file-contents filename nil beg end))
! (setq size (nth 1 value)))
! (if format
! (setq size (format-decode format size)
! value (list (car value) size)))
value))
(defun format-read (&optional prompt)
--- 429,462 ----
(fmt (format-read (format "Read file `%s' in format: "
(file-name-nondirectory file)))))
(list file fmt)))
! (let (value size old-undo)
! ;; Record only one undo entry for the insertion. Inhibit point-motion and
! ;; modification hooks as with `insert-file-contents'.
! (let ((inhibit-point-motion-hooks t)
! (inhibit-modification-hooks t))
! ;; Don't bind `buffer-undo-list' to t here to assert that
! ;; `insert-file-contents' may record whether the buffer was unmodified
! ;; before.
! (let ((format-alist nil))
! (setq value (insert-file-contents filename nil beg end))
! (setq size (nth 1 value)))
! (when (consp buffer-undo-list)
! (let ((head (car buffer-undo-list)))
! (when (and (consp head)
! (equal (car head) (point))
! (equal (cdr head) (+ (point) size)))
! ;; Remove first entry from `buffer-undo-list', we shall insert
! ;; another one below.
! (setq old-undo (cdr buffer-undo-list)))))
! (when format
! (let ((buffer-undo-list t))
! (setq size (format-decode format size)
! value (list (car value) size)))
! (unless (eq buffer-undo-list t)
! (setq buffer-undo-list
! (cons (cons (point) (+ (point) size)) old-undo)))))
! (unless inhibit-modification-hooks
! (run-hook-with-args 'after-change-functions (point) (+ (point) size) 0))
value))
(defun format-read (&optional prompt)
- Re: insert-file-contents and format-decode,
martin rudalics <=