From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] emacs-25 040e0d6: Fix 'toggle-save-place' Date: Thu, 25 Feb 2016 12:57:49 -0500 Message-ID: References: <20160224205710.26753.62720@vcs.savannah.gnu.org> <83si0gg4af.fsf@gnu.org> <83bn74g0cd.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1456423092 32666 80.91.229.3 (25 Feb 2016 17:58:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Feb 2016 17:58:12 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 25 18:58:04 2016 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 1aZ0At-0000KW-Fu for ged-emacs-devel@m.gmane.org; Thu, 25 Feb 2016 18:58:03 +0100 Original-Received: from localhost ([::1]:44993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ0As-0008Jj-QN for ged-emacs-devel@m.gmane.org; Thu, 25 Feb 2016 12:58:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ0Ao-0008IA-Ul for emacs-devel@gnu.org; Thu, 25 Feb 2016 12:57:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZ0Ao-0005rs-2Q for emacs-devel@gnu.org; Thu, 25 Feb 2016 12:57:58 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:63123) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ0Ah-0005qN-QJ; Thu, 25 Feb 2016 12:57:51 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BCFgA731xV/+OhCkxcgxCEAoVVwD6CTQQCAoE8PRABAQEBAQEBgQpBBYNdAQEEViMQCzQSFBgNJIg/zyMBAQEBAQUBAQEBAR2LOoUFB4QtBYtEbJJnkhSCFIFFI4QWIIJ4AQEB X-IPAS-Result: A0BCFgA731xV/+OhCkxcgxCEAoVVwD6CTQQCAoE8PRABAQEBAQEBgQpBBYNdAQEEViMQCzQSFBgNJIg/zyMBAQEBAQUBAQEBAR2LOoUFB4QtBYtEbJJnkhSCFIFFI4QWIIJ4AQEB X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="194382752" Original-Received: from 76-10-161-227.dsl.teksavvy.com (HELO pastel.home) ([76.10.161.227]) by ironport2-out.teksavvy.com with ESMTP; 25 Feb 2016 12:57:49 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 6941163F8B; Thu, 25 Feb 2016 12:57:49 -0500 (EST) In-Reply-To: <83bn74g0cd.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 25 Feb 2016 19:34:58 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:200670 Archived-At: >> -;;;###autoload > I'd like to keep the autoload, otherwise there's an asymmetry: the > global mode is autoloaded, the local one isn't. But there's no "local mode" yet. That'll be added in 26. For 25.1 there's only a "local toggle function". It's mostly a question of name, admittedly. An alternative is to use the patch below, which is more intrusive. diff --git a/lisp/saveplace.el b/lisp/saveplace.el index 0233a52..b2140fb 100644 --- a/lisp/saveplace.el +++ b/lisp/saveplace.el @@ -120,6 +120,25 @@ save-place-ignore-files-regexp (declare-function dired-current-directory "dired" (&optional localp)) +(defun save-place--setup-hooks (add) + (cond + (add + (add-hook 'find-file-hook #'save-place-find-file-hook t) + (add-hook 'dired-initial-position-hook #'save-place-dired-hook) + (unless noninteractive + (add-hook 'kill-emacs-hook #'save-place-kill-emacs-hook)) + (add-hook 'kill-buffer-hook #'save-place-to-alist)) + (t + ;; We should remove the hooks, but only if save-place-mode + ;; is nil everywhere. Is it worth the trouble, tho? + ;; (unless (or (default-value 'save-place-mode) + ;; (cl-some (buffer-list))) + ;; (remove-hook 'find-file-hook #'save-place-find-file-hook) + ;; (remove-hook 'dired-initial-position-hook #'save-place-dired-hook) + ;; (remove-hook 'kill-emacs-hook #'save-place-kill-emacs-hook) + ;; (remove-hook 'kill-buffer-hook #'save-place-to-alist)) + ))) + (define-obsolete-variable-alias 'save-place 'save-place-mode "25.1") ;;;###autoload (define-minor-mode save-place-mode @@ -128,23 +147,14 @@ save-place-mode where it was when you previously visited the same file." :global t :group 'save-place - (cond - (save-place-mode - (add-hook 'find-file-hook 'save-place-find-file-hook t) - (add-hook 'dired-initial-position-hook 'save-place-dired-hook) - (unless noninteractive - (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) - (add-hook 'kill-buffer-hook 'save-place-to-alist)) - (t - (remove-hook 'find-file-hook 'save-place-find-file-hook t) - (remove-hook 'dired-initial-position-hook 'save-place-dired-hook) - (remove-hook 'kill-emacs-hook 'save-place-kill-emacs-hook) - (remove-hook 'kill-buffer-hook 'save-place-to-alist)))) + (save-place--setup-hooks save-place-mode)) -(make-variable-buffer-local 'save-place-mode) ; Hysterical raisins. +(make-variable-buffer-local 'save-place-mode) +(define-obsolete-function-alias 'toggle-save-place + #'save-place-local-mode "25.1") ;;;###autoload -(defun toggle-save-place (&optional parg) ;FIXME: save-place-local-mode! +(define-minor-mode save-place-local-mode "Toggle whether to save your place in this file between sessions. If this mode is enabled, point is recorded when you kill the buffer or exit Emacs. Visiting this file again will go to that position, @@ -157,30 +167,13 @@ toggle-save-place file: \(save-place-mode 1)" - (interactive "P") + :variable save-place-mode (if (not (or buffer-file-name (and (derived-mode-p 'dired-mode) (boundp 'dired-subdir-alist) dired-subdir-alist (dired-current-directory)))) (message "Buffer `%s' not visiting a file or directory" (buffer-name)) - (setq save-place (if parg - (> (prefix-numeric-value parg) 0) - (not save-place))) - (cond - (save-place - (add-hook 'find-file-hook 'save-place-find-file-hook t) - (add-hook 'dired-initial-position-hook 'save-place-dired-hook) - (unless noninteractive - (add-hook 'kill-emacs-hook 'save-place-kill-emacs-hook)) - (add-hook 'kill-buffer-hook 'save-place-to-alist)) - (t - (remove-hook 'find-file-hook 'save-place-find-file-hook t) - (remove-hook 'dired-initial-position-hook 'save-place-dired-hook) - (remove-hook 'kill-emacs-hook 'save-place-kill-emacs-hook) - (remove-hook 'kill-buffer-hook 'save-place-to-alist))) - (message (if save-place - "Place will be saved" - "No place will be saved in this file")))) + (save-place--setup-hooks save-place-mode))) (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))