From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Kanis Newsgroups: gmane.emacs.devel Subject: Re: code review request for saveplace with dired buffer Date: Sun, 09 Jun 2013 17:42:34 +0200 Message-ID: <87bo7f70k5.fsf@kanis.fr> References: <87ppvy4e0m.fsf@kanis.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1370792575 23951 80.91.229.3 (9 Jun 2013 15:42:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Jun 2013 15:42:55 +0000 (UTC) Cc: Emacs Development List To: Stefan Monnier , Glenn Morris , kfogel@red-bean.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 09 17:42:56 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ulhlb-0001NI-Kb for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 17:42:51 +0200 Original-Received: from localhost ([::1]:45836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ulhlb-0004Fb-9o for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 11:42:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlhlV-0004FV-Db for emacs-devel@gnu.org; Sun, 09 Jun 2013 11:42:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UlhlS-0001BF-NB for emacs-devel@gnu.org; Sun, 09 Jun 2013 11:42:45 -0400 Original-Received: from kanis.fr ([46.19.35.252]:40566 helo=srv2.kanis.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlhlS-0001BA-9i; Sun, 09 Jun 2013 11:42:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kanis.fr; s=alpha; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=J9Z2E+nx/FpIUoEWyhSrGz12vRWq9wOS/Yc4f044Xw4=; b=Lujmk0ma6M37vz6J1dU2etp7xhpcRk97xNL/HP1yvBtojQYnL68pDWPv+Tvv1jB6vgzWalwirGyMzu27eXvLoaS8qmbQd7rb+EWamyWECVUPYH3zzjLmLuwijGJe2dlB; Original-Received: from smtp.comencini.fr ([164.138.25.8]) by smtp.comencini.fr with esmtpsa (TLS1.1:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80.1) (envelope-from ) id 1UlhlP-0003pS-1o; Sun, 09 Jun 2013 17:42:40 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAAB5QTFRF IBkXUxMTOCwoTC4qcUY8iFxQmmper31txpaJ/v/8aKZ1oAAAAcVJREFUOMt100tu2zAQAFDCXnUZ oAcIqG68LZULVLQBbwuSiffm6AIRRyeotAySJoVu2+FPpJWWC3/4NKOZocSW/yxWfnJ2+Bdwzhj7 8gleWVy7DXC2rkMNr2V/zRbghXIwthf3VbIA9Ffc71vZCSFyCEsBggtNS8ludwvfmhYA0Vn9o4DP zMWxR7+cPWzAYFzwM0ModtdmcDbDS6i/hT7L+RZof5yCXGrYe5jn2YO6BYMjgY+51tCIAqHgBLwR pwLnGuRjAKyBJkuN4yd4U92uCY1vUr2D/c5b8DuxyQwfOHUeaLqDJhnkkuGXbB56h2C1IVBdgncc bBi6feroa9B6jUDojnQPQKupbyXyeeCE1oT7Oqrt+SnfY3mkiyGA/3AmD3H5g32CcBx6hY8pRkwJ 9PpcjRGobUfprFnhAa1vepwcgMOhwG+pdSgKHFU9HAvoAH6XUl7lDUCCq5Qb6GMbVm3Aj++qDYCt wdBc/YHgOFCmS3mjDMRcSE2qY4E3Q3PVIQRQmeodNH4QEbRUFZzW+VotzwX4yTcRTySOML1qjcE5 hTirVqDHkMAP0PjAywp3d18JZtqzvr9zDYD+GaSKtE6Zlr/DLPNFmOcvBAAAAABJRU5ErkJggg== X-Hashcash: 1:20:130609:monnier@iro.umontreal.ca::t6qoVDXLhOTMGRje:00000000000000000000000000000000000000/zB X-Hashcash: 1:20:130609:kfogel@red-bean.com::YNscd30wR6d8Rnza:0000000000000000000000000000000000000000008mVz X-Hashcash: 1:20:130609:emacs-devel@gnu.org::Dvy3swDOLdWm4DDe:000000000000000000000000000000000000000000B+C0 In-Reply-To: (Stefan Monnier's message of "Fri, 07 Jun 2013 15:12:11 -0400") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 46.19.35.252 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160286 Archived-At: --=-=-= Content-Type: text/plain June, 07 at 15:12 Stefan wrote: > Thanks Ivan. See some stylistic comments below, but otherwise, feel > free to install it. Thanks for your feedback. I am attaching a second patch that takes in account all of your comments. Once I have figured out bzr I will push it. Ivan --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=saveplace-dired2.patch diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bec5a55..7529699 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-06-99 Ivan Kanis + Add support for dired in saveplace. + * dired.el (dired-initial-position-hook): New variable. + (dired-initial-position): Call hook to place cursor position. + * saveplace.el (save-place-to-alist): Add dired position. + (save-place-position-dired-cursor): Move cursor in dired from + previous position. + 2013-06-05 Leo Liu Re-implement smie matching block highlight using diff --git a/lisp/dired.el b/lisp/dired.el index 5b6a787..e5a7229 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -217,6 +217,11 @@ with the buffer narrowed to the listing." ;; Note this can't simply be run inside function `dired-ls' as the hook ;; functions probably depend on the dired-subdir-alist to be OK. +(defcustom dired-initial-position-hook nil + "This hook is used to position the cursor position." + :group 'dired + :type 'hook) + (defcustom dired-dnd-protocol-alist '(("^file:///" . dired-dnd-handle-local-file) ("^file://" . dired-dnd-handle-file) @@ -2762,7 +2767,8 @@ Point assumed at beginning of new subdir line." (end-of-line) (and (featurep 'dired-x) dired-find-subdir (dired-goto-subdir dirname)) - (if dired-trivial-filenames (dired-goto-next-nontrivial-file))) + (if dired-trivial-filenames (dired-goto-next-nontrivial-file)) + (run-hooks 'dired-initial-position-hook)) ;; These are hooks which make tree dired work. ;; They are in this file because other parts of dired need to call them. diff --git a/lisp/saveplace.el b/lisp/saveplace.el index 1b7efce..48d7e09 100644 --- a/lisp/saveplace.el +++ b/lisp/saveplace.el @@ -169,22 +169,24 @@ file: ;; file. If not, do so, then feel free to modify the alist. It ;; will be saved again when Emacs is killed. (or save-place-loaded (load-save-place-alist-from-file)) - (when (and buffer-file-name - (or (not save-place-ignore-files-regexp) - (not (string-match save-place-ignore-files-regexp - buffer-file-name)))) - (let ((cell (assoc buffer-file-name save-place-alist)) - (position (if (not (eq major-mode 'hexl-mode)) - (point) - (with-no-warnings - (1+ (hexl-current-address)))))) - (if cell - (setq save-place-alist (delq cell save-place-alist))) - (if (and save-place - (not (= position 1))) ;; Optimize out the degenerate case. - (setq save-place-alist - (cons (cons buffer-file-name position) - save-place-alist)))))) + (let ((item (or buffer-file-name + (and dired-directory (expand-file-name dired-directory))))) + (when (and item + (or (not save-place-ignore-files-regexp) + (not (string-match save-place-ignore-files-regexp + item)))) + (let ((cell (assoc item save-place-alist)) + (position (if (not (eq major-mode 'hexl-mode)) + (point) + (with-no-warnings + (1+ (hexl-current-address)))))) + (if cell + (setq save-place-alist (delq cell save-place-alist))) + (if (and save-place + (not (= position 1))) ;; Optimize out the degenerate case. + (setq save-place-alist + (cons (cons item position) + save-place-alist))))))) (defun save-place-forget-unreadable-files () "Remove unreadable files from `save-place-alist'. @@ -308,8 +310,20 @@ may have changed\) back to `save-place-alist'." (if save-place-loaded (save-place-alist-to-file))) +(defun save-place-position-dired-cursor () + "Position the cursor in a dired buffer." + (or save-place-loaded (load-save-place-alist-from-file)) + (let ((cell (assoc (expand-file-name dired-directory) save-place-alist))) + (if cell + (progn + (or revert-buffer-in-progress-p + (goto-char (cdr cell))) + ;; and make sure it will be saved again for later + (setq save-place t))))) + (add-hook 'find-file-hook 'save-place-find-file-hook t) +(add-hook 'dired-initial-position-hook 'save-place-position-dired-cursor) (unless noninteractive (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) --=-=-=--