Subject: 30.0.50; emacs 30.5.0 editing epub encoding system

From: H.-J. Heitländer <[email-masked]>
Date: Fri, 17 Mar 2023 09:02:16 +0000

Hi there

emacs seems to be losing the encoding system when editing and saving an 
epub file.

If needed I can provide a test epub file (ca. 250KB)

TIA

Heiner

test case 1)

Start <emacs -Q>

1) enter epub <C-x D> .../test.epub <ENTER>

2) switch to edit In DocView(?) <C-c C-c>

3) open file ...4.html <Enter>

4) change a line (for instance " " => " ")

5) save file <C-x C-f>

6) Symptom: minibuffer display "Wrong Type Argument: stringp, nil"

7) message Buffer

<snip>

Type C-c C-c to toggle between editing or viewing the document.

Parsing archive file...done.

Type C-c C-c to toggle between editing or viewing the document.

Saving file /home/uuu/CaLib/Author/test (6551)/test - 
author.epub:OEBPS/_public_vhost_g_gutenberg_html_files_3300_3300-h_3300-h-4.htm.html...

Updating archive...done

apply: Wrong type argument: stringp, nil

</snip>

test case 2)

start emacs (with custom init.el file)

1) <M-x load-file RET arc-mode.el>

<M-x load-file RET files.el>

<M-x load-file RET docview.el>

2) zoom to test file <C-x D RET> => /test

dir entry test

<snip>

drwxr-xr-x 2 user ugrp 4096 17. Mär 08:58 .

drwxr-xr-x 3 user ugrp 4096 17. Mär 09:06 ..

-rw-r--r-- 1 user ugrp 58207 17. Mär 08:06 cover.jpg

-rw-r--r-- 1 user ugrp 1237 17. Mär 08:06 metadata.opf

-rw-r--r-- 1 user ugrp 234869 17. Mär 08:58 test - Adam Smith.epub

</snip>

3) open test - Adam Smith.epub

4) minibuffer: Type C-c C-c to toggle between editing or viewing the 
document.

<C-c C-c>

5) open file <... 4.html RET>

6) change file (for instance " " => " ">

7) save file <C-x C-s>

8) backtrace in Appendix

Symptoms:

9) buffers are losing the encoding system (mode-line starts with "=:--- 
test..."

10 Directory buffer display in basic mode(?) (mode-line starts with 
"U:%%- emac...)

<snip>

-rw-r--r-- 1 user ugrp 250080 1. Jun 2022 reset-W10-Admin-PW.odt

-rw-r--r-- 1 user ugrp 954390 17. Mär 08:03 test1.epub

-rw-r--r-- 1 user ugrp 954390 17. Mär 07:55 test.epub

</snip>

Appendix: backtrace

<snip>

Debugger entered--Lisp error: (wrong-type-argument stringp nil)

write-region(nil nil nil)

(if (equal buffer-file-name doc-view--buffer-file-name) nil 
(doc-view-make-safe-dir doc-view-cache-directory) (write-region nil nil 
doc-view--buffer-file-name))

(let ((revert-buffer-preserve-modes t)) (apply orig-fun args) (if (equal 
buffer-file-name doc-view--buffer-file-name) nil (doc-view-make-safe-dir 
doc-view-cache-directory) (write-region nil nil 
doc-view--buffer-file-name)))

(closure ((args t t) (orig-fun . #f(compiled-function (&rest args) 
#<bytecode -0x1d1afa23a289a2b6>)) revert-buffer-preserve-modes) nil (let 
((revert-buffer-preserve-modes t)) (apply orig-fun args) (if (equal 
buffer-file-name doc-view--buffer-file-name) nil (doc-view-make-safe-dir 
doc-view-cache-directory) (write-region nil nil 
doc-view--buffer-file-name))))()

funcall((closure ((args t t) (orig-fun . #f(compiled-function (&rest 
args) #<bytecode -0x1d1afa23a289a2b6>)) revert-buffer-preserve-modes) 
nil (let ((revert-buffer-preserve-modes t)) (apply orig-fun args) (if 
(equal buffer-file-name doc-view--buffer-file-name) nil 
(doc-view-make-safe-dir doc-view-cache-directory) (write-region nil nil 
doc-view--buffer-file-name)))))

(if (and (eq 'pdf doc-view-doc-type) (executable-find "pdfinfo")) (if (= 
0 (call-process "pdfinfo" nil nil nil doc-view--buffer-file-name)) 
(funcall --cl-revert--) (if (called-interactively-p 'interactive) (progn 
(message "Can't revert right now because the file is corrupt...")))) 
(funcall --cl-revert--))

(let* ((--cl-revert-- #'(lambda nil (let ((revert-buffer-preserve-modes 
t)) (apply orig-fun args) (if (equal buffer-file-name 
doc-view--buffer-file-name) nil (doc-view-make-safe-dir 
doc-view-cache-directory) (write-region nil nil 
doc-view--buffer-file-name)))))) (if (and (eq 'pdf doc-view-doc-type) 
(executable-find "pdfinfo")) (if (= 0 (call-process "pdfinfo" nil nil 
nil doc-view--buffer-file-name)) (funcall --cl-revert--) (if 
(called-interactively-p 'interactive) (progn (message "Can't revert 
right now because the file is corrupt...")))) (funcall --cl-revert--)))

doc-view--revert-buffer(#f(compiled-function (&rest args) #<bytecode 
-0x1d1afa23a289a2b6>) t t)

apply(doc-view--revert-buffer #f(compiled-function (&rest args) 
#<bytecode -0x1d1afa23a289a2b6>) (t t))

#f(advice doc-view--revert-buffer :around #f(compiled-function (&rest 
args) #<bytecode -0x1d1afa23a289a2b6>))(t t)

apply(#f(advice doc-view--revert-buffer :around #f(compiled-function 
(&rest args) #<bytecode -0x1d1afa23a289a2b6>)) t t nil)

(let ((coding-system-for-read 'no-conversion)) (apply orig-fun t t (cdr 
(cdr args))))

(let ((no (archive-get-lineno))) (setq archive-files nil) (let 
((coding-system-for-read 'no-conversion)) (apply orig-fun t t (cdr (cdr 
args)))) (archive-mode) (goto-char archive-file-list-start) 
(archive-next-line no))

archive--mode-revert(#f(advice doc-view--revert-buffer :around 
#f(compiled-function (&rest args) #<bytecode -0x1d1afa23a289a2b6>)) nil nil)

apply(archive--mode-revert #f(advice doc-view--revert-buffer :around 
#f(compiled-function (&rest args) #<bytecode -0x1d1afa23a289a2b6>)) (nil 
nil))

#f(advice archive--mode-revert :around #f(advice doc-view--revert-buffer 
:around #f(compiled-function (&rest args) #<bytecode 
-0x1d1afa23a289a2b6>)))(nil nil)

funcall(#f(advice archive--mode-revert :around #f(advice 
doc-view--revert-buffer :around #f(compiled-function (&rest args) 
#<bytecode -0x1d1afa23a289a2b6>))) nil nil)

(let ((revert-buffer-in-progress-p t) (revert-buffer-preserve-modes 
preserve-modes) (state (and (boundp 'read-only-mode--state) (list 
read-only-mode--state)))) (funcall (or revert-buffer-function 
#'revert-buffer--default) ignore-auto noconfirm) (if state (progn (setq 
buffer-read-only (car state)) (set (make-local-variable 
'read-only-mode--state) (car state)))))

revert-buffer()

(if (not archive-remote) (revert-buffer) (archive-maybe-update nil))

(save-restriction (message "Updating archive...") (widen) (let ((writer 
(save-current-buffer (set-buffer archive-superior-buffer) (archive-name 
"write-file-member"))) (archive (save-current-buffer (set-buffer 
archive-superior-buffer) (archive-maybe-copy (buffer-file-name))))) (if 
(fboundp writer) (funcall writer archive archive-subfile-mode) 
(archive-*-write-file-member archive archive-subfile-mode (symbol-value 
writer))) (set-buffer-modified-p nil) (message "Updating 
archive...done")) (set-buffer archive-superior-buffer) (if (not 
archive-remote) (revert-buffer) (archive-maybe-update nil)))

(save-excursion (save-restriction (message "Updating archive...") 
(widen) (let ((writer (save-current-buffer (set-buffer 
archive-superior-buffer) (archive-name "write-file-member"))) (archive 
(save-current-buffer (set-buffer archive-superior-buffer) 
(archive-maybe-copy (buffer-file-name))))) (if (fboundp writer) (funcall 
writer archive archive-subfile-mode) (archive-*-write-file-member 
archive archive-subfile-mode (symbol-value writer))) 
(set-buffer-modified-p nil) (message "Updating archive...done")) 
(set-buffer archive-superior-buffer) (if (not archive-remote) 
(revert-buffer) (archive-maybe-update nil))))

archive-write-file-member()

run-hook-with-args-until-success(archive-write-file-member)

(or (run-hook-with-args-until-success 'local-write-file-hooks) 
(run-hook-with-args-until-success 'write-file-functions) (let ((dir 
(file-name-directory (expand-file-name buffer-file-name)))) (if 
(file-exists-p dir) nil (if (y-or-n-p (format-message "Directory `%s' 
does not exist; create? " dir)) (make-directory dir t) (error 
"Canceled"))) (setq setmodes (basic-save-buffer-1))))

(if (run-hook-with-args-until-success 'write-contents-functions) nil (or 
buffer-file-name (let ((filename (expand-file-name (read-file-name "File 
to save in: " nil (expand-file-name ...))))) (if (file-exists-p 
filename) (if (file-directory-p filename) (error "%s is a directory" 
filename) (if (y-or-n-p (format-message "File `%s' exists; overwrite? " 
filename)) nil (error "Canceled")))) (set-visited-file-name filename))) 
(vc-before-save) (or (run-hook-with-args-until-success 
'local-write-file-hooks) (run-hook-with-args-until-success 
'write-file-functions) (let ((dir (file-name-directory (expand-file-name 
buffer-file-name)))) (if (file-exists-p dir) nil (if (y-or-n-p 
(format-message "Directory `%s' does not exist; create? " dir)) 
(make-directory dir t) (error "Canceled"))) (setq setmodes 
(basic-save-buffer-1)))))

(save-restriction (widen) (save-excursion (and (> (point-max) 
(point-min)) (not find-file-literally) (null buffer-read-only) (/= 
(char-after (1- (point-max))) 10) (not (and (eq selective-display t) (= 
(char-after (1- ...)) 13))) (or (eq require-final-newline t) (eq 
require-final-newline 'visit-save) (and require-final-newline (y-or-n-p 
(format "Buffer %s does not end in newline. Add one? " (buffer-name))))) 
(save-excursion (goto-char (point-max)) (insert 10)))) (condition-case 
err (run-hooks 'before-save-hook) ((debug error) (message "Before-save 
hook error: %S" err) nil)) (if (run-hook-with-args-until-success 
'write-contents-functions) nil (or buffer-file-name (let ((filename 
(expand-file-name (read-file-name "File to save in: " nil ...)))) (if 
(file-exists-p filename) (if (file-directory-p filename) (error "%s is a 
directory" filename) (if (y-or-n-p ...) nil (error "Canceled")))) 
(set-visited-file-name filename))) (vc-before-save) (or 
(run-hook-with-args-until-success 'local-write-file-hooks) 
(run-hook-with-args-until-success 'write-file-functions) (let ((dir 
(file-name-directory (expand-file-name buffer-file-name)))) (if 
(file-exists-p dir) nil (if (y-or-n-p (format-message "Directory `%s' 
does not exist; create? " dir)) (make-directory dir t) (error 
"Canceled"))) (setq setmodes (basic-save-buffer-1))))) (if 
buffer-file-name (progn (if save-buffer-coding-system (setq 
save-buffer-coding-system last-coding-system-used) (setq 
buffer-file-coding-system last-coding-system-used)) (setq 
buffer-file-number (file-attribute-file-identifier (file-attributes 
buffer-file-name))) (if setmodes (condition-case nil (progn (if 
(condition-case err ... ...) nil (set-file-extended-attributes 
buffer-file-name ...))) (error nil))) (vc-after-save))) 
(delete-auto-save-file-if-necessary recent-save))

(let ((recent-save (recent-auto-save-p)) setmodes) (or (null 
buffer-file-name) (verify-visited-file-modtime (current-buffer)) (not 
(file-exists-p buffer-file-name)) (yes-or-no-p (format "%s has changed 
since visited or saved. Save anywa..." (file-name-nondirectory 
buffer-file-name))) (user-error "Save not confirmed")) (save-restriction 
(widen) (save-excursion (and (> (point-max) (point-min)) (not 
find-file-literally) (null buffer-read-only) (/= (char-after (1- 
(point-max))) 10) (not (and (eq selective-display t) (= (char-after ...) 
13))) (or (eq require-final-newline t) (eq require-final-newline 
'visit-save) (and require-final-newline (y-or-n-p (format "Buffer %s 
does not end in newline. Add one? " ...)))) (save-excursion (goto-char 
(point-max)) (insert 10)))) (condition-case err (run-hooks 
'before-save-hook) ((debug error) (message "Before-save hook error: %S" 
err) nil)) (if (run-hook-with-args-until-success 
'write-contents-functions) nil (or buffer-file-name (let ((filename 
(expand-file-name ...))) (if (file-exists-p filename) (if 
(file-directory-p filename) (error "%s is a directory" filename) (if ... 
nil ...))) (set-visited-file-name filename))) (vc-before-save) (or 
(run-hook-with-args-until-success 'local-write-file-hooks) 
(run-hook-with-args-until-success 'write-file-functions) (let ((dir 
(file-name-directory ...))) (if (file-exists-p dir) nil (if (y-or-n-p 
...) (make-directory dir t) (error "Canceled"))) (setq setmodes 
(basic-save-buffer-1))))) (if buffer-file-name (progn (if 
save-buffer-coding-system (setq save-buffer-coding-system 
last-coding-system-used) (setq buffer-file-coding-system 
last-coding-system-used)) (setq buffer-file-number 
(file-attribute-file-identifier (file-attributes buffer-file-name))) (if 
setmodes (condition-case nil (progn (if ... nil ...)) (error nil))) 
(vc-after-save))) (delete-auto-save-file-if-necessary recent-save)) 
(run-hooks 'after-save-hook))

(if (or (buffer-modified-p) (and buffer-file-name (not (file-exists-p 
buffer-file-name)))) (let ((recent-save (recent-auto-save-p)) setmodes) 
(or (null buffer-file-name) (verify-visited-file-modtime 
(current-buffer)) (not (file-exists-p buffer-file-name)) (yes-or-no-p 
(format "%s has changed since visited or saved. Save anywa..." 
(file-name-nondirectory buffer-file-name))) (user-error "Save not 
confirmed")) (save-restriction (widen) (save-excursion (and (> 
(point-max) (point-min)) (not find-file-literally) (null 
buffer-read-only) (/= (char-after (1- ...)) 10) (not (and (eq 
selective-display t) (= ... 13))) (or (eq require-final-newline t) (eq 
require-final-newline 'visit-save) (and require-final-newline (y-or-n-p 
...))) (save-excursion (goto-char (point-max)) (insert 10)))) 
(condition-case err (run-hooks 'before-save-hook) ((debug error) 
(message "Before-save hook error: %S" err) nil)) (if 
(run-hook-with-args-until-success 'write-contents-functions) nil (or 
buffer-file-name (let ((filename ...)) (if (file-exists-p filename) (if 
... ... ...)) (set-visited-file-name filename))) (vc-before-save) (or 
(run-hook-with-args-until-success 'local-write-file-hooks) 
(run-hook-with-args-until-success 'write-file-functions) (let ((dir 
...)) (if (file-exists-p dir) nil (if ... ... ...)) (setq setmodes 
(basic-save-buffer-1))))) (if buffer-file-name (progn (if 
save-buffer-coding-system (setq save-buffer-coding-system 
last-coding-system-used) (setq buffer-file-coding-system 
last-coding-system-used)) (setq buffer-file-number 
(file-attribute-file-identifier (file-attributes buffer-file-name))) (if 
setmodes (condition-case nil (progn ...) (error nil))) (vc-after-save))) 
(delete-auto-save-file-if-necessary recent-save)) (run-hooks 
'after-save-hook)) (or noninteractive (not called-interactively) 
(files--message "(No changes need to be saved)")))

(save-current-buffer (if (buffer-base-buffer) (set-buffer 
(buffer-base-buffer))) (if (or (buffer-modified-p) (and buffer-file-name 
(not (file-exists-p buffer-file-name)))) (let ((recent-save 
(recent-auto-save-p)) setmodes) (or (null buffer-file-name) 
(verify-visited-file-modtime (current-buffer)) (not (file-exists-p 
buffer-file-name)) (yes-or-no-p (format "%s has changed since visited or 
saved. Save anywa..." (file-name-nondirectory buffer-file-name))) 
(user-error "Save not confirmed")) (save-restriction (widen) 
(save-excursion (and (> (point-max) (point-min)) (not 
find-file-literally) (null buffer-read-only) (/= (char-after ...) 10) 
(not (and ... ...)) (or (eq require-final-newline t) (eq 
require-final-newline ...) (and require-final-newline ...)) 
(save-excursion (goto-char ...) (insert 10)))) (condition-case err 
(run-hooks 'before-save-hook) ((debug error) (message "Before-save hook 
error: %S" err) nil)) (if (run-hook-with-args-until-success 
'write-contents-functions) nil (or buffer-file-name (let (...) (if ... 
...) (set-visited-file-name filename))) (vc-before-save) (or 
(run-hook-with-args-until-success 'local-write-file-hooks) 
(run-hook-with-args-until-success 'write-file-functions) (let (...) (if 
... nil ...) (setq setmodes ...)))) (if buffer-file-name (progn (if 
save-buffer-coding-system (setq save-buffer-coding-system 
last-coding-system-used) (setq buffer-file-coding-system 
last-coding-system-used)) (setq buffer-file-number 
(file-attribute-file-identifier ...)) (if setmodes (condition-case nil 
... ...)) (vc-after-save))) (delete-auto-save-file-if-necessary 
recent-save)) (run-hooks 'after-save-hook)) (or noninteractive (not 
called-interactively) (files--message "(No changes need to be saved)"))))

basic-save-buffer(t)

(let ((modp (buffer-modified-p)) (make-backup-files (or (and 
make-backup-files (not (eq arg 0))) (memq arg '(16 64))))) (and modp 
(memq arg '(16 64)) (setq buffer-backed-up nil)) (if (and modp 
(buffer-file-name) (not noninteractive) (not save-silently)) (message 
"Saving file %s..." (buffer-file-name))) (basic-save-buffer 
(called-interactively-p 'any)) (and modp (memq arg '(4 64)) (setq 
buffer-backed-up nil)))

save-buffer(1)

funcall-interactively(save-buffer 1)

command-execute(save-buffer)

</snip>

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.36, cairo version 1.16.0) of 2023-03-02 built on fafnir
Repository revision: a798a29f7519244b47ffc3035fcd8bf7bafea4d5
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux bookworm/sid

Configured using:
'configure --with-json=ifavailable --with-modules --with-harfbuzz
--with-compress-install --with-threads --with-included-regex
--with-zlib --with-cairo --without-rsvg --without-sound
--without-imagemagick --without-toolkit-scroll-bars --without-gpm
--without-dbus --without-pop --with-mailutils --without-gsettings
--with-native-compilation --with-gnutls=ifavailable'

Configured features:
ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBOTF
LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG SECCOMP THREADS TIFF WEBP X11 XDBE XIM XINPUT2 XPM
GTK3 ZLIB

Important settings:
value of $LC_ALL: de_DE.UTF-8
value of $LC_MONETARY: de_DE.UTF-8
value of $LC_NUMERIC: de_DE.UTF-8
value of $LC_TIME: de_DE.UTF-8
value of $LANG: de_DE.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
show-paren-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads inotify lcms2 dynamic-setting
font-render-setting cairo move-toolbar gtk x-toolkit xinput2 x multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 76587 8662)
(symbols 48 7136 0)
(strings 32 19323 2067)
(string-bytes 1 574138)
(vectors 16 15417)
(vector-slots 8 319353 13066)
(floats 8 28 54)
(intervals 56 234 0)
(buffers 976 11))