unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to run code after a dired buffer is fully initialized?
@ 2009-04-06 20:27 Tassilo Horn
  2009-04-06 22:17 ` Johan Bockgård
  0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2009-04-06 20:27 UTC (permalink / raw)
  To: emacs-devel

Hi all,

I like using dired, but I don't like the standard behavior of creating
new dired buffers when I hit RET on a directory.  So I use my own
function `th-dired-find-file' which uses `dired-find-alternate-file' for
directories.

This works quite well, but I would like dired to remember the line point
was on the last time I visited that directory, and to go to that line
when I come back.  I tried to use a hashtable (`th-dired-dir-line-map')
mapping the directory to the line number.  The remembering part works
(`th-dired-save-line'), but I cannot find out where I should call
`th-dired-goto-line'.  I tried appending it to `dired-mode-hook' and
`dired-after-readin-hook', and then it says "Going to line X", but in
the dired buffer point is still on the first file after the `..' entry.

What am I doing wrong?

Here's my dired config:

--8<---------------cut here---------------start------------->8---
(require 'dired-x)
(setq dired-omit-files
      (rx (or (seq bol (? ".") "#")         ;; emacs autosave files
              (seq bol "." (not (any "."))) ;; dot-files
              (seq "~" eol)                 ;; backup-files
              (seq bol "CVS" eol)           ;; CVS dirs
              )))

(setq dired-omit-extensions
      (append dired-latex-unclean-extensions
              dired-bibtex-unclean-extensions
              dired-texinfo-unclean-extensions))

(defvar th-dired-dir-line-map (make-hash-table :test 'string=)
  "Maps dirname to line number where dired was.")

(defun th-dired-save-line ()
  (let ((lineno (line-number-at-pos)))
    (puthash dired-directory lineno th-dired-dir-line-map)))

;; TODO: Where do I need to call that.  Both dired-mode-hook and
;; dired-after-readin-hook have no effect.  It says "Going to line X",
;; but in the dired buffer point is on the file after `..'.
(defun th-dired-goto-line ()
  (let ((lineno (gethash dired-directory th-dired-dir-line-map nil)))
    (when lineno
      (message "Going to line %s" lineno)
      (goto-line lineno))))

(defun th-dired-up-directory ()
  "Go up one directory and don't create a new dired buffer but
reuse the current one."
  (interactive)
  (th-dired-save-line)
  (find-alternate-file ".."))

(defun th-dired-find-file ()
  "Find directory reusing the current buffer and file creating a
new buffer."
  (interactive)
  (th-dired-save-line)
  (if (file-directory-p (dired-get-file-for-visit))
      (dired-find-alternate-file)
    (dired-find-file)))

(defun th-dired-mode-init ()
  (dired-omit-mode 1)
  (auto-revert-mode 1)
  (hl-line-mode 1)
  (rename-buffer (concat "dired:" (buffer-name)) t)
  (local-set-key (kbd "C-c C-w") 'wdired-change-to-wdired-mode)
  (local-set-key (kbd "^")       'th-dired-up-directory)
  (local-set-key (kbd "e")       'th-dired-find-file-externally)
  (local-set-key (kbd "RET")     'th-dired-find-file))

(add-hook 'dired-mode-hook 'th-dired-mode-init t)

(put 'dired-find-alternate-file 'disabled nil)
(setq dired-recursive-deletes 'top
      dired-recursive-copies  'top
      dired-listing-switches "-alh"
      dired-dwim-target t)
--8<---------------cut here---------------end--------------->8---

Thanks for any pointers!
Tassilo




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to run code after a dired buffer is fully initialized?
  2009-04-06 20:27 How to run code after a dired buffer is fully initialized? Tassilo Horn
@ 2009-04-06 22:17 ` Johan Bockgård
  2009-04-07  6:23   ` Tassilo Horn
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Bockgård @ 2009-04-06 22:17 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> This works quite well, but I would like dired to remember the line
> point was on the last time I visited that directory, and to go to that
> line when I come back. I tried to use a hashtable
> (`th-dired-dir-line-map') mapping the directory to the line number.
> The remembering part works (`th-dired-save-line'), but I cannot find
> out where I should call `th-dired-goto-line'.

[dired.el]

    (defun dired-initial-position (dirname)
      ;; Where point should go in a new listing of DIRNAME.
      ;; Point assumed at beginning of new subdir line.
      ;; You may redefine this function as you wish, e.g. like in dired-x.el.
      (end-of-line)
      (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to run code after a dired buffer is fully initialized?
  2009-04-06 22:17 ` Johan Bockgård
@ 2009-04-07  6:23   ` Tassilo Horn
  0 siblings, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2009-04-07  6:23 UTC (permalink / raw)
  To: emacs-devel

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

Hi Johan,

>> This works quite well, but I would like dired to remember the line
>> point was on the last time I visited that directory, and to go to
>> that line when I come back. I tried to use a hashtable
>> (`th-dired-dir-line-map') mapping the directory to the line number.
>> The remembering part works (`th-dired-save-line'), but I cannot find
>> out where I should call `th-dired-goto-line'.
>
> [dired.el]
>
>     (defun dired-initial-position (dirname)
>       ;; Where point should go in a new listing of DIRNAME.
>       ;; Point assumed at beginning of new subdir line.
>       ;; You may redefine this function as you wish, e.g. like in dired-x.el.
>       (end-of-line)
>       (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))

Ah, great!  Since the function seems to be intended for redefinition, I
think a user var `dired-initial-position-function' would be better
(easier to find) for users.

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-07  6:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-06 20:27 How to run code after a dired buffer is fully initialized? Tassilo Horn
2009-04-06 22:17 ` Johan Bockgård
2009-04-07  6:23   ` Tassilo Horn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).