Berikut adalah empat (4) contoh display-buffer
kelompok fungsi kustom yang dapat disesuaikan sesuai kebutuhan khusus pengguna - di atas ; di bawah ; kiri ; kanan - dan di sini ada empat (4) interactive
fungsi untuk menampilkan file atau direktori dari baris dired-mode
buffer saat ini. Hanya ada tiga kondisi: (a) jika sudah ada jendela yang menampilkan buffer target, lalu pilih; (B) jika ada jendela ke arah yang diinginkan yang tersedia, maka gunakan; (C) catch-all adalah untuk membuat jendela baru ke arah yang diinginkan jika kondisi lain tidak terpenuhi.
Pemakaian:
M-x dired-display-above
M-x dired-display-below
M-x dired-display-left
M-x dired-display-right
Ada begitu banyak ikatan kunci yang sudah ada di dalamnya dired-mode
dan dired+
, sehingga saya tidak berani mencoba membuat milik saya sendiri. Pengguna bebas memilih pintasan keyboardnya sendiri, yang berada di luar cakupan contoh terbatas ini.
Pengguna bebas untuk menambahkan kondisi tambahan ke display-buffer
keluarga contoh fungsi untuk menangani lebih banyak situasi - misalnya, lebih banyak jendela daripada hanya beberapa.
(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)))
EDIT: Ini adalah implementasi yang sedikit lebih canggih / menyenangkan dari konsep di atas, yang memberi pengguna kemampuan untuk menggunakan ini secara non-interaktif atau interaktif ; misalnya, M-x dired-display-buffer
- di mana pengguna akan diminta untuk memilih direktori jika tidak mengarahkan file dired-mode
, dan untuk memilih arah tampilan (kiri, kanan, atas, di bawah, di bawah).
(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
untuk merujuk ke kuadran buffer di dalam yang samaframe
. Aframe
dianggap sebagai keseluruhan kucing-kaboodle, yang dapat memiliki banyak jendela di dalamnya. Emacs dapat menghasilkan banyak bingkai, dengan setiap bingkai berisi banyak jendela.