Subtract a buffer's (the file's) size from a variable before killing it. Emacs 26.
(defvar cumulative-open-bytes '0 ) (defun buffer-settings-calc-bytes () (interactive) (let ((current-open-file-size (file-attribute-size (file-attributes buffer-file-name)))) (setq cumulative-open-bytes (- current-open-file-size cumulative-open-bytes)) (message (propertize (format "Cumulative Open Bytes: (%d) after closing %s (%d bytes)." cumulative-open-bytes buffer-file-name current-open-file-size) 'face 'warning)))) (add-hook 'kill-buffer-hook 'buffer-settings-calc-bytes)
Results in the following message:
setq: Wrong type argument: number-or-marker-p, nil
This appears just after the string message from the function.
I have tried
setq in place of the
let, and removing
Emacs will not load with the above, and evaluating it in place breaks
most navigation and buffer features.
The following also appears invoking arbitrary commands in addition to the above:
Error running timer: (wrong-type-argument number-or-marker-p nil)
Is this a local binding issue? How should this hook be set?