当我们o在 dired 中使用时,它会在“其他窗口”中打开一个文件。但是,如果有多个其他窗口可见,那么它似乎是随机选择的。有没有办法选择应该在哪个窗口中打开该文件?
问问题
1035 次
2 回答
2
我也对 dired 的这种行为感到恼火。我喜欢ace-window让您只需一个按键即可轻松选择窗口的方式,因此 a 编写了一个函数,让我可以使用它在我选择的窗口中打开文件:
(require 'ace-window)
(defun find-file-ace-window ()
"Use ace window to select a window for opening a file from dired."
(interactive)
(let ((file (dired-get-file-for-visit)))
(if (> (length (aw-window-list)) 1)
(aw-select "" (lambda (window)
(aw-switch-to-window window)
(find-file file)))
(find-file-other-window file))))
替换dired标准find-file-other-window
命令添加
(define-key dired-mode-map "o" 'find-file-ace-window)
于 2017-12-03T23:04:59.563 回答
0
我怀疑这种行为是随机的,但您可以通过挂钩display-buffer
和绑定您自己的命令来更改它。
请注意,大部分代码是按区域对窗口列表进行排序。
(defvar le::dired-chosen-window nil
"current chosen window to show buffers for `le::dired-choose-window-action'")
(defun le::window-list-for-completion ()
"Return alist of (BUFFER-NAME . WINDOW) sorted by size,
suitable for completion."
;; Schwartzian transform
(mapcar
(lambda (cell)
(let ((window (car cell)))
(cons (concat
(when (and (boundp 'window-numbering-mode)
window-numbering-mode)
(format "%s: "
(window-numbering-get-number-string window)))
(buffer-name (window-buffer window)))
window)))
(sort (loop with boost-alist = (if (eq major-mode 'dired-mode)
(list (cons (selected-window) -1000000))
nil)
for window in (window-list nil 0 (window-at 0 0))
for index from 0
collect (cons window (+
(* (window-total-width window)
(window-total-height window)
100)
index
(let ((boost (assq window boost-alist)))
(if boost
(cdr boost)
0)))))
(lambda (a b)
(> (cdr a) (cdr b))))))
(defun le::dired-choose-window (window)
"Choose window to display buffer in.
Reset selection with universal prefix (C-u)."
(interactive (let ((completions (le::window-list-for-completion)))
(list (unless current-prefix-arg
(cdr (assoc (completing-read "window holding buffer: " completions) completions))))))
(setq le::dired-chosen-window window))
(defun le::dired-choose-window-action (buffer alist)
"action to display buffer in `le::dired-chosen-window'"
(window--display-buffer buffer le::dired-chosen-window 'reuse))
(defun le::dired-find-file-specified-window ()
"Dired command to display buffer in chosen window"
(interactive)
(let ((display-buffer-overriding-action '((le::dired-choose-window-action))))
(dired-find-file-other-window)))
(define-key dired-mode-map [remap dired-find-file-other-window] 'le::dired-find-file-specified-window)
- 评估缓冲区。
- 选择窗口
le::dired-choose-window-action
- 从 dired按下o以在所选窗口中打开文件。
于 2013-03-17T16:51:05.943 回答