Use generic get and set methods
This commit is contained in:
100
eyebrowse.el
100
eyebrowse.el
@ -158,30 +158,55 @@ If t, switching to the same window config as
|
|||||||
|
|
||||||
;; --- internal functions ----------------------------------------------------
|
;; --- internal functions ----------------------------------------------------
|
||||||
|
|
||||||
|
(defun eyebrowse-get (type &optional frame)
|
||||||
|
"Retrieve frame-specific value of TYPE.
|
||||||
|
If FRAME is nil, use current frame. TYPE can be any of
|
||||||
|
'window-configs, 'current-slot, 'last-slot."
|
||||||
|
(cond
|
||||||
|
((eq type 'window-configs)
|
||||||
|
(frame-parameter frame 'eyebrowse-window-configs))
|
||||||
|
((eq type 'current-slot)
|
||||||
|
(frame-parameter frame 'eyebrowse-current-slot))
|
||||||
|
((eq type 'last-slot)
|
||||||
|
(frame-parameter frame 'eyebrowse-last-slot))))
|
||||||
|
|
||||||
|
(defun eyebrowse-set (type value &optional frame)
|
||||||
|
"Set frame-specific value of TYPE to VALUE.
|
||||||
|
If FRAME is nil, use current frame. TYPE can be any of
|
||||||
|
'window-configs, 'current-slot, 'last-slot."
|
||||||
|
(cond
|
||||||
|
((eq type 'window-configs)
|
||||||
|
(set-frame-parameter frame 'eyebrowse-window-configs value))
|
||||||
|
((eq type 'current-slot)
|
||||||
|
(set-frame-parameter frame 'eyebrowse-current-slot value))
|
||||||
|
((eq type 'last-slot)
|
||||||
|
(set-frame-parameter frame 'eyebrowse-last-slot value))))
|
||||||
|
(put 'eyebrowse-set 'lisp-indent-function 1)
|
||||||
|
|
||||||
(defun eyebrowse-insert-in-window-config-list (element)
|
(defun eyebrowse-insert-in-window-config-list (element)
|
||||||
"Insert ELEMENT in the list of window configs.
|
"Insert ELEMENT in the list of window configs.
|
||||||
This function keeps the sortedness intact."
|
This function keeps the sortedness intact."
|
||||||
(setq eyebrowse-window-configs
|
(eyebrowse-set 'window-configs
|
||||||
(--sort (< (car it) (car other))
|
(--sort (< (car it) (car other))
|
||||||
(cons element eyebrowse-window-configs))))
|
(cons element (eyebrowse-get 'window-configs)))))
|
||||||
|
|
||||||
(defun eyebrowse-update-window-config-element (old-element new-element)
|
(defun eyebrowse-update-window-config-element (old-element new-element)
|
||||||
"Replace OLD-ELEMENT with NEW-ELEMENT in the window config list."
|
"Replace OLD-ELEMENT with NEW-ELEMENT in the window config list."
|
||||||
(setq eyebrowse-window-configs
|
(eyebrowse-set 'window-configs
|
||||||
(-replace-at (-elem-index old-element eyebrowse-window-configs)
|
(-replace-at (-elem-index old-element (eyebrowse-get 'window-configs))
|
||||||
new-element eyebrowse-window-configs)))
|
new-element (eyebrowse-get 'window-configs))))
|
||||||
|
|
||||||
(defun eyebrowse-save-window-config (slot)
|
(defun eyebrowse-save-window-config (slot)
|
||||||
"Save the current window config to SLOT."
|
"Save the current window config to SLOT."
|
||||||
(let* ((element (list slot (current-window-configuration) (point)))
|
(let* ((element (list slot (current-window-configuration) (point)))
|
||||||
(match (assq slot eyebrowse-window-configs)))
|
(match (assq slot (eyebrowse-get 'window-configs))))
|
||||||
(if match
|
(if match
|
||||||
(eyebrowse-update-window-config-element match element)
|
(eyebrowse-update-window-config-element match element)
|
||||||
(eyebrowse-insert-in-window-config-list element))))
|
(eyebrowse-insert-in-window-config-list element))))
|
||||||
|
|
||||||
(defun eyebrowse-load-window-config (slot)
|
(defun eyebrowse-load-window-config (slot)
|
||||||
"Restore the window config from SLOT."
|
"Restore the window config from SLOT."
|
||||||
(let ((match (assq slot eyebrowse-window-configs)))
|
(let ((match (assq slot (eyebrowse-get 'window-configs))))
|
||||||
(when match
|
(when match
|
||||||
(let ((window-config (cadr match))
|
(let ((window-config (cadr match))
|
||||||
(point (nth 2 match)))
|
(point (nth 2 match)))
|
||||||
@ -190,9 +215,9 @@ This function keeps the sortedness intact."
|
|||||||
|
|
||||||
(defun eyebrowse-delete-window-config (slot)
|
(defun eyebrowse-delete-window-config (slot)
|
||||||
"Remove the window config at SLOT."
|
"Remove the window config at SLOT."
|
||||||
(setq eyebrowse-window-configs
|
(eyebrowse-set 'window-configs
|
||||||
(remove (assq slot eyebrowse-window-configs)
|
(remove (assq slot (eyebrowse-get 'window-configs))
|
||||||
eyebrowse-window-configs)))
|
(eyebrowse-get 'window-configs))))
|
||||||
|
|
||||||
(defun eyebrowse-switch-to-window-config (slot)
|
(defun eyebrowse-switch-to-window-config (slot)
|
||||||
"Switch to the window config SLOT.
|
"Switch to the window config SLOT.
|
||||||
@ -202,17 +227,17 @@ This will save the current window config to
|
|||||||
`eyebrowse-current-slot' equals SLOT, this will switch to the
|
`eyebrowse-current-slot' equals SLOT, this will switch to the
|
||||||
last window config."
|
last window config."
|
||||||
(when (and eyebrowse-switch-back-and-forth-p
|
(when (and eyebrowse-switch-back-and-forth-p
|
||||||
(= eyebrowse-current-slot slot))
|
(= (eyebrowse-get 'current-slot) slot))
|
||||||
(setq slot eyebrowse-last-slot
|
(setq slot (eyebrowse-get 'last-slot))
|
||||||
eyebrowse-last-slot eyebrowse-current-slot))
|
(eyebrowse-set 'last-slot (eyebrowse-get 'current-slot)))
|
||||||
(when (/= eyebrowse-current-slot slot)
|
(when (/= (eyebrowse-get 'current-slot) slot)
|
||||||
(run-hooks 'eyebrowse-pre-window-switch-hook)
|
(run-hooks 'eyebrowse-pre-window-switch-hook)
|
||||||
(eyebrowse-save-window-config eyebrowse-current-slot)
|
(eyebrowse-save-window-config (eyebrowse-get 'current-slot))
|
||||||
(eyebrowse-load-window-config slot)
|
(eyebrowse-load-window-config slot)
|
||||||
(setq eyebrowse-last-slot eyebrowse-current-slot)
|
(eyebrowse-set 'last-slot (eyebrowse-get 'current-slot))
|
||||||
(setq eyebrowse-current-slot slot)
|
(eyebrowse-set 'current-slot slot)
|
||||||
(eyebrowse-save-window-config eyebrowse-current-slot)
|
(eyebrowse-save-window-config (eyebrowse-get 'current-slot))
|
||||||
(eyebrowse-load-window-config eyebrowse-current-slot)
|
(eyebrowse-load-window-config (eyebrowse-get 'current-slot))
|
||||||
(run-hooks 'eyebrowse-post-window-switch-hook)))
|
(run-hooks 'eyebrowse-post-window-switch-hook)))
|
||||||
|
|
||||||
(defun eyebrowse-update-mode-line ()
|
(defun eyebrowse-update-mode-line ()
|
||||||
@ -223,16 +248,16 @@ last window config."
|
|||||||
'face 'eyebrowse-mode-line-delimiters))
|
'face 'eyebrowse-mode-line-delimiters))
|
||||||
(separator (propertize eyebrowse-mode-line-separator
|
(separator (propertize eyebrowse-mode-line-separator
|
||||||
'face 'eyebrowse-mode-line-separator))
|
'face 'eyebrowse-mode-line-separator))
|
||||||
(current-slot (number-to-string eyebrowse-current-slot))
|
(current-slot (number-to-string (eyebrowse-get 'current-slot)))
|
||||||
(active-item (propertize current-slot
|
(active-item (propertize current-slot
|
||||||
'face 'eyebrowse-mode-line-active))
|
'face 'eyebrowse-mode-line-active))
|
||||||
(window-config-slots (mapcar (lambda (item)
|
(window-config-slots (mapcar (lambda (item)
|
||||||
(number-to-string (car item)))
|
(number-to-string (car item)))
|
||||||
eyebrowse-window-configs)))
|
(eyebrowse-get 'window-configs))))
|
||||||
(if (and (not (eq eyebrowse-mode-line-style 'hide))
|
(if (and (not (eq eyebrowse-mode-line-style 'hide))
|
||||||
(or (eq eyebrowse-mode-line-style 'always)
|
(or (eq eyebrowse-mode-line-style 'always)
|
||||||
(and (eq eyebrowse-mode-line-style 'smart)
|
(and (eq eyebrowse-mode-line-style 'smart)
|
||||||
(> (length eyebrowse-window-configs) 1))))
|
(> (length (eyebrowse-get 'window-configs)) 1))))
|
||||||
(s-concat left-delimiter
|
(s-concat left-delimiter
|
||||||
(s-join separator
|
(s-join separator
|
||||||
(-replace-at (-elem-index current-slot
|
(-replace-at (-elem-index current-slot
|
||||||
@ -249,17 +274,18 @@ If `eyebrowse-wrap-around-p' is t, this will switch from the last
|
|||||||
to the first one. When used with a numerical argument, switch to
|
to the first one. When used with a numerical argument, switch to
|
||||||
window config COUNT."
|
window config COUNT."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs))
|
(let* ((match (assq (eyebrowse-get 'current-slot)
|
||||||
(index (-elem-index match eyebrowse-window-configs)))
|
(eyebrowse-get 'window-configs)))
|
||||||
|
(index (-elem-index match (eyebrowse-get 'window-configs))))
|
||||||
(if count
|
(if count
|
||||||
(eyebrowse-switch-to-window-config count)
|
(eyebrowse-switch-to-window-config count)
|
||||||
(when index
|
(when index
|
||||||
(if (< (1+ index) (length eyebrowse-window-configs))
|
(if (< (1+ index) (length (eyebrowse-get 'window-configs)))
|
||||||
(eyebrowse-switch-to-window-config
|
(eyebrowse-switch-to-window-config
|
||||||
(car (nth (1+ index) eyebrowse-window-configs)))
|
(car (nth (1+ index) (eyebrowse-get 'window-configs))))
|
||||||
(when eyebrowse-wrap-around-p
|
(when eyebrowse-wrap-around-p
|
||||||
(eyebrowse-switch-to-window-config
|
(eyebrowse-switch-to-window-config
|
||||||
(caar eyebrowse-window-configs))))))))
|
(caar (eyebrowse-get 'window-configs)))))))))
|
||||||
|
|
||||||
(defun eyebrowse-prev-window-config (count)
|
(defun eyebrowse-prev-window-config (count)
|
||||||
"Switch to the previous available window config.
|
"Switch to the previous available window config.
|
||||||
@ -267,8 +293,9 @@ If `eyebrowse-wrap-around-p' is t, this will switch from the
|
|||||||
first to the last one. When used with a numerical argument,
|
first to the last one. When used with a numerical argument,
|
||||||
switch COUNT window configs backwards and always wrap around."
|
switch COUNT window configs backwards and always wrap around."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs))
|
(let* ((match (assq (eyebrowse-get 'current-slot)
|
||||||
(index (-elem-index match eyebrowse-window-configs)))
|
(eyebrowse-get 'window-configs)))
|
||||||
|
(index (-elem-index match (eyebrowse-get 'window-configs))))
|
||||||
(if count
|
(if count
|
||||||
(let ((eyebrowse-wrap-around-p t))
|
(let ((eyebrowse-wrap-around-p t))
|
||||||
(eyebrowse-prev-window-config
|
(eyebrowse-prev-window-config
|
||||||
@ -277,27 +304,28 @@ switch COUNT window configs backwards and always wrap around."
|
|||||||
(when index
|
(when index
|
||||||
(if (> index 0)
|
(if (> index 0)
|
||||||
(eyebrowse-switch-to-window-config
|
(eyebrowse-switch-to-window-config
|
||||||
(car (nth (1- index) eyebrowse-window-configs)))
|
(car (nth (1- index) (eyebrowse-get 'window-configs))))
|
||||||
(when eyebrowse-wrap-around-p
|
(when eyebrowse-wrap-around-p
|
||||||
(eyebrowse-switch-to-window-config
|
(eyebrowse-switch-to-window-config
|
||||||
(caar (last eyebrowse-window-configs)))))))))
|
(caar (last (eyebrowse-get 'window-configs))))))))))
|
||||||
|
|
||||||
(defun eyebrowse-last-window-config ()
|
(defun eyebrowse-last-window-config ()
|
||||||
"Switch to the last window config."
|
"Switch to the last window config."
|
||||||
(interactive)
|
(interactive)
|
||||||
(eyebrowse-switch-to-window-config eyebrowse-last-slot))
|
(eyebrowse-switch-to-window-config (eyebrowse-get 'last-slot)))
|
||||||
|
|
||||||
(defun eyebrowse-close-window-config ()
|
(defun eyebrowse-close-window-config ()
|
||||||
"Close the current window config.
|
"Close the current window config.
|
||||||
This removes it from `eyebrowse-window-configs' and switches to
|
This removes it from `eyebrowse-window-configs' and switches to
|
||||||
another appropriate window config."
|
another appropriate window config."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (> (length eyebrowse-window-configs) 1)
|
(when (> (length (eyebrowse-get 'window-configs)) 1)
|
||||||
(if (equal (assq eyebrowse-current-slot eyebrowse-window-configs)
|
(if (equal (assq (eyebrowse-get 'current-slot)
|
||||||
(car (last eyebrowse-window-configs)))
|
(eyebrowse-get 'window-configs))
|
||||||
|
(car (last (eyebrowse-get 'window-configs))))
|
||||||
(eyebrowse-prev-window-config nil)
|
(eyebrowse-prev-window-config nil)
|
||||||
(eyebrowse-next-window-config nil))
|
(eyebrowse-next-window-config nil))
|
||||||
(eyebrowse-delete-window-config eyebrowse-last-slot)))
|
(eyebrowse-delete-window-config (eyebrowse-get 'last-slot))))
|
||||||
|
|
||||||
(defun eyebrowse-switch-to-window-config-0 ()
|
(defun eyebrowse-switch-to-window-config-0 ()
|
||||||
"Switch to window configuration 0."
|
"Switch to window configuration 0."
|
||||||
|
|||||||
Reference in New Issue
Block a user