-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab-bar-session.el
148 lines (122 loc) · 5.29 KB
/
tab-bar-session.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
;;; tab-bar-session.el --- Save session of tab-bar -*- lexical-binding: t; -*-
;; Copyright (C) 2019 OGAWA Hirofumi
;; Author: OGAWA Hirofumi <[email protected]>
;; Keywords: convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'desktop)
(require 'tab-bar)
(defgroup tbsession nil
"Save status of Emacs when you exit."
:group 'frames)
(defcustom tbsession-default-file-name
(convert-standard-filename "tbsession-configs.el")
"File used to save and load window configurations."
:type 'file)
(defcustom tbsession-default-dirname user-emacs-directory
"The directory in which the desktop file should be saved."
:type 'directory)
(defcustom tbsession-line-style 'smart
"Mode line style for tab-bar-session.
Possible values are:
`smart' - hide when only one tab, otherwise use index.
`index' - use index of tab-bar.
nil - hide always"
:type '(choice (const :tag "Smart" smart)
(const :tag "Index" index)
(const :tag "Hide" nil)))
(defface tbsession-line-delimiters
'((t nil))
"Face for the mode line indicator delimiters.")
(defface tbsession-line-inactive
'((t nil))
"Face for the inactive items of the mode line indicator.")
(defface tbsession-line-active
'((t (:inherit mode-line-emphasis)))
"Face for the active items of the mode line indicator.")
(defcustom tbsession-line-left-delimiter "["
"Left delimiter of the mode line indicator."
:type 'string)
(defcustom tbsession-line-right-delimiter "]"
"Right delimiter of the mode line indicator."
:type 'string)
(defun tbsession-filter-alist ()
"Return `frameset-filter-alist' only for tabs."
(let ((frameset-filter-alist (copy-tree frameset-filter-alist))
(save-alist '(tabs)))
(mapc
(lambda (element)
(let* ((param (car element))
(action (if (memq param save-alist)
(cdr (assq param frameset-filter-alist))
:never)))
(push (cons param action) frameset-filter-alist)))
(frame-parameters))
frameset-filter-alist))
;;;###autoload
(defun tbsession-save (dirname)
"Save tab-bar session to `tbsession-default-dirname'.
With prefix argument \\[universal-argument], prompt for DIRNAME."
(interactive (list
(let ((default tbsession-default-dirname))
(if current-prefix-arg
(read-directory-name "Directory to save Session file in: "
default default t)
default))))
(let ((desktop-base-file-name tbsession-default-file-name)
;; Minimize variables to save desktop file
(frameset-filter-alist (tbsession-filter-alist))
(desktop-globals-to-save '())
(desktop-locals-to-save '()))
(desktop-save dirname)
(message "Saved config to \"%s\""
(expand-file-name desktop-base-file-name dirname))))
;;;###autoload
(defun tbsession-load (&optional dirname)
"Load tab-bar session from `tbsession-default-dirname'.
With prefix argument \\[universal-argument], prompt for DIRNAME."
(interactive (list
(let ((default tbsession-default-dirname))
(if current-prefix-arg
(read-directory-name "Directory to load Session file in: "
default default t)
default))))
(let ((desktop-base-file-name tbsession-default-file-name))
(desktop-read dirname)
(message "Loaded config from \"%s\""
(expand-file-name desktop-base-file-name dirname))))
;;; mode-line
(defun tbsession-mode-line-indicator ()
"Return a string representation of the window configurations."
(let ((hide (and (eq tbsession-line-style 'smart)
(<= (length (tab-bar-tabs)) 1))))
(unless hide
(let ((left-delimiter (propertize tbsession-line-left-delimiter
'face 'tbsession-line-delimiters))
(right-delimiter (propertize tbsession-line-right-delimiter
'face 'tbsession-line-delimiters))
(current-index (tab-bar--current-tab-index)))
(concat left-delimiter
(propertize (number-to-string (1+ current-index))
'face 'tbsession-line-active)
right-delimiter)))))
;;;###autoload
(defun tbsession-move-mode-line ()
"Move mode line indicator to first."
(let ((elt (assoc 'tbsession-line-style mode-line-misc-info)))
(setq mode-line-misc-info (delete elt mode-line-misc-info))
(push '(tbsession-line-style (:eval (tbsession-mode-line-indicator)))
mode-line-misc-info)))
(provide 'tab-bar-session)
;;; tab-bar-session.el ends here