From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-devel@gnu.org
Subject: How to run code after a dired buffer is fully initialized?
Date: Mon, 06 Apr 2009 22:27:33 +0200 [thread overview]
Message-ID: <878wmd5xze.fsf@thinkpad.tsdh.de> (raw)
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
next reply other threads:[~2009-04-06 20:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-06 20:27 Tassilo Horn [this message]
2009-04-06 22:17 ` How to run code after a dired buffer is fully initialized? Johan Bockgård
2009-04-07 6:23 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878wmd5xze.fsf@thinkpad.tsdh.de \
--to=tassilo@member.fsf.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).