Aquí hay cuatro (4) ejemplos de display-buffer
familias de funciones personalizadas que se pueden personalizar para satisfacer las necesidades particulares de un usuario, arriba ; abajo ; la izquierda ; derecha - y aquí hay cuatro (4) interactive
funciones para mostrar el archivo o directorio de la línea actual de un dired-mode
búfer. Solo hay tres condiciones: (a) si ya hay una ventana que muestra el búfer de destino, elíjalo; (b) si hay una ventana en la dirección deseada que está disponible, úsela; (c) el objetivo general es crear una nueva ventana en la dirección deseada si no se cumplen las otras condiciones.
Uso:
M-x dired-display-above
M-x dired-display-below
M-x dired-display-left
M-x dired-display-right
Hay tantas combinaciones de teclas ya integradas dired-mode
y dired+
, que no me atrevo a inventar las mías. El usuario es libre de elegir sus propios atajos de teclado, lo que está más allá del alcance de este ejemplo limitado.
El usuario es libre de agregar condiciones adicionales a la display-buffer
familia de funciones de muestra para manejar más situaciones, por ejemplo, más ventanas que solo un par.
(defun my-display-buffer-below (buffer alist)
"Doc-string."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'below))
(t
(split-window (selected-window) nil 'below)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
(defun my-display-buffer-above (buffer alist)
"Doc-string."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'above))
(t
(split-window (selected-window) nil 'above)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
(defun my-display-buffer-left (buffer alist)
"Doc-string."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'left))
(t
(split-window (selected-window) nil 'left)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
(defun my-display-buffer-right (buffer alist)
"Doc-string."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'right))
(t
(split-window (selected-window) nil 'right)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
(defun dired-display-above ()
"Doc-string."
(interactive)
(let* (
(file-or-dir (dired-get-file-for-visit))
(buffer (find-file-noselect file-or-dir)))
(my-display-buffer-above buffer nil)))
(defun dired-display-below ()
"Doc-string."
(interactive)
(let* (
(file-or-dir (dired-get-file-for-visit))
(buffer (find-file-noselect file-or-dir)))
(my-display-buffer-below buffer nil)))
(defun dired-display-left ()
"Doc-string."
(interactive)
(let* (
(file-or-dir (dired-get-file-for-visit))
(buffer (find-file-noselect file-or-dir)))
(my-display-buffer-left buffer nil)))
(defun dired-display-right ()
"Doc-string."
(interactive)
(let* (
(file-or-dir (dired-get-file-for-visit))
(buffer (find-file-noselect file-or-dir)))
(my-display-buffer-right buffer nil)))
EDITAR: Aquí hay una implementación un poco más sofisticada / divertida del concepto anterior, que le da al usuario la capacidad de usar esto de manera no interactiva o interactiva ; por ejemplo, M-x dired-display-buffer
- donde se le pedirá al usuario que elija un directorio si no se encuentra sobre un archivo dired-mode
y que elija una dirección de visualización (izquierda, derecha, arriba, abajo).
(defun my-display-buffer (buffer-or-name alist direction &optional size pixelwise)
"BUFFER: The buffer that will be displayed.
ALIST: See the doc-string of `display-buffer' for more information.
DIRECTION: Must use one of these symbols: 'left 'right 'below 'above
SIZE: See the doc-string for `split-window'.
PIXELWISE: See the doc-string for `split-window'.
There are three possibilities:
- (1) If a window on the frame already displays the target buffer,
then just reuse the same window.
- (2) If there is already a window in the specified direction in relation
to the selected window, then display the target buffer in said window.
- (3) If there is no window in the specified direction, then create one
in that direction and display the target buffer in said window."
(let* ((buffer
(if (bufferp buffer-or-name)
buffer-or-name
(get-buffer buffer-or-name)))
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction direction))
(t
(split-window (selected-window) size direction pixelwise)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
window))
(defun dired-display-buffer (&optional direction alist)
"Display a dired-mode buffer or a file underneath point in a dired-mode buffer."
(interactive)
(let* ((file-or-dir (or (and (eq major-mode 'dired-mode) (dired-get-file-for-visit))
(read-directory-name "Directory: ")))
(buffer (find-file-noselect file-or-dir))
(direction
(if direction
direction
(let ((char (read-char-exclusive (concat
"["
(propertize "l" 'face '(:foreground "red"))
"]"
(propertize "eft" 'face '(:foreground "blue"))
" | ["
(propertize "r" 'face '(:foreground "red"))
"]"
(propertize "ight" 'face '(:foreground "blue"))
" | ["
(propertize "a" 'face '(:foreground "red"))
"]"
(propertize "bove" 'face '(:foreground "blue"))
" | ["
(propertize "b" 'face '(:foreground "red"))
"]"
(propertize "elow" 'face '(:foreground "blue"))))))
(cond
((eq char ?l)
'left)
((eq char ?r)
'right)
((eq char ?a)
'above)
((eq char ?b)
'below)
;;; FIXME: @lawlist may add a loop similar to `org-capture'
;;; whereby a new `read-char-exclusive' will be initiated if
;;; a user did not initially choose a valid option (l/r/a/b).
(t
(let ((debug-on-quit nil)
(msg (concat "dired-display-buffer: "
"You did not select l/r/a/b "
"-- exiting.")))
(signal 'quit `(,msg)))))))))
(my-display-buffer buffer alist direction)))
window
para referirnos a un cuadrante de búfer dentro del mismoframe
. Seframe
considera que A es todo el gatito-kaboodle, que puede tener muchas ventanas dentro. Emacs puede generar múltiples cuadros, cada cuadro contiene múltiples ventanas.