 (add-to-list 'recentf-used-hooks '(dired-mode-hook  kotct/recentf-track-opened-directory))
 (add-to-list 'recentf-used-hooks '(kill-buffer-hook kotct/recentf-track-closed-directory))
 
-;; enable recentf-mode
+;; Finally, enable `recentf-mode'
 (recentf-mode 1)
 
 (provide 'recentf-c)

  ;; as a whole to run in linear time
  (let* ((file-name-directory-translators '())
         (translators-cons nil)
         (list-for-recentf (mapcar (lambda (item)
                                     (let ((translated nil))
                                       (prog1
                                           (if (kotct/file-directory-nonremote-p (cdr item))
                                               (progn
                                                 (setf translated (cdr item))
                                                 (cons (car item) (directory-file-name (cdr item))))
                                             item)
                                         (if translators-cons
                                             (setf (cdr translators-cons) (list translated)
                                                   translators-cons (cdr translators-cons))
                                           (setf file-name-directory-translators (list translated)
                                                 translators-cons file-name-directory-translators)))))
                                   l))
         (list-with-basenames (recentf-show-basenames list-for-recentf no-dir)))
    (mapcar (lambda (item)
              (if (equal item '("" . "/"))


(global-set-key (kbd "C-x C-r") #'kotct/ido-recentf-open)

;; Handle directories (incl. remotes) for recentf.
(defun kotct/file-directory-nonremote-p (filename)
  "Return t if FILENAME names an existing directory.

Remote directories are assumed to exist unless there is already
an open connection that we can use to verify existence."
  (if (or (not (file-remote-p filename))
          (file-remote-p filename nil t))
      (file-directory-p filename)
    (string= (substring filename -1) "/")))

