1

I'm loading dired+ from a file ( as it has been removed from Melpa ), but it won't load when I try to make it conditional of opening a dired buffer.

;; ---- Dired + --------
;; Loads Dired+ 

(use-package dired+
  :load-path "~/.emacs.d/elpa-offline/dired+"   

  :after dired
  
  :config
  (require 'dired+)
  (print "Dired + package Loaded")
)

Also I tried making it depending of using a binding key but it doesn't load that way either:

;; ---- Dired + --------
;; Loads Dired+ Manually

(use-package dired+
  :load-path "~/.emacs.d/elpa-offline/dired+"   

  :bind ( "C-x d" . dired)
  
  :config
  (require 'dired+)
  (print "Dired + package Loaded")
)

The (print "Dired + package Loaded") is just so I can check if is properly loading on the message buffer.

3
  • Is the question only how to do it with use-package? If not, just use dired-load-hook. (Presumably you don't want to reload Dired+ each time you open a Dired buffer or reread a Dired listing.)
    – Drew
    Aug 8, 2021 at 18:40
  • I'm trying to make the Emacs loading time shorter, and Dired+ takes almost two seconds of the six or seven seconds that takes Emacs to be ready for typing. The idea was to avoid loading Dired+ until I open a dired buffer with ("C-x d").
    – Fabman
    Aug 8, 2021 at 20:46
  • I just tried using dired-load-hook but it doesn't make a difference because Emacs seems to load dired when starts.
    – Fabman
    Aug 8, 2021 at 20:47

1 Answer 1

4

Use one of the hooks (dired-before-readin-hook or dired-mode-hook) that's used each time Dired is used, but have your hook function do just (require 'dired+), so it does nothing once Dired+ has been loaded.

I would probably put it on dired-before-readin-hook. Use M-x customize-variable and add this hook function:

(defun my-require-dired+ ()
  "Require Dired+."
  (require 'dired+))

(add-hook 'dired-before-readin-hook 'my-require-dired+)
1
  • Awesome!. It works perfectly. It even works with tramp when I open a remote folder.
    – Fabman
    Aug 9, 2021 at 11:43

Your Answer

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

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