From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: How to run code after a dired buffer is fully initialized? Date: Mon, 06 Apr 2009 22:27:33 +0200 Message-ID: <878wmd5xze.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1239049779 15322 80.91.229.12 (6 Apr 2009 20:29:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Apr 2009 20:29:39 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 06 22:30:58 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LqvSZ-00006R-1x for ged-emacs-devel@m.gmane.org; Mon, 06 Apr 2009 22:30:24 +0200 Original-Received: from localhost ([127.0.0.1]:46846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LqvRA-00041k-Tx for ged-emacs-devel@m.gmane.org; Mon, 06 Apr 2009 16:28:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LqvPy-0002xt-4a for emacs-devel@gnu.org; Mon, 06 Apr 2009 16:27:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LqvPt-0002u8-FN for emacs-devel@gnu.org; Mon, 06 Apr 2009 16:27:41 -0400 Original-Received: from [199.232.76.173] (port=38746 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LqvPt-0002tm-70 for emacs-devel@gnu.org; Mon, 06 Apr 2009 16:27:37 -0400 Original-Received: from out2.smtp.messagingengine.com ([66.111.4.26]:36965) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LqvPs-0002nN-Pk for emacs-devel@gnu.org; Mon, 06 Apr 2009 16:27:37 -0400 Original-Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 72AAA3125E7 for ; Mon, 6 Apr 2009 16:27:36 -0400 (EDT) Original-Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute2.internal (MEProxy); Mon, 06 Apr 2009 16:27:36 -0400 X-Sasl-enc: 7COTSdzikq39JRL8RNdYsbP/xXcdgZIMyZZPuz89wCy+ 1239049655 Original-Received: from thinkpad.tsdh.de (p54AF2BDB.dip0.t-ipconnect.de [84.175.43.219]) by mail.messagingengine.com (Postfix) with ESMTPA id 96D853AB29 for ; Mon, 6 Apr 2009 16:27:35 -0400 (EDT) Mail-Copies-To: never Mail-Followup-To: emacs-devel@gnu.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:110100 Archived-At: 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