 
 (global-set-key (kbd "C-x C-r") #'kotct/ido-recentf-open)
 
-;; custom recentf additions that can handle directories
+;; 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))
+
+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) "/")))
 

;;; C-x C-r: find recent files and directories using recentf

;; require is okay because recentf will be autoloaded at the end of this
;; file anyway if we don't require it now, and we need some of its definitions
(require 'recentf)
(require 'cl)

;; only keep last 200 recent files
(setf recentf-max-saved-items 200)

;; save every five minutes
(run-at-time t (* 5 60) #'recentf-save-list)

;; recentf completion using ido
(defun kotct/ido-recentf-open ()
  "Use `ido-completing-read' to \\[find-file] a recent file"
  (interactive)
  (let ((recent-alist (kotct/recentf-show-basenames-modified-directories (recentf-menu-elements recentf-max-saved-items))))
    (if (find-file (assoc-default
                    (ido-completing-read "Find recent file: " (mapcar #'car recent-alist))
                    recent-alist))

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

;; Finally, enable `recentf-mode'
(recentf-mode 1)

(provide 'recentf-c)
