;;; 特に Java のプロジェクトとかで
;;; i の dired-maybe-insert-subdir だと
;;; サブディレクトリが1つしかないディレクトリを
;;; たくさん展開する事になって見難いので
;;; そういうのを飛して、中身があるディレクトリだけ展開する機能
(defun my/most-shallow-directory-with-contents (dir)
(catch 'return
(while t
(let ((fs (remove-if (lambda (f) (string-match "/\\.\\.?$" f))
(directory-files dir t))))
(cond ((not fs) (throw 'return nil))
((and (= 1 (length fs))
(file-directory-p (car fs))) (setq dir (car fs)))
(t (throw 'return dir)))))))
(defun my/dired-insert-subdir (dirname &optional force-child-p)
(interactive
(list (dired-get-filename) current-prefix-arg))
(let ((dirname (if force-child-p
dirname
(my/most-shallow-directory-with-contents dirname))))
(if dirname
(dired-insert-subdir dirname)
(message "Directory to open was not found."))))
(define-key dired-mode-map (kbd "i") 'my/dired-insert-subdir)