[21.4] Fix file-name handling for `insert-file-contents'

Vin Shelton acs at xemacs.org
Wed Oct 14 12:26:07 EDT 2009


Mike -

I'll apply this fix.  Once I commit, look the changes over because I
had to apply them by hand.

Please consider creating a test for this.

Thank you,
  Vin

2009/10/14 Michael Sperber <sperber at deinprogramm.de>:
>
> Hi Vin,
>
> I don't know if you've followed the discussion on xemacs-beta, but this
> patch fixes breakage beyond what I originally saw, specifically image
> specifier handling with :file, as reported by David.  Could this go into
> 21.4?
>
> changeset:   3722:a0adf5f08c44
> user:        michaels
> date:        Tue Dec 05 08:21:03 2006 +0000
> files:       lisp/ChangeLog lisp/code-files.el src/ChangeLog src/fileio.c
> description:
> [xemacs-hg @ 2006-12-05 08:20:54 by michaels]
> 2006-11-30  Mike Sperber  <mike at xemacs.org>
>
>        * fileio.c (Finsert_file_contents_internal): Don't call the
>        file-name handler for `insert-file-contents' from here, which is
>        too late.  Instead, do it from Lisp.SSper
>
> 2006-11-30  Mike Sperber  <mike at xemacs.org>
>
>        * code-files.el (insert-file-contents): Call the file-name handler
>        from Lisp, not from `insert-file-contents-internal', which is too late.
>
>
> --
> Cheers =8-} Mike
> Friede, Völkerverständigung und überhaupt blabla
>
> changeset:   3722:a0adf5f08c44
> user:        michaels
> date:        Tue Dec 05 08:21:03 2006 +0000
> files:       lisp/ChangeLog lisp/code-files.el src/ChangeLog src/fileio.c
> description:
> [xemacs-hg @ 2006-12-05 08:20:54 by michaels]
> 2006-11-30  Mike Sperber  <mike at xemacs.org>
>
>        * fileio.c (Finsert_file_contents_internal): Don't call the
>        file-name handler for `insert-file-contents' from here, which is
>        too late.  Instead, do it from Lisp.SSper
>
> 2006-11-30  Mike Sperber  <mike at xemacs.org>
>
>        * code-files.el (insert-file-contents): Call the file-name handler
>        from Lisp, not from `insert-file-contents-internal', which is too late.
>
>
> diff --git a/lisp/ChangeLog b/lisp/ChangeLog
> --- a/lisp/ChangeLog
> +++ b/lisp/ChangeLog
> @@ -1,3 +1,8 @@
> +2006-11-30  Mike Sperber  <mike at xemacs.org>
> +
> +       * code-files.el (insert-file-contents): Call the file-name handler
> +       from Lisp, not from `insert-file-contents-internal', which is too late.
> +
>  2006-11-28  Mike Sperber  <mike at xemacs.org>
>
>        * files.el (revert-buffer-internal): Determine the coding system
> diff --git a/lisp/code-files.el b/lisp/code-files.el
> --- a/lisp/code-files.el
> +++ b/lisp/code-files.el
> @@ -382,86 +382,90 @@
>  See also `insert-file-contents-access-hook',
>  `insert-file-contents-pre-hook', `insert-file-contents-error-hook',
>  and `insert-file-contents-post-hook'."
> -  (let (return-val coding-system used-codesys)
> -    ;; OK, first load the file.
> -    (condition-case err
> -       (progn
> -         (run-hook-with-args 'insert-file-contents-access-hook
> -                             filename visit)
> -         ;; determine the coding system to use, as described above.
> -         (setq coding-system
> -               (or
> -                ;; #1.
> -                coding-system-for-read
> -                ;; #2.
> -                (run-hook-with-args-until-success
> -                 'insert-file-contents-pre-hook
> -                 filename visit)
> -                ;; #3.
> -                (find-file-coding-system-for-read-from-filename filename)
> -                ;; #4.
> -                buffer-file-coding-system-for-read
> -                ;; #5.
> -                'raw-text))
> -         (if (consp coding-system)
> -             (setq return-val coding-system)
> -           (if (null (find-coding-system coding-system))
> -               (progn
> -                 (lwarn 'coding-system 'notice
> -                  "Invalid coding-system (%s), using 'undecided"
> -                  coding-system)
> -                 (setq coding-system 'undecided)))
> -           (setq return-val
> -                 (insert-file-contents-internal filename visit start end
> -                                                replace coding-system
> -                                                ;; store here!
> -                                                'used-codesys))
> -           ))
> -      (file-error
> -       (run-hook-with-args 'insert-file-contents-error-hook
> -                          filename visit err)
> -       (signal (car err) (cdr err))))
> -    (setq coding-system used-codesys)
> -    ;; call any `post-read-conversion' for the coding system that
> -    ;; was used ...
> -    (let ((func
> -          (coding-system-property coding-system 'post-read-conversion))
> -         (endmark (make-marker)))
> -      (set-marker endmark (+ (point) (nth 1 return-val)))
> -      (if func
> -         (unwind-protect
> -             (save-excursion
> -               (let (buffer-read-only)
> -                 (if (>= (function-max-args func) 2)
> -                     ;; #### fuckme!  Someone at FSF changed the calling
> -                     ;; convention of post-read-conversion.  We try to
> -                     ;; support the old way.  #### Should we kill this?
> -                     (funcall func (point) (marker-position endmark))
> -                   (funcall func (- (marker-position endmark) (point))))))
> -           (if visit
> -               (progn
> -                 (set-buffer-auto-saved)
> -                 (set-buffer-modified-p nil)))))
> -      (setcar (cdr return-val) (- (marker-position endmark) (point))))
> -    ;; now finally set the buffer's `buffer-file-coding-system' ...
> -    (if (run-hook-with-args-until-success 'insert-file-contents-post-hook
> -                                         filename visit return-val)
> -       nil
> -      (if (local-variable-p 'buffer-file-coding-system (current-buffer))
> -         ;; if buffer-file-coding-system is already local, just
> -         ;; set its eol type to what was found, if it wasn't
> -         ;; set already.
> -         (set-buffer-file-coding-system
> -          (subsidiary-coding-system buffer-file-coding-system
> -                                    (coding-system-eol-type coding-system)) t)
> -       ;; otherwise actually set buffer-file-coding-system.
> -       (set-buffer-file-coding-system coding-system t)))
> -    ;; ... and `buffer-file-coding-system-when-loaded'.  the machinations
> -    ;; of set-buffer-file-coding-system cause the actual coding system
> -    ;; object to be stored, so do that here, too.
> -    (setq buffer-file-coding-system-when-loaded
> -         (get-coding-system coding-system))
> -    return-val))
> +  (let* ((expanded (substitute-in-file-name filename))
> +        (handler (find-file-name-handler expanded 'insert-file-contents)))
> +    (if handler
> +       (funcall handler 'insert-file-contents filename visit start end replace)
> +      (let (return-val coding-system used-codesys)
> +       ;; OK, first load the file.
> +       (condition-case err
> +           (progn
> +             (run-hook-with-args 'insert-file-contents-access-hook
> +                                 filename visit)
> +             ;; determine the coding system to use, as described above.
> +             (setq coding-system
> +                   (or
> +                    ;; #1.
> +                    coding-system-for-read
> +                    ;; #2.
> +                    (run-hook-with-args-until-success
> +                     'insert-file-contents-pre-hook
> +                     filename visit)
> +                    ;; #3.
> +                    (find-file-coding-system-for-read-from-filename filename)
> +                    ;; #4.
> +                    buffer-file-coding-system-for-read
> +                    ;; #5.
> +                    'raw-text))
> +             (if (consp coding-system)
> +                 (setq return-val coding-system)
> +               (if (null (find-coding-system coding-system))
> +                   (progn
> +                     (lwarn 'coding-system 'notice
> +                       "Invalid coding-system (%s), using 'undecided"
> +                       coding-system)
> +                     (setq coding-system 'undecided)))
> +               (setq return-val
> +                     (insert-file-contents-internal filename visit start end
> +                                                    replace coding-system
> +                                                    ;; store here!
> +                                                    'used-codesys))
> +               ))
> +         (file-error
> +          (run-hook-with-args 'insert-file-contents-error-hook
> +                              filename visit err)
> +          (signal (car err) (cdr err))))
> +       (setq coding-system used-codesys)
> +       ;; call any `post-read-conversion' for the coding system that
> +       ;; was used ...
> +       (let ((func
> +              (coding-system-property coding-system 'post-read-conversion))
> +             (endmark (make-marker)))
> +         (set-marker endmark (+ (point) (nth 1 return-val)))
> +         (if func
> +             (unwind-protect
> +                 (save-excursion
> +                   (let (buffer-read-only)
> +                     (if (>= (function-max-args func) 2)
> +                         ;; #### fuckme!  Someone at FSF changed the calling
> +                         ;; convention of post-read-conversion.  We try to
> +                         ;; support the old way.  #### Should we kill this?
> +                         (funcall func (point) (marker-position endmark))
> +                       (funcall func (- (marker-position endmark) (point))))))
> +               (if visit
> +                   (progn
> +                     (set-buffer-auto-saved)
> +                     (set-buffer-modified-p nil)))))
> +         (setcar (cdr return-val) (- (marker-position endmark) (point))))
> +       ;; now finally set the buffer's `buffer-file-coding-system' ...
> +       (if (run-hook-with-args-until-success 'insert-file-contents-post-hook
> +                                             filename visit return-val)
> +           nil
> +         (if (local-variable-p 'buffer-file-coding-system (current-buffer))
> +             ;; if buffer-file-coding-system is already local, just
> +             ;; set its eol type to what was found, if it wasn't
> +             ;; set already.
> +             (set-buffer-file-coding-system
> +              (subsidiary-coding-system buffer-file-coding-system
> +                                        (coding-system-eol-type coding-system)) t)
> +           ;; otherwise actually set buffer-file-coding-system.
> +           (set-buffer-file-coding-system coding-system t)))
> +       ;; ... and `buffer-file-coding-system-when-loaded'.  the machinations
> +       ;; of set-buffer-file-coding-system cause the actual coding system
> +       ;; object to be stored, so do that here, too.
> +       (setq buffer-file-coding-system-when-loaded
> +             (get-coding-system coding-system))
> +       return-val))))
>
>  (defvar write-region-pre-hook nil
>   "A special hook to decide the coding system used for writing out a file.
> diff --git a/src/ChangeLog b/src/ChangeLog
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,9 @@
> +2006-11-30  Mike Sperber  <mike at xemacs.org>
> +
> +       * fileio.c (Finsert_file_contents_internal): Don't call the
> +       file-name handler for `insert-file-contents' from here, which is
> +       too late.  Instead, do it from Lisp.SSper
> +
>  2006-11-29  Dr. Volker Zell  <Dr.Volker.Zell at oracle.com>
>
>        * sysdir.h: Revert workaround missing d_ino field from 'struct
> diff --git a/src/fileio.c b/src/fileio.c
> --- a/src/fileio.c
> +++ b/src/fileio.c
> @@ -2844,16 +2844,6 @@
>
>   filename = Fexpand_file_name (filename, Qnil);
>
> -  /* If the file name has special constructs in it,
> -     call the corresponding file handler.  */
> -  handler = Ffind_file_name_handler (filename, Qinsert_file_contents);
> -  if (!NILP (handler))
> -    {
> -      val = call6 (handler, Qinsert_file_contents, filename,
> -                  visit, start, end, replace);
> -      goto handled;
> -    }
> -
>   if (!NILP (used_codesys))
>     CHECK_SYMBOL (used_codesys);
>
>
>
> _______________________________________________
> XEmacs-Patches mailing list
> XEmacs-Patches at calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/xemacs-patches
>
>



More information about the XEmacs-Patches mailing list