Skip to content

Commit

Permalink
prevent frame-multiplexer commands from being taken in terminal-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Jul 21, 2024
1 parent 1a715ed commit b7f25a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion extensions/terminal/terminal-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
terminal-resize
terminal-copy-mode-on
lem-core::<mouse-motion-event>
lem-core::<mouse-event>))
lem-core::<mouse-event>
lem/frame-multiplexer:frame-multiplexer-advice))

(define-major-mode terminal-mode ()
(:name "Terminal"
Expand Down
32 changes: 23 additions & 9 deletions src/ext/frame-multiplexer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:lem/button
:lem/common/ring)
(:export :*keymap*
:frame-multiplexer-advice
:frame-multiplexer-next
:frame-multiplexer-prev
:frame-multiplexer-switch
Expand Down Expand Up @@ -311,11 +312,15 @@
*virtual-frame-map*)
(clrhash *virtual-frame-map*)))

(define-command toggle-frame-multiplexer () ()
(defclass frame-multiplexer-advice () ())

(define-command (toggle-frame-multiplexer (:advice-classes frame-multiplexer-advice)) () ()
(setf (variable-value 'frame-multiplexer :global)
(not (variable-value 'frame-multiplexer :global))))

(define-command frame-multiplexer-normalize-ids () ()
(define-command (frame-multiplexer-normalize-ids (:advice-classes frame-multiplexer-advice))
()
()
"Normalize the IDs of all the frames.
Assigns a smaller ID to a frame, if there is a smaller unused ID.
This does not change the order of the frames."
Expand All @@ -334,7 +339,10 @@ This does not change the order of the frames."
(setf (aref (virtual-frame-id/frame-table vf) index) nil)
(setq free-index (next-free (1+ free-index)))))))

(define-command frame-multiplexer-create-with-new-buffer-list () ()
(define-command (frame-multiplexer-create-with-new-buffer-list
(:advice-classes frame-multiplexer-advice))
()
()
(check-frame-multiplexer-usable)
(let* ((vf (gethash (implementation) *virtual-frame-map*))
(id (find-unused-frame-id vf)))
Expand All @@ -344,7 +352,8 @@ This does not change the order of the frames."
(allocate-frame vf frame)
(switch-current-frame vf frame))))

(define-command frame-multiplexer-delete (&optional id) (:universal-nil)
(define-command (frame-multiplexer-delete (:advice-classes frame-multiplexer-advice))
(&optional id) (:universal-nil)
"Delete the current frame.
With prefix argument ID, delete the frame with the given ID."
(check-frame-multiplexer-usable)
Expand All @@ -361,7 +370,8 @@ With prefix argument ID, delete the frame with the given ID."
(switch-current-frame vf (search-previous-frame vf frame-now)))
(free-frame vf frame-now))))

(define-command frame-multiplexer-prev (&optional (n 1)) (:universal)
(define-command (frame-multiplexer-prev (:advice-classes frame-multiplexer-advice))
(&optional (n 1)) (:universal)
"Switch to the Nth previous frame.
The prefix argument N defaults to 1."
(check-frame-multiplexer-usable)
Expand All @@ -373,7 +383,8 @@ The prefix argument N defaults to 1."
(when frame
(switch-current-frame vf frame))))

(define-command frame-multiplexer-next (&optional (n 1)) (:universal)
(define-command (frame-multiplexer-next (:advice-classes frame-multiplexer-advice))
(&optional (n 1)) (:universal)
"Switch to the Nth next frame.
The prefix argument N defaults to 1."
(check-frame-multiplexer-usable)
Expand All @@ -385,7 +396,8 @@ The prefix argument N defaults to 1."
(when frame
(switch-current-frame vf frame))))

(define-command frame-multiplexer-switch (&optional (id 1)) (:universal)
(define-command (frame-multiplexer-switch (:advice-classes frame-multiplexer-advice))
(&optional (id 1)) (:universal)
"Switch to the frame with ID.
The prefix argument ID defaults to 1."
;; TODO: It would be great to enhance this by showing a prompt
Expand All @@ -397,7 +409,8 @@ The prefix argument ID defaults to 1."
(switch-current-frame vf (frame-table-entry-frame entry))
(editor-error "No frame with ID ~a" id))))

(define-command frame-multiplexer-recent (&optional (n 1)) (:universal)
(define-command (frame-multiplexer-recent (:advice-classes frame-multiplexer-advice))
(&optional (n 1)) (:universal)
"Switch to the Nth most recent frame selected.
The prefix argument N defaults to 1."
(check-frame-multiplexer-usable)
Expand All @@ -418,7 +431,8 @@ The prefix argument N defaults to 1."
(let ((entry (aref (virtual-frame-id/frame-table vf) recent-frame-id)))
(switch-current-frame vf (frame-table-entry-frame entry)))))))

(define-command frame-mulitplexer-rename (name &optional id) ((:string "New name: ") :universal-nil)
(define-command (frame-mulitplexer-rename (:advice-classes frame-multiplexer-advice))
(name &optional id) ((:string "New name: ") :universal-nil)
"Rename the current frame to NAME.
With prefix argument ID, rename the frame with the given ID."
(check-frame-multiplexer-usable)
Expand Down

0 comments on commit b7f25a4

Please sign in to comment.