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: Mon, 16 Dec 2013 22:58:41 +0200 Organization: JURTA Message-ID: <87zjo05x8e.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> <87sittlvd7.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1387227616 31045 80.91.229.3 (16 Dec 2013 21:00:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Dec 2013 21:00:16 +0000 (UTC) Cc: Karl Fogel , 15329@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 16 22:00:21 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 1VsfH3-0002aB-Bp for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Dec 2013 22:00:21 +0100 Original-Received: from localhost ([::1]:58159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsfH2-00064G-Rj for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Dec 2013 16:00:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsfGu-00063P-1G for bug-gnu-emacs@gnu.org; Mon, 16 Dec 2013 16:00:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsfGm-0005oH-OP for bug-gnu-emacs@gnu.org; Mon, 16 Dec 2013 16:00:11 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsfGm-0005mr-Lo for bug-gnu-emacs@gnu.org; Mon, 16 Dec 2013 16:00:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VsfGl-0003HL-O8 for bug-gnu-emacs@gnu.org; Mon, 16 Dec 2013 16:00:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Dec 2013 21:00:03 +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.138722756912526 (code B ref 15329); Mon, 16 Dec 2013 21:00:03 +0000 Original-Received: (at 15329) by debbugs.gnu.org; 16 Dec 2013 20:59:29 +0000 Original-Received: from localhost ([127.0.0.1]:54512 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsfGC-0003Fw-L8 for submit@debbugs.gnu.org; Mon, 16 Dec 2013 15:59:29 -0500 Original-Received: from [69.163.184.122] (port=39382 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsfG9-0003Fj-LX for 15329@debbugs.gnu.org; Mon, 16 Dec 2013 15:59:26 -0500 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.184.122]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 957E434CB01680; Mon, 16 Dec 2013 12:59:23 -0800 (PST) In-Reply-To: (Drew Adams's message of "Sun, 15 Dec 2013 13:43:42 -0800 (PST)") 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:82093 Archived-At: >> - (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)) > > Is `dired-directory' really the right test here? I am used to seeing > (derived-mode-p 'dired-mode) for that purpose (assuming I understand the > purpose here). Yes, `dired-directory' is the right test, because `dired-directory' is used as a key in `save-place-alist'. > There is, BTW, nothing in the doc string of `dired-directory' that says > what a nil value means. Thanks for pointing to the doc string of `dired-directory' where I noticed: May be a list, in which case the car is the directory name and the cdr is the list of files to mention. This case should be handled properly that I added to the following patch. > Should code now instead be using `dired-directory' to test whether the > mode is (derived from) Dired? Yes, code should be using `dired-directory' now. > If so, then at the very least the doc string of that variable should > describe such a Boolean meaning: nil means not in Dired mode or a mode > derived from it (or whatever the completely correct interpretation is). Are you sure that nil means not in Dired mode or a mode derived from it? Anyway, this is a new version: === modified file 'lisp/saveplace.el' --- lisp/saveplace.el 2013-09-12 05:32:57 +0000 +++ lisp/saveplace.el 2013-12-16 20:56:14 +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. @@ -170,20 +172,29 @@ (defun save-place-to-alist () ;; will be saved again when Emacs is killed. (or save-place-loaded (load-save-place-alist-from-file)) (let ((item (or buffer-file-name - (and dired-directory (expand-file-name dired-directory))))) + (and dired-directory + (if (consp dired-directory) + (expand-file-name (car 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)))))) + (position (cond ((eq major-mode 'hexl-mode) + (with-no-warnings + (1+ (hexl-current-address)))) + (dired-directory + (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 +301,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,18 +311,27 @@ (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)) - (let ((cell (assoc (expand-file-name dired-directory) save-place-alist))) + (let ((cell (assoc (if (consp dired-directory) + (expand-file-name (car dired-directory)) + (expand-file-name dired-directory)) + save-place-alist))) (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)))))