(dired.info)Dired Hooks

Prev: Dired Configuration Up: Dired Customization

Dired Hooks

Hook variables can contain functions that are run at certain times in

     Run after loading Dired.  You can customize key bindings or load
     extensions with this.  For example:

          (setq dired-load-hook
                 (lambda ()
                  ;; Load extras:
                  (load "dired-x")
                  ;; How to define your own key bindings:
                  (define-key dired-mode-map " " 'scroll-up)
                  (define-key dired-mode-map "b" 'scroll-down))))

     Run at the very end of `dired-mode', after most buffer local
     variables have been initialized (e.g., `default-directory' and
     `dired-directory'), but before the directory listing has been read

     Do buffer local things here, for example:

          (setq dired-mode-hook
                 (lambda ()
                   (dired-extra-startup)	 ;; dired-extra support
                   ;; How to set (local) variables in each new Dired buffer:
                   (setq case-fold-search t)
                   (setq truncate-lines t))))

     Since the listing has not yet been inserted you could still change
     `dired-actual-switches'.  For example, if you use `ange-ftp.el',
     you might want to replace the `-A' with the `-a' switch, depending
     on whether `default-directory' corresponds to a System V hosts
     that does not understand all BSD `ls' switches.  The
     `dired.README' file gives an example.  If you set
     `dired-actual-switches' remember that you may also have to set
     `dired-sort-mode' to the appropriate string so that the modeline
     looks right.

     Do not set `dired-mode-hook' inside your `dired-load-hook', simply
     set it somewhere in your `~/.emacs' (before Dired is loaded, if
     you explicitly load Dired).  This is so that extensions packages
     loaded via the load hook can add things to the `dired-mode-hook' at
     the front or at the end, as they see fit.

     In case you set `truncate-lines' to `t' as in the above example,
     here is a function to toggle the value of `truncate-lines', in
     Dired and other buffers:
          (defun set-truncate-lines ()
            "Toggle value of truncate-lines and refresh window display."
            (setq truncate-lines (not truncate-lines))
            ;; now refresh window display (an idiom from simple.el):
              (set-window-start (selected-window)
                                (window-start (selected-window)))))
     You could bind it to `C-x 4 $':
          (define-key ctl-x-4-map "$" 'set-truncate-lines)
     It is sometimes useful to toggle `truncate-lines' in Dired buffers
     to make long filenames completely visible and get the listing
     properly aligned again.

     This hook is run before a dired buffer is newly read in (created
     or reverted).

     After each listing of a file or directory, this hook is run with
     the buffer narrowed to the listing.

     The `dired-subdir-alist' has already been updated so that the usual
     Dired functions like `dired-get-filename' work.  It is possible to
     modify the buffer with this hook.  The package `dired-x.el' does
     this to implement omitting certain uninteresting files from a Dired
     buffer.  Under X11, highlighting of certain files is also possible
     (see package `dired-x11.el').

automatically generated by info2www