0

Emacs 27.1

package: consult ver.0.32

Here my init.el

(use-package consult
  :config (message "consult - I'm always here after the package is loaded")
  (add-hook 'dired-mode-hook (lambda () (recentf-add-file default-directory)))
  (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
 )

(use-package consult-dir
  :ensure t
  :bind (("C-x C-d" . consult-dir)
     ("C-x C-j" . consult-dir-dired)
         :map minibuffer-local-completion-map
         ("C-x C-d" . consult-dir)
     ("C-x C-j" . consult-dir-dired)))

(use-package consult-project-extra
  :ensure t
  :bind
  (("C-c p f" . consult-project-extra-find)
   ("C-c p o" . consult-project-extra-find-other-window)))

enter image description here

M-x consult-recent-file

enter image description here

Why also show recent directories. I need to show only recent files!

If I remove

  (add-hook 'dired-mode-hook (lambda () (recentf-add-file default-directory)))

than it work fine.

But I need this config, because recent directories not working correctly:

  M-x consult-dir
  Press "r" 

1 Answer 1

0

I think the recentf (wrapped by consult-recent-file) behavior is correct since you are adding directory (where recentf-add-file expects file) in order to change the behavior of consult-dir as you wish. Then, how about just erasing the directory and put it back using something like "recentf-remove-file", the opposite of recentf-add-file when you finish using consult-dir(or before using consult-recent-file)? I found recentf-remove-if-non-kept that is close to that purpose. Here is the modified one can be used for that just by removing condition (the original lines are commented out) and you can find a suitable hook to add (recentf-remove default-directory):

;; (defsubst recentf-remove-if-non-kept (filename)
(defun recentf-remove (filename)
  "Remove FILENAME from the recent list"
  ;; , if file is not kept.Return non-nil if FILENAME has been removed."
  ;; (unless (recentf-keep-p filename)
  (let ((m (recentf-string-member
            (recentf-expand-file-name filename) recentf-list)))
    (and m (setq recentf-list (delq (car m) recentf-list)))))
;; )
2
  • When try to execute this function I get error: Debugger entered--Lisp error: (scan-error "Unbalanced parentheses" 546 1) Apr 10, 2023 at 18:21
  • Since the number of opening parentheses and closing one of the above snippet are the same and balanced (There are 11 of each, right?), I can't imagine what is happening on your end. As a minimum test, what happens when you enter C-x C-e (to call eval-last-sexp) at the end of the snippet? Then likewise enter C-x C-e at each end of (recentf-add-file default-directory) and (recentf-remove default-directory), where does it go wrong?
    – roomworoof
    Apr 11, 2023 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.