Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erikmd opened this issue Aug 26, 2023 · 2 comments
Open

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

erikmd opened this issue Aug 26, 2023 · 2 comments

Comments

@erikmd
Copy link
Contributor

erikmd commented Aug 26, 2023

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
Copy link
Contributor Author

erikmd commented Sep 21, 2023

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
Copy link
Contributor Author

erikmd commented Nov 17, 2023

Hi @ema2159 ! - just a friendly ping ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant