Say I want to add a hook to an in-built function, for example dired-find-file.
So I declare and add my hook as follow:
(defvar my/dired-find-file-hook nil)
(add-hook 'my/dired-find-file-hook 'my-find-file-function)
I now need to run (run-hooks 'my/dired-find-file-hook) at the end of dired-find-file, what is the best way to do this?
What I have been doing is just declaring the entire function again, as per the following, but this feels like a messy way to achieve this.
(defun dired-find-file ()
"In Dired, visit the file or directory named on this line."
(interactive)
;; Bind `find-file-run-dired' so that the command works on directories
;; too, independent of the user's setting.
(let ((find-file-run-dired t)
;; This binding prevents problems with preserving point in
;; windows displaying Dired buffers, because reverting a Dired
;; buffer empties it, which changes the places where the
;; markers used by switch-to-buffer-preserve-window-point
;; point.
(switch-to-buffer-preserve-window-point
(if dired-auto-revert-buffer
nil
switch-to-buffer-preserve-window-point)))
(find-file (dired-get-file-for-visit)))
(run-hooks 'my/dired-find-file-hook))
Is there a better way I should achieve this?