darkroom icon indicating copy to clipboard operation
darkroom copied to clipboard

arithmetic error and failing to unload

Open TLINDEN opened this issue 8 years ago • 0 comments

I'd like to use darkroom.el as minor mode with org-present.el, a slide-show mode for org-mode. Here's my config:

;; slideshows
(load-file (concat my-lisp "/org-present.el"))
(load-file (concat my-lisp "/darkroom.el"))
(eval-after-load "org-present"
  '(progn
     (add-hook 'org-present-mode-hook
               (lambda ()
                 (org-present-big)
                 (org-display-inline-images)
                 (org-present-hide-cursor)
                 (org-present-read-only)
                 (darkroom-tentative-mode)
     ))

     (add-hook 'org-present-mode-quit-hook
               (lambda ()
                 (org-present-small)
                 (org-remove-inline-images)
                 (org-present-show-cursor)
                 (org-present-read-write)
                 (darkroom-tentative-mode)
     ))
     )
  )

When I start an org-present slideshow with an org file, the darkroom minor mode starts as well. It works but it shows an "Arithmetic Error" on the botton. However after the first keystroke (or a mouse click somewhere) during the slideshow this error vanishes. Also, the scrollbar on the right is still visible (in normal mode I have it enabled). Screenshot:

math error

Since I don't intent to use darkroom outside of slideshows, I turn it off when the slideshow finishes. Then the display looks a bit "destroyed", see screenshot:

weird display

Emacs still works as it should but it seems, it has a 5 cm wide invisible left margin of some kind. Also darkroom seems to be still active, there's no modeline and it's a bit messy to get emacs back to normal.

I'm not sure if this is important: I'm working on Xmonad, so my windows don't have borders or titlebars, just in case you're wondering about the screenshots. Also I can reproduce the problem on different platforms and versions (FreeBSD and Linux, different emacs and xmonad versions).


As you suggested by mail, I run it with debugging enabled, here's the output for the first error:

Debugger entered--Lisp error: (arith-error)
  truncate(1884 0)
  (cons (truncate (+ (window-width window (quote pixelwise)) (* char-width (or (car margins) 0)) (* char-width (or (cdr margins) 0))) scaled-char-width) scaled-char-width)
  (let* ((window (or window (selected-window))) (scaled-char-width (car (window-text-pixel-size window (point-min) (1+ (point-min))))) (char-width (frame-char-width)) (margins (window-margins window))) (cons (truncate (+ (window-width window (quote pixelwise)) (* char-width (or (car margins) 0)) (* char-width (or (cdr margins) 0))) scaled-char-width) scaled-char-width))
  darkroom--window-width(#<window 3 on *slide*>)
  (if (integerp window) window (darkroom--window-width window))
  (let* ((window-width-info (if (integerp window) window (darkroom--window-width window))) (window-width (car window-width-info)) (scaled-char-width (cdr window-width-info)) (top-quartile-avg (or darkroom--guess-margins-statistics-cache (set (make-local-variable (quote darkroom--guess-margins-statistics-cache)) (let* ((line-widths ...) (n4 ...)) (/ (apply ... ...) n4)))))) (cond ((> top-quartile-avg window-width) (message "Long lines detected. Consider turning on `visual-line-mode'") darkroom-margins-if-failed-guess) ((> top-quartile-avg (* 0.9 fill-column)) (let ((margin (truncate (* ... ...) 2))) (if darkroom-verbose (message "Choosing %s-wide margins based on fill-column %s" margin fill-column)) (cons margin margin))) (t darkroom-margins-if-failed-guess)))
  (if (or visual-line-mode (and buffer-face-mode (eq (quote variable-pitch) buffer-face-mode-face)) (= (point-min) (point-max))) darkroom-margins-if-failed-guess (let* ((window-width-info (if (integerp window) window (darkroom--window-width window))) (window-width (car window-width-info)) (scaled-char-width (cdr window-width-info)) (top-quartile-avg (or darkroom--guess-margins-statistics-cache (set (make-local-variable (quote darkroom--guess-margins-statistics-cache)) (let* (... ...) (/ ... n4)))))) (cond ((> top-quartile-avg window-width) (message "Long lines detected. Consider turning on `visual-line-mode'") darkroom-margins-if-failed-guess) ((> top-quartile-avg (* 0.9 fill-column)) (let ((margin (truncate ... 2))) (if darkroom-verbose (message "Choosing %s-wide margins based on fill-column %s" margin fill-column)) (cons margin margin))) (t darkroom-margins-if-failed-guess))))
  darkroom-guess-margins(#<window 3 on *slide*>)
  funcall(darkroom-guess-margins #<window 3 on *slide*>)
  (if (functionp darkroom-margins) (funcall darkroom-margins window) darkroom-margins)
  (let ((darkroom-margins (if (functionp darkroom-margins) (funcall darkroom-margins window) darkroom-margins))) (cond ((consp darkroom-margins) darkroom-margins) ((and (floatp darkroom-margins) (< darkroom-margins 1)) (let ((delta (darkroom--float-to-columns darkroom-margins))) (cons delta delta))) (t (error "Illegal value in `darkroom-margins'"))))
  darkroom--compute-margins(#<window 3 on *slide*>)
  (let* ((window-configuration-change-hook nil) (window (selected-window)) (margins (darkroom--compute-margins window))) (set-window-buffer window (current-buffer)) (set-window-margins window (round (* darkroom--margin-factor (car margins))) (round (* darkroom--margin-factor (cdr margins)))))
  darkroom--set-margins()
  (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins))
  (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins)) (internal--after-with-selected-window save-selected-window--state))
  (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins)) (internal--after-with-selected-window save-selected-window--state)))
  (let ((save-selected-window--state (internal--before-with-selected-window w))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins)) (internal--after-with-selected-window save-selected-window--state))))
  (closure ((just-margins) t) (w) (let ((save-selected-window--state (internal--before-with-selected-window w))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins)) (internal--after-with-selected-window save-selected-window--state)))))(#<window 3 on *slide*>)
  mapc((closure ((just-margins) t) (w) (let ((save-selected-window--state (internal--before-with-selected-window w))) (save-current-buffer (unwind-protect (progn (select-window (car save-selected-window--state) (quote norecord)) (darkroom--set-margins)) (internal--after-with-selected-window save-selected-window--state))))) (#<window 3 on *slide*>))
  darkroom--enter(nil)
  (cond ((= (count-windows) 1) (darkroom--enter darkroom--saved-state)) (darkroom--saved-state (darkroom--leave)) (t))
  darkroom--enter-or-leave()
  (cond (darkroom-tentative-mode (add-hook (quote window-configuration-change-hook) (quote darkroom--enter-or-leave) (quote append) (quote local)) (darkroom--enter-or-leave)) (t (darkroom--leave)))
  (let ((last-message (current-message))) (setq darkroom-tentative-mode (if (eq arg (quote toggle)) (not darkroom-tentative-mode) (> (prefix-numeric-value arg) 0))) (remove-hook (quote window-configuration-change-hook) (quote darkroom--enter-or-leave) (quote local)) (if darkroom-mode (progn (display-warning (quote darkroom) (concat "Turning off `darkroom-mode' first. " "It doesn't go with `darkroom-tentative-mode'.") (let ((darkroom-tentative-mode nil)) (darkroom-mode -1))))) (cond (darkroom-tentative-mode (add-hook (quote window-configuration-change-hook) (quote darkroom--enter-or-leave) (quote append) (quote local)) (darkroom--enter-or-leave)) (t (darkroom--leave))) (run-hooks (quote darkroom-tentative-mode-hook) (if darkroom-tentative-mode (quote darkroom-tentative-mode-on-hook) (quote darkroom-tentative-mode-off-hook))) (if (called-interactively-p (quote any)) (progn nil (if (and (current-message) (not (equal last-message (current-message)))) nil (message "DarkRoom-Tentative mode %sabled" (if darkroom-tentative-mode "en" "dis"))))))
  darkroom-tentative-mode()
  (lambda nil (org-present-big) (org-display-inline-images) (org-present-hide-cursor) (org-present-read-only) (define-key org-present-mode-keymap [down] (quote org-present-next)) (define-key org-present-mode-keymap [up] (quote org-present-prev)) (define-key org-present-mode-keymap (kbd "q") (quote org-present-quit)) (global-set-key (kbd "C-c p") (quote slide-return-to-present)) (define-key org-present-mode-keymap (kbd "s") (quote slide-split-to-past)) (setq current-buffer (buffer-name)) (rename-buffer "*slide*") (darkroom-tentative-mode))()
  run-hooks(org-present-mode-hook)
  org-present()
  call-interactively(org-present nil nil)
  command-execute(org-present)

Finally, also after stopping the slide show it is also not possible to exit emacs, C-x-c only results in this in Messages:

(No files need saving)
cons: Arithmetic error
(No files need saving)
cons: Arithmetic error
(No files need saving)
cons: Arithmetic error
(No files need saving)
cons: Arithmetic error
(No files need saving)
cons: Arithmetic error

It needs to be killed from the outside.

best, Tom

TLINDEN avatar Apr 02 '16 13:04 TLINDEN