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: Sun, 15 Dec 2013 22:20:04 +0200 Organization: JURTA Message-ID: <87sittlvd7.fsf@mail.jurta.org> References: <87mwnj1414.fsf@mail.jurta.org> <8761u6ow6t.fsf@kwarm.red-bean.com> <87d2odvk36.fsf@mail.jurta.org> <87hacy829m.fsf@floss.red-bean.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1387138994 32357 80.91.229.3 (15 Dec 2013 20:23:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Dec 2013 20:23:14 +0000 (UTC) Cc: 15329@debbugs.gnu.org To: Karl Fogel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Dec 15 21:23:19 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 1VsIDf-00081l-5C for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Dec 2013 21:23:19 +0100 Original-Received: from localhost ([::1]:52383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsIDe-0000jX-He for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Dec 2013 15:23:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsIDU-0000jE-PZ for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2013 15:23:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsIDO-0005Tf-PH for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2013 15:23:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsIDO-0005Ta-LH for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2013 15:23:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VsIDO-0007LF-Bk for bug-gnu-emacs@gnu.org; Sun, 15 Dec 2013 15:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Dec 2013 20:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15329 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.138713896628191 (code B ref 15329); Sun, 15 Dec 2013 20:23:02 +0000 Original-Received: (at 15329) by debbugs.gnu.org; 15 Dec 2013 20:22:46 +0000 Original-Received: from localhost ([127.0.0.1]:52087 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsID7-0007Kc-9O for submit@debbugs.gnu.org; Sun, 15 Dec 2013 15:22:45 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:55419 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsID5-0007KU-CI for 15329@debbugs.gnu.org; Sun, 15 Dec 2013 15:22:43 -0500 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id D20CD258B9E936; Sun, 15 Dec 2013 12:22:41 -0800 (PST) In-Reply-To: <87hacy829m.fsf@floss.red-bean.com> (Karl Fogel's message of "Thu, 03 Oct 2013 16:37:09 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) 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:82027 Archived-At: > While the current rather random behavior in dired is obviously a bug, > and fixing it would be a Good Thing, I'm not sure it rises to the level > where I drop other things to work on it :-). However, if someone were > to write a patch (along the lines described in this bug report), I'd > certainly commit to reviewing it. I realized now that the current format is completely backward-compatible. When `find-file-hook' restores the saved position in a file, it doesn't see the dired entries (that end with a directory separator) in the new format. As an additional benefit, the users can add a regexp like "/$" to `save-place-ignore-files-regexp' to not save dired positions. More packages can do the same later, e.g. Info could save the entries like "(emacs) Top" with own additional information that only Info will restore, etc. So now dired positions should be fixed by this patch: === modified file 'lisp/saveplace.el' --- lisp/saveplace.el 2013-09-12 05:32:57 +0000 +++ lisp/saveplace.el 2013-12-15 20:12:27 +0000 @@ -152,8 +152,8 @@ (defun toggle-save-place (&optional parg \(setq-default save-place t\)" (interactive "P") - (if (not buffer-file-name) - (message "Buffer `%s' not visiting a file" (buffer-name)) + (if (not (or buffer-file-name dired-directory)) + (message "Buffer `%s' not visiting a file or directory" (buffer-name)) (if (and save-place (or (not parg) (<= parg 0))) (progn (message "No place will be saved in this file") @@ -161,6 +161,8 @@ (defun toggle-save-place (&optional parg (message "Place will be saved") (setq save-place t)))) +(declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep)) + (defun save-place-to-alist () ;; put filename and point in a cons box and then cons that onto the ;; front of the save-place-alist, if save-place is non-nil. @@ -176,14 +178,20 @@ (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) + (let ((filename (dired-get-filename nil t))) + (if filename + `((dired-filename . ,filename)) + (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))))))) @@ -290,7 +298,8 @@ (defun save-places-to-alist () (with-current-buffer (car buf-list) ;; save-place checks buffer-file-name too, but we can avoid ;; overhead of function call by checking here too. - (and buffer-file-name (save-place-to-alist)) + (and (or buffer-file-name dired-directory) + (save-place-to-alist)) (setq buf-list (cdr buf-list)))))) (defun save-place-find-file-hook () @@ -299,10 +308,13 @@ (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))))) +(declare-function dired-goto-file "dired" (file)) + (defun save-place-dired-hook () "Position the point in a dired buffer." (or save-place-loaded (load-save-place-alist-from-file)) @@ -310,7 +322,10 @@ (defun save-place-dired-hook () (if cell (progn (or revert-buffer-in-progress-p - (goto-char (cdr cell))) + (if (integerp (cdr cell)) + (goto-char (cdr cell)) + (and (assq 'dired-filename (cdr cell)) + (dired-goto-file (cdr (assq 'dired-filename (cdr cell))))))) ;; and make sure it will be saved again for later (setq save-place t)))))