1

diredで使うoと「別ウィンドウ」でファイルを開きます。ただし、他のウィンドウが複数表示されている場合は、ランダムに選択されているように見えます。そのファイルを開くウィンドウを選択する方法はありますか?

4

2 に答える 2

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)
  1. バッファを評価します。
  2. で窓を選ぶle::dired-choose-window-action
  3. odired から押して、選択したウィンドウでファイルを開きます。
于 2013-03-17T16:51:05.943 に答える