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))

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?

  • 1
    (1) Are you aware that you are trying to use the old advise system? (2) Sanity check: did you call ad-activate with appropriate arguments? (otherwise advise won't have any effect).
    – wvxvw
    Jan 17 '17 at 15:10
  • @wvxvw i'm not and did not, hard to find articles on the advices, look further, thank you
    – 4lex1v
    Jan 17 '17 at 15:12
  • This is the new advise system: gnu.org/software/emacs/manual/html_node/elisp/…
    – wvxvw
    Jan 17 '17 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.