Compare commits
22 Commits
a68ac22b64
...
main
Author | SHA1 | Date | |
---|---|---|---|
8c396a11f5 | |||
e8b16420f8 | |||
7a75e73f88 | |||
3e37e3ad0c | |||
57a18de9aa | |||
23721d0a55 | |||
7514139d18 | |||
5ff002372b | |||
6de0e152eb | |||
68818946a6 | |||
30da3d7c08 | |||
aba0e70aec | |||
63c390d76b | |||
05fe647254 | |||
31037cf599 | |||
ab090d02ee | |||
dbde4c1ee3 | |||
86f6ef3abc | |||
31636a8ccf | |||
5c89fb4fd6 | |||
a3722fbb12 | |||
a0b669e25b |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.elc
|
||||||
|
*.eld
|
28
README.org
28
README.org
@ -43,6 +43,26 @@ this utility:
|
|||||||
|
|
||||||
* How?
|
* How?
|
||||||
|
|
||||||
|
** Installation
|
||||||
|
|
||||||
|
You can install pip-frame.el from [[https://melpa.org/#/pip-frame][MELPA]]. If you use [[https://github.com/radian-software/straight.el][straight.el]] and
|
||||||
|
prefer using source repos directly, you can install pip-frame.el as
|
||||||
|
follows:
|
||||||
|
|
||||||
|
#+begin_src elisp
|
||||||
|
(straight-use-package
|
||||||
|
'(pip-frame :type git
|
||||||
|
:repo "https://git.zamazal.org/pdm/pip-frame"
|
||||||
|
:local-repo "pip-frame"))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
For manual installation, simply put [[./pip-frame.el][pip-frame.el]] file to your
|
||||||
|
=site-lisp= directory and add the following to your Emacs configuration:
|
||||||
|
|
||||||
|
#+begin_src elisp
|
||||||
|
(require ’pip-frame)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** Commands
|
** Commands
|
||||||
|
|
||||||
The PIP frame is created using =M-x pip-frame-add-buffer= command. You
|
The PIP frame is created using =M-x pip-frame-add-buffer= command. You
|
||||||
@ -96,6 +116,10 @@ Some customization examples:
|
|||||||
(internal-border-width . 20))))
|
(internal-border-width . 20))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
-----
|
* Contact
|
||||||
|
|
||||||
/To Petr./
|
pip-frame.el is available at [[https://git.zamazal.org/pdm/pip-frame][git.zamazal.org]]. You can file issues
|
||||||
|
there.
|
||||||
|
|
||||||
|
If you don’t want to discuss things publicly or to bother registering
|
||||||
|
at yet another web site, you can reach me at [[mailto:pdm@zamazal.org][pdm@zamazal.org]].
|
||||||
|
143
pip-frame.el
143
pip-frame.el
@ -1,7 +1,13 @@
|
|||||||
;;; pip-frame.el --- PIP frame support -*- lexical-binding: t -*-
|
;;; pip-frame.el --- Display and manage a PIP frame -*- lexical-binding: t -*-
|
||||||
|
|
||||||
;; Copyright (C) 2022 Milan Zamazal <pdm@zamazal.org>
|
;; Copyright (C) 2022 Milan Zamazal <pdm@zamazal.org>
|
||||||
|
|
||||||
|
;; Author: Milan Zamazal <pdm@zamazal.org>
|
||||||
|
;; Version: 1
|
||||||
|
;; Package-Requires: ((emacs "25.1"))
|
||||||
|
;; Keywords: frames
|
||||||
|
;; URL: https://git.zamazal.org/pdm/pip-frame
|
||||||
|
|
||||||
;; COPYRIGHT NOTICE
|
;; COPYRIGHT NOTICE
|
||||||
;;
|
;;
|
||||||
;; This program is free software: you can redistribute it and/or modify
|
;; This program is free software: you can redistribute it and/or modify
|
||||||
@ -17,6 +23,8 @@
|
|||||||
;; You should have received a copy of the GNU General Public License
|
;; You should have received a copy of the GNU General Public License
|
||||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
;; Display a floating Emacs frame with selected buffers.
|
;; Display a floating Emacs frame with selected buffers.
|
||||||
;; Similar to PIP on screens. Probably most useful in EXWM.
|
;; Similar to PIP on screens. Probably most useful in EXWM.
|
||||||
;;
|
;;
|
||||||
@ -25,10 +33,13 @@
|
|||||||
;; `M-x pip-frame-remove-buffer' or close the whole frame with
|
;; `M-x pip-frame-remove-buffer' or close the whole frame with
|
||||||
;; `M-x pip-frame-delete-frame'.
|
;; `M-x pip-frame-delete-frame'.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
|
|
||||||
(defgroup pip-frame ()
|
(defgroup pip-frame ()
|
||||||
"Display PIP frame.")
|
"Display PIP frame."
|
||||||
|
:group 'frames)
|
||||||
|
|
||||||
(defcustom pip-frame-scale 4
|
(defcustom pip-frame-scale 4
|
||||||
"How many times to shrink the PIP frame relative to the display size."
|
"How many times to shrink the PIP frame relative to the display size."
|
||||||
@ -49,7 +60,9 @@ Usually, the value should be larger than 0 and much smaller than 1."
|
|||||||
|
|
||||||
(defcustom pip-frame-parameters
|
(defcustom pip-frame-parameters
|
||||||
'((left . 0.9)
|
'((left . 0.9)
|
||||||
(top . 0.9))
|
(top . 0.9)
|
||||||
|
(tab-bar-lines . 0)
|
||||||
|
(minibuffer . nil))
|
||||||
"Alist of frame parameters to use for the PIP frame.
|
"Alist of frame parameters to use for the PIP frame.
|
||||||
The frame size is determined automatically using `pip-frame-scale'
|
The frame size is determined automatically using `pip-frame-scale'
|
||||||
custom option but it can be overriden here."
|
custom option but it can be overriden here."
|
||||||
@ -61,16 +74,21 @@ custom option but it can be overriden here."
|
|||||||
:type '(alist :key-type symbol :value-type sexp)
|
:type '(alist :key-type symbol :value-type sexp)
|
||||||
:group 'pip-frame)
|
:group 'pip-frame)
|
||||||
|
|
||||||
|
(defcustom pip-frame-temporary-buffer-seconds 10
|
||||||
|
"Number of seconds to keep a buffer displayed temporarily by default."
|
||||||
|
:type 'number
|
||||||
|
:group 'pip-frame)
|
||||||
|
|
||||||
(defvar pip-frame--name "PIP-frame")
|
(defvar pip-frame--name "PIP-frame")
|
||||||
|
|
||||||
(defun pip-frame--get-frame (&optional no-error)
|
(defun pip-frame--get-frame (&optional no-error)
|
||||||
(let ((frame (cl-find pip-frame--name (frame-list)
|
(let ((frame (cl-find pip-frame--name (frame-list)
|
||||||
:key #'(lambda (f) (frame-parameter f 'name)))))
|
:key (lambda (f) (frame-parameter f 'name)))))
|
||||||
(or frame
|
(or frame
|
||||||
(unless no-error
|
(unless no-error
|
||||||
(error "No PIP frame")))))
|
(error "No PIP frame")))))
|
||||||
|
|
||||||
(defun pip-frame--make-frame ()
|
(defun pip-frame--make-frame (buffer)
|
||||||
(let ((frame (make-frame `((name . ,pip-frame--name)
|
(let ((frame (make-frame `((name . ,pip-frame--name)
|
||||||
(unsplittable . t)
|
(unsplittable . t)
|
||||||
,@pip-frame-parameters
|
,@pip-frame-parameters
|
||||||
@ -79,54 +97,93 @@ custom option but it can be overriden here."
|
|||||||
(frame-inhibit-implied-resize t)
|
(frame-inhibit-implied-resize t)
|
||||||
(face-height (round (/ (face-attribute 'default :height) pip-frame-font-scale))))
|
(face-height (round (/ (face-attribute 'default :height) pip-frame-font-scale))))
|
||||||
(set-face-attribute 'default frame :height face-height)
|
(set-face-attribute 'default frame :height face-height)
|
||||||
(mapc #'(lambda (p) (set-face-attribute 'default frame (car p) (cdr p)))
|
(dolist (p pip-frame-face-attributes)
|
||||||
pip-frame-face-attributes)
|
(set-face-attribute 'default frame (car p) (cdr p)))
|
||||||
|
(set-window-buffer (car (window-list frame)) buffer)
|
||||||
frame))
|
frame))
|
||||||
|
|
||||||
(defun pip-frame-delete-frame ()
|
(defun pip-frame-delete-frame ()
|
||||||
""
|
"Delete the PIP frame."
|
||||||
(interactive)
|
(interactive)
|
||||||
(delete-frame (pip-frame--get-frame)))
|
(delete-frame (pip-frame--get-frame)))
|
||||||
|
|
||||||
(defun pip-frame--buffers ()
|
(defun pip-frame--buffers ()
|
||||||
(mapcar #'window-buffer (window-list (pip-frame--get-frame))))
|
(mapcar #'window-buffer (window-list (pip-frame--get-frame))))
|
||||||
|
|
||||||
(defun pip-frame--add-additional-buffer ()
|
(defun pip-frame--add-additional-buffer (buffer temporary)
|
||||||
(let* ((windows (window-list (pip-frame--get-frame)))
|
(let ((windows (window-list (pip-frame--get-frame))))
|
||||||
(sizes (mapcar #'(lambda (w)
|
(unless (and temporary
|
||||||
(let ((width (window-body-width w t))
|
(cl-find buffer windows :key #'window-buffer :test #'eq))
|
||||||
(height (window-body-height w t)))
|
(let* ((sizes (mapcar (lambda (w)
|
||||||
(cons (+ (* width width) (* height height))
|
(let ((width (window-body-width w t))
|
||||||
w)))
|
(height (window-body-height w t)))
|
||||||
windows))
|
(cons (+ (* width width) (* height height))
|
||||||
(largest (cdr (cl-first (cl-sort sizes #'> :key #'car))))
|
w)))
|
||||||
(side (if (> (window-body-width largest t) (* 2 (window-body-height largest t)))
|
windows))
|
||||||
'right
|
(largest (cdr (cl-first (cl-sort sizes #'> :key #'car))))
|
||||||
'below))
|
(side (if (> (window-body-width largest t)
|
||||||
(new-window (split-window largest nil side)))
|
(* 2 (window-body-height largest t)))
|
||||||
(set-window-buffer new-window (current-buffer))))
|
'right
|
||||||
|
'below))
|
||||||
|
(new-window (split-window largest nil side)))
|
||||||
|
(set-window-buffer new-window buffer)))))
|
||||||
|
|
||||||
|
(defvar pip-frame--buffer-timers '())
|
||||||
|
|
||||||
|
(defun pip-frame--make-buffer-temporary (buffer seconds)
|
||||||
|
(when (eq seconds t)
|
||||||
|
(setq seconds pip-frame-temporary-buffer-seconds))
|
||||||
|
(let ((timer (run-with-timer seconds nil #'pip-frame-remove-buffer buffer)))
|
||||||
|
(setq pip-frame--buffer-timers (cons (cons buffer timer)
|
||||||
|
pip-frame--buffer-timers))))
|
||||||
|
|
||||||
|
(defun pip-frame--delete-buffer-timer (buffer)
|
||||||
|
(let ((timer (alist-get buffer pip-frame--buffer-timers)))
|
||||||
|
(when timer
|
||||||
|
(cancel-timer timer)
|
||||||
|
(setq pip-frame--buffer-timers
|
||||||
|
(assq-delete-all buffer pip-frame--buffer-timers)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun pip-frame-add-buffer ()
|
(defun pip-frame-add-buffer (&optional buffer-or-name temporary)
|
||||||
""
|
"Add a buffer to the PIP frame.
|
||||||
|
If there is no PIP frame then create one.
|
||||||
|
If BUFFER-OR-NAME is specified, add the given buffer to the frame,
|
||||||
|
otherwise add the current buffer.
|
||||||
|
If TEMPORARY is given, display the buffer in the PIP frame for that
|
||||||
|
many seconds and then remove it from the frame. If t, display it for
|
||||||
|
`pip-frame-temporary-buffer-seconds'.
|
||||||
|
A buffer can be added and displayed multiple times in the frame. If
|
||||||
|
TEMPORARY is non-nil, the buffer is not displayed again if it is
|
||||||
|
already present."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((frame (or (pip-frame--get-frame t))))
|
(let ((frame (pip-frame--get-frame t))
|
||||||
|
(buffer (get-buffer (or buffer-or-name (current-buffer)))))
|
||||||
(if frame
|
(if frame
|
||||||
(pip-frame--add-additional-buffer)
|
(progn
|
||||||
(pip-frame--make-frame))))
|
(when temporary
|
||||||
|
(pip-frame--delete-buffer-timer buffer))
|
||||||
|
(pip-frame--add-additional-buffer buffer temporary))
|
||||||
|
(pip-frame--make-frame buffer))
|
||||||
|
(when temporary
|
||||||
|
(pip-frame--make-buffer-temporary buffer temporary))))
|
||||||
|
|
||||||
(defun pip-frame-remove-buffer (buffer-name)
|
(defun pip-frame-remove-buffer (buffer-or-name)
|
||||||
""
|
"Remove buffer named BUFFER-OR-NAME from the PIP frame.
|
||||||
|
If it is the last buffer in the PIP frame, delete the frame.
|
||||||
|
If the buffer is not present in the PIP frame, do nothing."
|
||||||
(interactive (list (completing-read "Remove PIP buffer: "
|
(interactive (list (completing-read "Remove PIP buffer: "
|
||||||
(mapcar #'buffer-name (pip-frame--buffers))
|
(mapcar #'buffer-name (pip-frame--buffers))
|
||||||
nil t)))
|
nil t)))
|
||||||
(let* ((windows (window-list (pip-frame--get-frame)))
|
(if-let ((frame (pip-frame--get-frame t))
|
||||||
(windows-to-delete (cl-remove buffer-name windows
|
(windows (window-list frame))
|
||||||
:key #'(lambda (w) (buffer-name (window-buffer w)))
|
(buffer (get-buffer buffer-or-name))
|
||||||
:test-not #'string=)))
|
(windows-to-delete (cl-remove buffer windows
|
||||||
(if (= (length windows-to-delete) (length windows))
|
:key #'window-buffer
|
||||||
(pip-frame-delete-frame)
|
:test-not #'eq)))
|
||||||
(mapc #'delete-window windows-to-delete))))
|
(if (= (length windows-to-delete) (length windows))
|
||||||
|
(pip-frame-delete-frame)
|
||||||
|
(seq-do #'delete-window windows-to-delete))))
|
||||||
|
|
||||||
(defun pip-frame--move (x y)
|
(defun pip-frame--move (x y)
|
||||||
(let ((frame (pip-frame--get-frame)))
|
(let ((frame (pip-frame--get-frame)))
|
||||||
@ -140,18 +197,22 @@ custom option but it can be overriden here."
|
|||||||
(round (* pip-frame-move-step (nth (if vertical 3 2) workarea))))))
|
(round (* pip-frame-move-step (nth (if vertical 3 2) workarea))))))
|
||||||
|
|
||||||
(defun pip-frame-move-left ()
|
(defun pip-frame-move-left ()
|
||||||
|
"Move the PIP frame left."
|
||||||
(interactive)
|
(interactive)
|
||||||
(pip-frame--move (- (pip-frame--move-step nil)) 0))
|
(pip-frame--move (- (pip-frame--move-step nil)) 0))
|
||||||
|
|
||||||
(defun pip-frame-move-right ()
|
(defun pip-frame-move-right ()
|
||||||
|
"Move the PIP frame right."
|
||||||
(interactive)
|
(interactive)
|
||||||
(pip-frame--move (pip-frame--move-step nil) 0))
|
(pip-frame--move (pip-frame--move-step nil) 0))
|
||||||
|
|
||||||
(defun pip-frame-move-up ()
|
(defun pip-frame-move-up ()
|
||||||
|
"Move the PIP frame up."
|
||||||
(interactive)
|
(interactive)
|
||||||
(pip-frame--move 0 (- (pip-frame--move-step t))))
|
(pip-frame--move 0 (- (pip-frame--move-step t))))
|
||||||
|
|
||||||
(defun pip-frame-move-down ()
|
(defun pip-frame-move-down ()
|
||||||
|
"Move the PIP frame down."
|
||||||
(interactive)
|
(interactive)
|
||||||
(pip-frame--move 0 (pip-frame--move-step t)))
|
(pip-frame--move 0 (pip-frame--move-step t)))
|
||||||
|
|
||||||
@ -164,9 +225,17 @@ custom option but it can be overriden here."
|
|||||||
map))
|
map))
|
||||||
|
|
||||||
(defun pip-frame-move ()
|
(defun pip-frame-move ()
|
||||||
""
|
"Move PIP frame interactively.
|
||||||
|
Use arrow keys to move the frame around.
|
||||||
|
Any other key stops this command and executes its own command."
|
||||||
(interactive)
|
(interactive)
|
||||||
(message "Use arrow keys to move the frame, any other key to quit")
|
(message "Use arrow keys to move the frame, any other key to quit")
|
||||||
(set-transient-map pip-frame-move-map t))
|
(set-transient-map pip-frame-move-map t))
|
||||||
|
|
||||||
(provide 'pip-frame)
|
(provide 'pip-frame)
|
||||||
|
|
||||||
|
;; Local Variables:
|
||||||
|
;; checkdoc-force-docstrings-flag: nil
|
||||||
|
;; End:
|
||||||
|
|
||||||
|
;;; pip-frame.el ends here
|
||||||
|
BIN
screenshot.jpg
BIN
screenshot.jpg
Binary file not shown.
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 50 KiB |
Reference in New Issue
Block a user