Skip to content

Store customized tab order on desktop sessions #256

@cortsf

Description

@cortsf

Hello all, and thanks for making centaur-tabs. I'd like to know if there is any supported or simple way of storing customized (check bottom note) tab orders in desktop sessions. Many years ago I came with a hacky solution which is probably wrong on many levels (I didn't had too much time to fully understand all the centaur-tabs source code, nor to become an elisp expert) but it did work 100% of the times for many years, until emacs 30.

 (add-hook 'desktop-save-hook 'centaur-fran-save-tabsets)

(defun desktop-load-fran () (interactive)
       (let* ((_load (call-interactively 'desktop+-load)))
	 (run-at-time "0.1 sec" nil 'centaur-fran-load-tabsets)
	 )
       )
       
(defun centaur-fran-save-tabsets () (interactive)
       (setq centaur-tabs-serialized-tabsets '())
       (mapcar (lambda (tabset-name)
		 (let* (
			(bufset (centaur-tabs-get-tabset tabset-name))
			(tabset (centaur-tabs-tabs bufset))
			(group-name (format "%s" bufset))
			(buffer-list (mapcar 'buffer-name (mapcar 'car tabset)))
			)
		   (push (cons group-name buffer-list) centaur-tabs-serialized-tabsets)
		   )
		 )
	       (seq-filter (lambda (x) (if (or (eq x "Emacs") (eq x 0)) nil t)) centaur-tabs-tabsets) ;; "Emacs" causes empty tablines sometines. Do not remove without heavy testing. 
	       )
       )


(defun centaur-fran-load-tabsets () (interactive)
       (mapcar (lambda (serialized-tabset)
		 (let* (
			(bufset (centaur-tabs-get-tabset (car serialized-tabset)))
			(current-group-tabs (centaur-tabs-tabs bufset))
			(stringtail (cdr serialized-tabset))
			(new-group-tabs '())
			)
		   (mapcar (lambda (x) 
			     (if (get-buffer x)
				 (push (car (seq-filter (lambda (y) (if (string= x (buffer-name (car y))) t nil)) current-group-tabs) ) new-group-tabs)
			     )
			     ) 
			   stringtail) 
		   (set bufset (reverse new-group-tabs))
		   (centaur-tabs-set-template bufset nil)
		   (centaur-tabs-display-update)
		   )
		 )
	       centaur-tabs-serialized-tabsets
	       )
       )

Now everything (saving/loading sessions) fails with this error:

Wrong type argument: stringp, #<obarray n=3>

To be honest I don't remember exactly what the heck this code is doing and don't know why it fails 😄 so I'm looking for any other not so hacky solution if possible. Otherwise I hope this ugly hack inspires anybody looking for such functionality (share it!).

Note: Storing the tab order is useful when altering the default order with (centaur-tabs-move-current-tab-to-left) and (centaur-tabs-move-current-tab-to-right) (I always do it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions