One of Github's features i like is that it "flattens" path if a folder contains only one subfolder, i.e you have a src
folder which has only main
folder, so by clicking on src
you go to the content of main
. I'm using ranger for navigation and want to achieve the same behaviour. I've decided to try advices for the first time, but can't get it working:
(defadvice ranger-find-file (before flatten-subfolder (entity ignore-history))
(interactive "DInitialDirectory: ")
(message "Calling ADVICE")
(let ((folder (or entity (dired-get-filename nil t))))
(when (and folder (file-directory-p folder))
(let* ((subfolder (f-directories folder))
(nr-of-subfolders (length subfolder)))
(if (eq nr-of-subfolders 1)
(flatten-subfolder (car subfolder))
entity)))))
My understanding was that when i call ranger-find-file, which has the following signature:
(defun ranger-find-file (&optional entry ignore-history) ...)
would first invoke my advice (flatten-subfolder
) which would flatten (go down the path) folders and invoke ranger-find-file
with the result of the advice above. Obviously it doesn't work, is there any way to do this?