ema2159 / centaur-tabs

Emacs plugin aiming to become an aesthetic, modern looking tabs plugin
GNU General Public License v3.0
757 stars 51 forks source link

(wrong-type-argument number-or-marker-p nil) after `C-x 5 f ~/.emacs` #221

Closed erikmd closed 3 months ago

erikmd commented 1 year ago

Dear @ema2159, I recently spotted a subtle bug that I wasn't able to fix myself. See the details below. I use GNU Emacs 27.1 on Debian 11.

Steps to reproduce

# Steps to use the .emacs init of our teaching unit (called "tapfa")
mv ~/.emacs ~/.emacs.bak
curl -fL -o ~/.emacs https://github.com/erikmd/tapfa-init.el/raw/master/.emacs
emacs &  # Note that this will automatically install modes thanks to (use-package)
# Click on the dialog buttons "Light" (for example), "OK", "Non", "Emacs/shell", "OK"
# Close emacs after the installation

emacs &
# Type "C-x 5 f ~/.emacs RET"
# Notice that the tabs bar DOES NOT SHOW UP in the new frame

# Type "C-h e"
# Notice the message
# "Error during redisplay: (eval (centaur-tabs-line)) signaled (wrong-type-argument number-or-marker-p nil)"

# Type "M-: (centaur-tabs-line) RET"
# Notice the Backtrace buffer:
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  centaur-tabs-line-format(Elisp)
  centaur-tabs-line()
  eval((centaur-tabs-line) t)
  eval-expression((centaur-tabs-line) nil nil 127)
  funcall-interactively(eval-expression (centaur-tabs-line) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)
erikmd commented 1 year ago

Hi @ema2159 ! would you have a clue of how to fix this bug?

FWIW, the centaur-tabs-line-format code is as follows:

(defun centaur-tabs-line-format (tabset)
  "Return the `centaur-tabs-display-line-format' value to display TABSET."
  (let* ((sel (centaur-tabs-selected-tab tabset))
     (tabs (centaur-tabs-view tabset))
     (padcolor centaur-tabs-background-color)
     (all-tabs (centaur-tabs-tabs tabset))
     (total-tabs (length all-tabs))
         (sel-index (+ (cl-position (car sel) (cl-mapcar 'car all-tabs)) 1))
     atsel elts)
    ;; Track the selected tab to ensure it is always visible.
    (when centaur-tabs--track-selected
      (while (not (memq sel tabs))
    (centaur-tabs-scroll tabset -1)
    (setq tabs (centaur-tabs-view tabset)))
      (while (and tabs (not atsel))
    (setq elts  (cons (centaur-tabs-line-tab (car tabs)) elts)
          atsel (eq (car tabs) sel)
          tabs  (cdr tabs)))
      (setq elts (nreverse elts))
      ;; At this point the selected tab is the last elt in ELTS.
      ;; Scroll TABSET and ELTS until the selected tab becomes
      ;; visible.
      (let (buffer-list-update-hook)
    (with-temp-buffer
      (let ((truncate-partial-width-windows nil)
        (inhibit-modification-hooks t)
        deactivate-mark ;; Prevent deactivation of the mark!
        start)
        (setq truncate-lines nil
          buffer-undo-list t)
        (setq start (point))
        (while (and (cdr elts) ;; Always show the selected tab!
            (progn
              (delete-region start (point-max))
              (goto-char (point-max))
              (apply #'insert elts)
              (goto-char (point-min))
              (> (vertical-motion 1) 0)))
          (centaur-tabs-scroll tabset 1)
          (setq elts (cdr elts))))))
      (setq elts (nreverse elts))
      (setq centaur-tabs--track-selected nil))
    ;; Format remaining tabs.
    (while tabs
      (setq elts (cons (centaur-tabs-line-tab (car tabs)) elts)
        tabs (cdr tabs)))
    ;; Cache and return the new tab bar.
    (centaur-tabs-set-template
     tabset
     (list
      (centaur-tabs-count sel-index total-tabs)
      (centaur-tabs-line-format--buttons)
      (nreverse elts)
      (propertize "% "
                  'face (list :background padcolor)
                  'pointer 'arrow)
      (centaur-tabs-line-format--new-button)))
    ))

and the (1st) error comes from the evaluation of (+ (cl-position (car sel) (cl-mapcar 'car all-tabs)) 1) given sel = nil

erikmd commented 1 year ago

Hi @ema2159 ! - just a friendly ping ^^

erikmd commented 3 months ago

FYI I can't reproduce the issue anymore (@jcs090218 I believe you fixed it along the way) so closing the issue now, thanks!