DiredLineCommands

I don’t like that `dired-(next|previous)-line’ moves to “not useful” lines in DiredMode, like the empty ones between inserted subdirectores, so I came up with this simple defun that suit my needs better.

 (defun dired-next-file-line ()
   "Moves to the next dired line that have a file or directory name on
 it"
   (interactive)
   (call-interactively 'dired-next-line)
   (if (not (or (dired-move-to-filename) (eobp)))
       (dired-next-file-line)))
 
 (defun dired-previous-file-line ()
   "Moves to the previous dired line that have a file or directory name
 on it"
   (interactive)
   (call-interactively 'dired-previous-line)
   (if (not (or (dired-move-to-filename) (bobp)))
       (dired-previous-file-line)))

I changed the place of the last line in each function. This works for me.


I use this one (Joseph):

  (defadvice dired-next-line (around dired-next-line+ activate)
  "Replace current buffer if file is a directory."
        ad-do-it
        (while (and  (not  (eobp)) (not ad-return-value))
          (forward-line)
          (setq ad-return-value(dired-move-to-filename))
          )
        (when (eobp)
            (forward-line -1)
            (setq ad-return-value(dired-move-to-filename))
            )
  )
  (defadvice dired-previous-line (around dired-previous-line+ activate)
  "Replace current buffer if file is a directory."
        ad-do-it
        (while (and  (not  (bobp)) (not ad-return-value))
          (forward-line -1)
          (setq ad-return-value(dired-move-to-filename))
          )
        (when (bobp)
          (call-interactively 'dired-next-line)
            )
  )

See also DiredTweaks.


CategoryDirectories