From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places 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 To: 15329@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.137884625423163 (code B ref -1); Tue, 10 Sep 2013 20:51:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Sep 2013 20:50:54 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 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 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 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 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 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) From: Juri Linkov Organization: JURTA Date: Tue, 10 Sep 2013 23:45:15 +0300 Message-ID: <87r4cwjy50.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain 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-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) 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))))) From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Sep 2013 20:48: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 To: 15329@debbugs.gnu.org Cc: emacs-devel@gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.137893244820254 (code B ref 15329); Wed, 11 Sep 2013 20:48:02 +0000 Received: (at 15329) by debbugs.gnu.org; 11 Sep 2013 20:47:28 +0000 Received: from localhost ([127.0.0.1]:56622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VJrJv-0005Gb-FB for submit@debbugs.gnu.org; Wed, 11 Sep 2013 16:47:27 -0400 Received: from ps18281.dreamhost.com ([69.163.218.105]:40894 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VJrJs-0005GQ-Fk for 15329@debbugs.gnu.org; Wed, 11 Sep 2013 16:47:25 -0400 Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 8CFCD258B9E935; Wed, 11 Sep 2013 13:47:22 -0700 (PDT) From: Juri Linkov Organization: JURTA References: <87r4cwjy50.fsf@mail.jurta.org> Date: Wed, 11 Sep 2013 23:45:11 +0300 In-Reply-To: <87r4cwjy50.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 10 Sep 2013 23:45:15 +0300") Message-ID: <87mwnj1414.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) > 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. I realized this is not backward-compatible change, i.e. older Emacs versions won't be able to read saved places in the new format. Unfortunately, Dired filename positions can't be added to the current format that uses an alist with cons pair cells. I mean (FILENAME . POINT) can't be changed to (FILENAME POINT DIRED-FILENAME-POSITION) because older Emacs versions will fail to read them. The only solution that I see is to save two alists to the places file: ((FILENAME1 . POINT1) (FILENAME2 . POINT2) ...) ((FILENAME1 DIRED-FILENAME-POSITION1) (FILENAME2 DIRED-FILENAME-POSITION2) ...) Then the current code: (with-demoted-errors (car (read-from-string (buffer-substring (point-min) (point-max))))) will read the first alist without problems, and additional code in newer versions like (with-demoted-errors (cadr (read-from-string (buffer-substring (point-min) (point-max))))) will read the second alist with more information about the context of saved places (like bookmarks). From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Karl Fogel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Sep 2013 16:14:01 +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 To: emacs-devel@gnu.org Cc: 15329@debbugs.gnu.org Reply-To: Karl Fogel Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.137900238814089 (code B ref 15329); Thu, 12 Sep 2013 16:14:01 +0000 Received: (at 15329) by debbugs.gnu.org; 12 Sep 2013 16:13:08 +0000 Received: from localhost ([127.0.0.1]:59229 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VK9W0-0003fA-7E for submit@debbugs.gnu.org; Thu, 12 Sep 2013 12:13:08 -0400 Received: from mail-oa0-f48.google.com ([209.85.219.48]:42294) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VK9Vy-0003eg-H3 for 15329@debbugs.gnu.org; Thu, 12 Sep 2013 12:13:07 -0400 Received: by mail-oa0-f48.google.com with SMTP id o17so14923oag.7 for <15329@debbugs.gnu.org>; Thu, 12 Sep 2013 09:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:references:references :reply-to:date:message-id:user-agent:mime-version:content-type; bh=qs+BGgrAYpBNXFpxhdbpcLpmJ/SKaC55S5HOW0fi66A=; b=kQNGkKG7gBBceB8axprelQyUXl2ezDJWITnAQdi6AcYhC+lRcsHJUM8Qcf7poVJkev evtc5NndrLQ9vs83ehOQnXS7vQeZtmc1dzdaLDS6uhc+7rdyuOvR5/f+6eYsWzyjQV6o C6MfcVZ0ktdJADD4KdvudKOhj03c5a0pWibixUFsY2+jq+/ANmLJCvTCh5xgABGWsE7A oULDMcVcNBwHz/5YUgg51DLpv+pRDM7TnMyfZSZYhoOsBOClEXO7UHupXT//nM9zwd08 jilunJWfeJobwMyM5KOR5i6Osh7HG/bR4Hvv2hLvztIsI0hs2qx8kasU3RK8ApMNY0d4 8ulg== X-Received: by 10.60.116.170 with SMTP id jx10mr1146781oeb.98.1379002380679; Thu, 12 Sep 2013 09:13:00 -0700 (PDT) Received: from kwarm.red-bean.com (74-92-190-113-Illinois.hfc.comcastbusiness.net. [74.92.190.113]) by mx.google.com with ESMTPSA id tz10sm6455847obc.10.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 12 Sep 2013 09:13:00 -0700 (PDT) From: Karl Fogel In-Reply-To: <87mwnj1414.fsf@mail.jurta.org> References: References: <87mwnj1414.fsf@mail.jurta.org> Date: Thu, 12 Sep 2013 11:12:58 -0500 Message-ID: <8761u6ow6t.fsf@kwarm.red-bean.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Juri Linkov wrote: >> 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. > >I realized this is not backward-compatible change, i.e. >older Emacs versions won't be able to read saved places >in the new format. Unfortunately, Dired filename positions >can't be added to the current format that uses an alist >with cons pair cells. I mean (FILENAME . POINT) >can't be changed to (FILENAME POINT DIRED-FILENAME-POSITION) >because older Emacs versions will fail to read them. > >The only solution that I see is to save two alists to the places file: > >((FILENAME1 . POINT1) > (FILENAME2 . POINT2) > ...) >((FILENAME1 DIRED-FILENAME-POSITION1) > (FILENAME2 DIRED-FILENAME-POSITION2) > ...) > >Then the current code: > > (with-demoted-errors > (car (read-from-string > (buffer-substring (point-min) (point-max))))) > >will read the first alist without problems, >and additional code in newer versions like > > (with-demoted-errors > (cadr (read-from-string > (buffer-substring (point-min) (point-max))))) > >will read the second alist with more information >about the context of saved places (like bookmarks). Well, rather, we could use that as an upgrade strategy for the saveplace format as a whole. In other words, starting now and for a few versions of Emacs into the future, write the old format to the first part of the file, and then a more flexible new format to the second part. The modern format would have a more extensible structure, similarly to how bookmark.el does it. Say, a sublist whose first element is the type of the record, and the rest of which is the data for that record. Like: ((FILE_OR_DIR_NAME_1 ('position (position information goes here))) (FILE_OR_DIR_NAME_2 ('dired-position (different kind of information))) ...) etc. Thoughts? -Karl From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Sep 2013 19:14: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 To: Karl Fogel Cc: 15329@debbugs.gnu.org, emacs-devel@gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.13790131887577 (code B ref 15329); Thu, 12 Sep 2013 19:14:02 +0000 Received: (at 15329) by debbugs.gnu.org; 12 Sep 2013 19:13:08 +0000 Received: from localhost ([127.0.0.1]:59552 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VKCKC-0001y9-7h for submit@debbugs.gnu.org; Thu, 12 Sep 2013 15:13:08 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:23475) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VKCKA-0001xV-34 for 15329@debbugs.gnu.org; Thu, 12 Sep 2013 15:13:06 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFG4rxBo/2dsb2JhbABEvw4Xc4IfAQVWIxALDiYSFBgNJIgkwS2RCgOkeoFegxM X-IPAS-Result: Av4EABK/CFG4rxBo/2dsb2JhbABEvw4Xc4IfAQVWIxALDiYSFBgNJIgkwS2RCgOkeoFegxM X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="27525330" Received: from 184-175-16-104.dsl.teksavvy.com (HELO pastel.home) ([184.175.16.104]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 12 Sep 2013 15:09:30 -0400 Received: by pastel.home (Postfix, from userid 20848) id 3B2B962D8E; Thu, 12 Sep 2013 15:13:00 -0400 (EDT) From: Stefan Monnier Message-ID: References: <87mwnj1414.fsf@mail.jurta.org> <8761u6ow6t.fsf@kwarm.red-bean.com> Date: Thu, 12 Sep 2013 15:13:00 -0400 In-Reply-To: <8761u6ow6t.fsf@kwarm.red-bean.com> (Karl Fogel's message of "Thu, 12 Sep 2013 11:12:58 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) > ((FILE_OR_DIR_NAME_1 ('position (position information goes here))) > (FILE_OR_DIR_NAME_2 ('dired-position (different kind of information))) > ...) Re-using as much as possible of bookmarks's format would make sense. Stefan From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Sep 2013 20:54: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 To: Karl Fogel Cc: 15329@debbugs.gnu.org, emacs-devel@gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.137901921917354 (code B ref 15329); Thu, 12 Sep 2013 20:54:02 +0000 Received: (at 15329) by debbugs.gnu.org; 12 Sep 2013 20:53:39 +0000 Received: from localhost ([127.0.0.1]:59729 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VKDtT-0004Vp-1i for submit@debbugs.gnu.org; Thu, 12 Sep 2013 16:53:39 -0400 Received: from ps18281.dreamhost.com ([69.163.218.105]:44005 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VKDtR-0004Vf-4E for 15329@debbugs.gnu.org; Thu, 12 Sep 2013 16:53:37 -0400 Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 18A9D258B9E935; Thu, 12 Sep 2013 13:53:34 -0700 (PDT) From: Juri Linkov Organization: JURTA References: <87mwnj1414.fsf@mail.jurta.org> <8761u6ow6t.fsf@kwarm.red-bean.com> Date: Thu, 12 Sep 2013 23:52:29 +0300 In-Reply-To: <8761u6ow6t.fsf@kwarm.red-bean.com> (Karl Fogel's message of "Thu, 12 Sep 2013 11:12:58 -0500") Message-ID: <87d2odvk36.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) > The modern format would have a more extensible structure, similarly to how > bookmark.el does it. Say, a sublist whose first element is the type of > the record, and the rest of which is the data for that record. Do you think it would be possible to use the existing infrastructure of bookmark.el, so for instance, to save a place in an Info manual, saveplace.el could call `Info-bookmark-make-record' and to restore it with `Info-bookmark-jump'. This would be better than adding a third hook for saveplace (the second existing hook is desktop-specific like `Info-desktop-buffer-misc-data' and `Info-restore-desktop-buffer'). From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Karl Fogel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 03 Oct 2013 21:38: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 To: Juri Linkov Cc: 15329@debbugs.gnu.org, emacs-devel@gnu.org Reply-To: Karl Fogel Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.13808362353298 (code B ref 15329); Thu, 03 Oct 2013 21:38:02 +0000 Received: (at 15329) by debbugs.gnu.org; 3 Oct 2013 21:37:15 +0000 Received: from localhost ([127.0.0.1]:52491 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VRqaB-0000r8-5S for submit@debbugs.gnu.org; Thu, 03 Oct 2013 17:37:15 -0400 Received: from mail-ie0-f170.google.com ([209.85.223.170]:36970) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VRqa8-0000qx-Aa for 15329@debbugs.gnu.org; Thu, 03 Oct 2013 17:37:14 -0400 Received: by mail-ie0-f170.google.com with SMTP id x13so7257838ief.29 for <15329@debbugs.gnu.org>; Thu, 03 Oct 2013 14:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:reply-to:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=Aa6cCtloVJhupzXw7ceNR1UYjTWoaZ+bQayThXlmkdA=; b=mQQVzn4tIF//MiZtC7uUj8nq3aFr6mBPNRbfT8UDh+RxQi2Cgw35MnhQz907t4yX7k 2W5oWJ5jiR1Y/ZhdljH+2SD+FxYlAWthVyXDIHDE9KDSYkw5GDLLZy5i0OX4i3CdujKu O7Hj5dU3SgW1pxHMbvFLJnWPoXTqTRUvBYAzOSh1b0VmbmNrOdgL934eekLex4uxvoWh 0fkMcgR5eoVSMT+Paxyx0PJMlsYkaPKH8SOG5fHwcPn1CmP5bdwXVX7J6IJQN983oT7p 6iqe/jx/3XbsJDT5Q+oPMj9N3P/WrZfTjcHmPl2UQIs1x9AHO8um0z0vDVipOU+qDd8L /5WA== X-Received: by 10.42.12.80 with SMTP id x16mr2561955icx.56.1380836231405; Thu, 03 Oct 2013 14:37:11 -0700 (PDT) Received: from floss.red-bean.com (74-92-190-113-Illinois.hfc.comcastbusiness.net. [74.92.190.113]) by mx.google.com with ESMTPSA id w4sm2574081igb.5.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 03 Oct 2013 14:37:10 -0700 (PDT) From: Karl Fogel References: <87mwnj1414.fsf@mail.jurta.org> <8761u6ow6t.fsf@kwarm.red-bean.com> <87d2odvk36.fsf@mail.jurta.org> Date: Thu, 03 Oct 2013 16:37:09 -0500 In-Reply-To: <87d2odvk36.fsf@mail.jurta.org> (Juri Linkov's message of "Thu, 12 Sep 2013 23:52:29 +0300") Message-ID: <87hacy829m.fsf@floss.red-bean.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Juri Linkov writes: >> The modern format would have a more extensible structure, similarly to how >> bookmark.el does it. Say, a sublist whose first element is the type of >> the record, and the rest of which is the data for that record. > >Do you think it would be possible to use the existing >infrastructure of bookmark.el, so for instance, to save >a place in an Info manual, saveplace.el could call >`Info-bookmark-make-record' and to restore it with >`Info-bookmark-jump'. This would be better than adding >a third hook for saveplace (the second existing hook >is desktop-specific like `Info-desktop-buffer-misc-data' >and `Info-restore-desktop-buffer'). Yes; since both saveplace and bookmark are in the standard Emacs dist, it's fine for them to share code, and would improve maintainability. I'm not sure when I'll get a chance to work on this, though. The original bug here is about saving/restoring position in dired buffers. 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. Best, -Karl From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places 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 To: Karl Fogel Cc: 15329@debbugs.gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.138713896628191 (code B ref 15329); Sun, 15 Dec 2013 20:23:02 +0000 Received: (at 15329) by debbugs.gnu.org; 15 Dec 2013 20:22:46 +0000 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 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 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) From: Juri Linkov Organization: JURTA References: <87mwnj1414.fsf@mail.jurta.org> <8761u6ow6t.fsf@kwarm.red-bean.com> <87d2odvk36.fsf@mail.jurta.org> <87hacy829m.fsf@floss.red-bean.com> Date: Sun, 15 Dec 2013 22:20:04 +0200 In-Reply-To: <87hacy829m.fsf@floss.red-bean.com> (Karl Fogel's message of "Thu, 03 Oct 2013 16:37:09 -0500") Message-ID: <87sittlvd7.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) > 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))))) From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Dec 2013 21:44: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 To: Juri Linkov , Karl Fogel Cc: 15329@debbugs.gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.13871438288155 (code B ref 15329); Sun, 15 Dec 2013 21:44:02 +0000 Received: (at 15329) by debbugs.gnu.org; 15 Dec 2013 21:43:48 +0000 Received: from localhost ([127.0.0.1]:52169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsJTY-00027T-90 for submit@debbugs.gnu.org; Sun, 15 Dec 2013 16:43:48 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:27462) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsJTV-00027K-M8 for 15329@debbugs.gnu.org; Sun, 15 Dec 2013 16:43:46 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBFLhhZO018904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 15 Dec 2013 21:43:44 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBFLhgPR006957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 15 Dec 2013 21:43:43 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBFLhgeg016977; Sun, 15 Dec 2013 21:43:42 GMT MIME-Version: 1.0 Message-ID: Date: Sun, 15 Dec 2013 13:43:42 -0800 (PST) From: Drew Adams 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> In-Reply-To: <87sittlvd7.fsf@mail.jurta.org> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6680.5000 (x86)] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) > - (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). There is, BTW, nothing in the doc string of `dired-directory' that says what a nil value means. Should code now instead be using `dired-directory' to test whether the mode is (derived from) Dired? 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). From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places 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 To: Drew Adams Cc: Karl Fogel , 15329@debbugs.gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.138722756912526 (code B ref 15329); Mon, 16 Dec 2013 21:00:03 +0000 Received: (at 15329) by debbugs.gnu.org; 16 Dec 2013 20:59:29 +0000 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 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 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) From: Juri Linkov Organization: JURTA 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> Date: Mon, 16 Dec 2013 22:58:41 +0200 In-Reply-To: (Drew Adams's message of "Sun, 15 Dec 2013 13:43:42 -0800 (PST)") Message-ID: <87zjo05x8e.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: >> - (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). [...] Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: >> - (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). [...] Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS >> - (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))))) From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Dec 2013 21:16: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 To: Juri Linkov Cc: Karl Fogel , 15329@debbugs.gnu.org Received: via spool by 15329-submit@debbugs.gnu.org id=B15329.138722855014370 (code B ref 15329); Mon, 16 Dec 2013 21:16:02 +0000 Received: (at 15329) by debbugs.gnu.org; 16 Dec 2013 21:15:50 +0000 Received: from localhost ([127.0.0.1]:54534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsfW1-0003jh-Mz for submit@debbugs.gnu.org; Mon, 16 Dec 2013 16:15:50 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:45859) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VsfW0-0003jZ-D6 for 15329@debbugs.gnu.org; Mon, 16 Dec 2013 16:15:49 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBGLFkWc023493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Dec 2013 21:15:47 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBGLFiFX017502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 16 Dec 2013 21:15:45 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBGLFikG019151; Mon, 16 Dec 2013 21:15:44 GMT MIME-Version: 1.0 Message-ID: Date: Mon, 16 Dec 2013 13:15:43 -0800 (PST) From: Drew Adams 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> <87zjo05x8e.fsf@mail.jurta.org> In-Reply-To: <87zjo05x8e.fsf@mail.jurta.org> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6680.5000 (x86)] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) > > Is `dired-directory' really the right test here? I am used to seeing > > (derived-mode-p 'dired-mode) for that purpose (assuming I understand th= e > > purpose here). >=20 > Yes, `dired-directory' is the right test, because `dired-directory' > is used as a key in `save-place-alist'. OK. > > There is, BTW, nothing in the doc string of `dired-directory' that says > > what a nil value means. >=20 > Thanks for pointing to the doc string of `dired-directory' where I notice= d: >=20 > May be a list, in which case the car is the > directory name and the cdr is the list of files to mention. Yes, I use that use case quite a lot. > This case should be handled properly that I added to the following patch. Great. > > Should code now instead be using `dired-directory' to test whether the > > mode is (derived from) Dired? >=20 > Yes, code should be using `dired-directory' now. OK. Do you happen to know whether that is only the case now or has been th= e case all along? `dired-directory' is old, but I have always seen `derived-mode-p' used for the test - and I see it still, e.g., for `dired-toggle-read-only'. Or does it perhaps not matter at all which we use? Looking for what is best to use with multiple Emacs versions. > > 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). ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >=20 > Are you sure that nil means not in Dired mode or a mode derived from it? I posed a question; I didn't make a statement. Let's please describe what nil means here, whatever that might be. > Anyway, this is a new version: Thanks for taking the cons case into account. From unknown Sun Jun 15 01:07:28 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Juri Linkov Subject: bug#15329: closed (Re: bug#15329: saveplace restores dired positions to random places) Message-ID: References: <871u17w9xy.fsf@mail.jurta.org> <87r4cwjy50.fsf@mail.jurta.org> X-Gnu-PR-Message: they-closed 15329 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 15329@debbugs.gnu.org Date: Fri, 20 Dec 2013 20:23:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1387570982-26723-1" This is a multi-part message in MIME format... ------------=_1387570982-26723-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #15329: saveplace restores dired positions to random places which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 15329@debbugs.gnu.org. --=20 15329: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D15329 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1387570982-26723-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 15329-done) by debbugs.gnu.org; 20 Dec 2013 20:22:02 +0000 Received: from localhost ([127.0.0.1]:60479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vu6aA-0006vY-F8 for submit@debbugs.gnu.org; Fri, 20 Dec 2013 15:22:02 -0500 Received: from [69.163.184.122] (port=36801 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vu6a8-0006v9-Iy for 15329-done@debbugs.gnu.org; Fri, 20 Dec 2013 15:22:01 -0500 Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.184.122]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 27AF932CCE8D9F; Fri, 20 Dec 2013 12:21:58 -0800 (PST) From: Juri Linkov To: Karl Fogel Subject: Re: bug#15329: saveplace restores dired positions to random places Organization: JURTA 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> Date: Fri, 20 Dec 2013 22:20:57 +0200 In-Reply-To: <87sittlvd7.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 15 Dec 2013 22:20:04 +0200") Message-ID: <871u17w9xy.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: > 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. [...] Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Debbugs-Envelope-To: 15329-done Cc: 15329-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: > 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. [...] Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS > 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. Karl, due to the imminent feature freeze I had to commit the patch now. Please revert it if you don't agree with this implementation. ------------=_1387570982-26723-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 10 Sep 2013 20:50:54 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 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 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 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 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 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) From: Juri Linkov To: bug-gnu-emacs@gnu.org Subject: saveplace restores dired positions to random places Organization: JURTA Date: Tue, 10 Sep 2013 23:45:15 +0300 Message-ID: <87r4cwjy50.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain 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-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) 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))))) ------------=_1387570982-26723-1-- From unknown Sun Jun 15 01:07:28 2025 X-Loop: help-debbugs@gnu.org Subject: bug#15329: saveplace restores dired positions to random places Resent-From: Karl Fogel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Dec 2013 02:10: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 To: Juri Linkov Cc: 15329-done@debbugs.gnu.org Reply-To: Karl Fogel Received: via spool by 15329-done@debbugs.gnu.org id=D15329.13875917531083 (code D ref 15329); Sat, 21 Dec 2013 02:10:03 +0000 Received: (at 15329-done) by debbugs.gnu.org; 21 Dec 2013 02:09:13 +0000 Received: from localhost ([127.0.0.1]:60587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VuC08-0000HO-4V for submit@debbugs.gnu.org; Fri, 20 Dec 2013 21:09:12 -0500 Received: from mail-ig0-f177.google.com ([209.85.213.177]:47002) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VuC04-0000HB-NG for 15329-done@debbugs.gnu.org; Fri, 20 Dec 2013 21:09:09 -0500 Received: by mail-ig0-f177.google.com with SMTP id uy17so8686926igb.4 for <15329-done@debbugs.gnu.org>; Fri, 20 Dec 2013 18:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:reply-to:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=shbszfJBajPwpVSouyoUNEJwDIxTbU8wf4wg2nIaL9c=; b=hrITJjk01WCph1+0yOz3XIpWIfSbZ/y7yLBYfmrIsvuDTWBwP6VSuaHKESYqFXhtVm 9WxJVdhOUtpJYiRxPyqSv/P4cHXR0R/NccF6wtbEFE55G1IlM4lWAYkK8VbWTdGv8f9u 00X+lH6gys5n840lgNlDW4gxbszuGs6vfes6asAR8VcujLO5RThRgDynQNGg6AETO7Vv x89EFNSmqfpLsigmaVmBDlB20S9rfdSxHHn234U3OOvL2uDBZrUvemnC2fTMFxjMMOU6 huc92pYvonRjhgTnZCofH2Ny3LoaIsQypWHI4pjNbEyImZhCMOLGFiwhtMkskmk57dzP tzAw== X-Received: by 10.43.154.73 with SMTP id ld9mr8461icc.53.1387591748058; Fri, 20 Dec 2013 18:09:08 -0800 (PST) Received: from ktab.red-bean.com (74-92-190-113-Illinois.hfc.comcastbusiness.net. [74.92.190.113]) by mx.google.com with ESMTPSA id y10sm14886724igl.4.2013.12.20.18.09.06 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 20 Dec 2013 18:09:07 -0800 (PST) From: Karl Fogel 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> <871u17w9xy.fsf@mail.jurta.org> Date: Fri, 20 Dec 2013 20:09:06 -0600 In-Reply-To: <871u17w9xy.fsf@mail.jurta.org> (Juri Linkov's message of "Fri, 20 Dec 2013 22:20:57 +0200") Message-ID: <871u17rm4d.fsf@ktab.red-bean.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Juri Linkov writes: >> 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. > >Karl, due to the imminent feature freeze I had to commit the patch now. >Please revert it if you don't agree with this implementation. Understood, and thank you. Unlike the rest of the Western world, my schedule is such that I don't have much time for Emacs hacking during the holiday season, but should be able to pay some attention to Emacs stuff afterwards. So I'll review this then. It's unfortunate that that review has to wait until possibly after the release :-(, but I try to think about these things with a long term perspective... Best, -K