From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#15329: saveplace restores dired positions to random places Date: Tue, 10 Sep 2013 23:45:15 +0300 Organization: JURTA Message-ID: <87r4cwjy50.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1378846282 18437 80.91.229.3 (10 Sep 2013 20:51:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Sep 2013 20:51:22 +0000 (UTC) To: 15329@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 10 22:51:23 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1VJUuA-0005Ec-QF for geb-bug-gnu-emacs@m.gmane.org; Tue, 10 Sep 2013 22:51:23 +0200 Original-Received: from localhost ([::1]:59958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUuA-0002ps-Gh for geb-bug-gnu-emacs@m.gmane.org; Tue, 10 Sep 2013 16:51:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUtz-0002ou-Is for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:51:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJUtr-00081D-3x for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:51:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUtr-000817-0r for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:51:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VJUtq-00061v-NQ for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Sep 2013 20:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15329 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.137884625423163 (code B ref -1); Tue, 10 Sep 2013 20:51:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Sep 2013 20:50:54 +0000 Original-Received: from localhost ([127.0.0.1]:53376 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VJUti-00061W-Eh for submit@debbugs.gnu.org; Tue, 10 Sep 2013 16:50:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50835) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VJUtf-00061G-SB for submit@debbugs.gnu.org; Tue, 10 Sep 2013 16:50:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJUtS-0007xE-33 for submit@debbugs.gnu.org; Tue, 10 Sep 2013 16:50:46 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:41128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUtS-0007xA-04 for submit@debbugs.gnu.org; Tue, 10 Sep 2013 16:50:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUtM-0002oO-08 for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:50:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJUtD-0007u7-UM for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:50:31 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:53451 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJUtD-0007tZ-Of for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2013 16:50:23 -0400 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 5CA0F258B9E935 for ; Tue, 10 Sep 2013 13:50:21 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:78194 Archived-At: Tags: patch Remembering dired positions is a good feature, but unfortunately in its current implementation is useless. The problem is that often the position of point in Dired is restored to random places because in Dired buffers it depends on many irrelevant ever-changing factors such as the total size of all files in the directory and available space (thus the line with this information changes its length), sizes of each file above the restored file in the Dired buffer also accounts to the incorrect position of point, also added/deleted files in Dired change the restored position to random places, different sorting order, etc. An obvious solution to this problem is to save the current file name in Dired instead of its point. It seems saving information other than point doesn't contradict the purpose of saveplace.el that automatically saves places where visiting them later automatically moves point to the saved position. Also elements of `save-place-alist' are (FILENAME . POSITION), not more limited (FILENAME . POINT). So saving a string to POSITION would be consistent with the design of saveplace.el. === modified file 'lisp/saveplace.el' --- lisp/saveplace.el 2013-06-14 09:32:01 +0000 +++ lisp/saveplace.el 2013-09-10 20:44:01 +0000 @@ -176,14 +178,17 @@ (defun save-place-to-alist () (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)))))) + (position (cond ((eq major-mode 'hexl-mode) + (with-no-warnings + (1+ (hexl-current-address)))) + ((derived-mode-p 'dired-mode) + (or (dired-get-filename nil t) (point))) + (t (point))))) (if cell (setq save-place-alist (delq cell save-place-alist))) (if (and save-place - (not (= position 1))) ;; Optimize out the degenerate case. + (not (and (integerp position) + (= position 1)))) ;; Optimize out the degenerate case. (setq save-place-alist (cons (cons item position) save-place-alist))))))) @@ -298,7 +304,8 @@ (defun save-place-find-file-hook () (if cell (progn (or revert-buffer-in-progress-p - (goto-char (cdr cell))) + (and (integerp (cdr cell)) + (goto-char (cdr cell)))) ;; and make sure it will be saved again for later (setq save-place t))))) @@ -309,7 +318,10 @@ (defun save-place-dired-hook () (if cell (progn (or revert-buffer-in-progress-p - (goto-char (cdr cell))) + (cond ((integerp (cdr cell)) + (goto-char (cdr cell))) + ((stringp (cdr cell)) + (dired-goto-file (cdr cell))))) ;; and make sure it will be saved again for later (setq save-place t)))))