From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#20712: 25.0.50; save-place-mode doesn't work for new files Date: Wed, 17 Jun 2015 09:47:22 -0400 Message-ID: References: <87bngzqk7z.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1434548913 5791 80.91.229.3 (17 Jun 2015 13:48:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Jun 2015 13:48:33 +0000 (UTC) Cc: 20712@debbugs.gnu.org To: Tassilo Horn Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 17 15:48:23 2015 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 1Z5DhQ-00048c-ST for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Jun 2015 15:48:17 +0200 Original-Received: from localhost ([::1]:47023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5DhP-0005jR-VG for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Jun 2015 09:48:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5DhG-0005j3-Uy for bug-gnu-emacs@gnu.org; Wed, 17 Jun 2015 09:48:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5DhC-0002jT-Se for bug-gnu-emacs@gnu.org; Wed, 17 Jun 2015 09:48:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5DhC-0002jL-MP for bug-gnu-emacs@gnu.org; Wed, 17 Jun 2015 09:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z5DhC-0007iP-Es for bug-gnu-emacs@gnu.org; Wed, 17 Jun 2015 09:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Jun 2015 13:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20712-submit@debbugs.gnu.org id=B20712.143454885329618 (code B ref 20712); Wed, 17 Jun 2015 13:48:02 +0000 Original-Received: (at 20712) by debbugs.gnu.org; 17 Jun 2015 13:47:33 +0000 Original-Received: from localhost ([127.0.0.1]:57035 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z5Dgi-0007hc-3K for submit@debbugs.gnu.org; Wed, 17 Jun 2015 09:47:33 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:20180) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z5Dge-0007hK-U0 for 20712@debbugs.gnu.org; Wed, 17 Jun 2015 09:47:30 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A2FgA731xV/1enxEVcgxCEAoVVu0CEfoJNBAICgTw6EwEBAQEBAQGBCkEFg10BAQMBViMFCwsOJhIUGA0kiDcIzyMBAQEBAQEEAQEBAR6LOoUFB4QtBYtEk1OOFoYSgUUjhBQigngBAQE X-IPAS-Result: A0A2FgA731xV/1enxEVcgxCEAoVVu0CEfoJNBAICgTw6EwEBAQEBAQGBCkEFg10BAQMBViMFCwsOJhIUGA0kiDcIzyMBAQEBAQEEAQEBAR6LOoUFB4QtBYtEk1OOFoYSgUUjhBQigngBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="127020589" Original-Received: from 69-196-167-87.dsl.teksavvy.com (HELO ceviche.home) ([69.196.167.87]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jun 2015 09:47:22 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 49F756614A; Wed, 17 Jun 2015 09:47:22 -0400 (EDT) In-Reply-To: <87bngzqk7z.fsf@gnu.org> (Tassilo Horn's message of "Mon, 01 Jun 2015 21:53:04 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) 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:104023 Archived-At: > Putting (save-place-mode) in ~/.emacs doesn't have the desired effects > for new files, i.e., files which have no entry in `save-place-alist' / > `save-place-file' yet. > > Recipe: > 1. emacs -Q --eval '(save-place-mode)' test.txt > 2. Add\nsome\ntext. > 3. save and quit emacs > 4. emacs -Q --eval '(save-place-mode)' test.txt > > Expected: point is on the dot in "text." > Actual: point is at 0 [...] > introduced with the commit 9c3e1e4e5bc230c4b4fd6649b6afb5d4792592c2. Oh, indeed, I see the problem: despite the ":global t" argument, define-minor-mode sets the var with `setq' rather than with `setq-default', so the make-variable-buffer-local causes this code to only set the var buffer-locally. I think define-minor-mode should use setq-default instead. Can you try the patch below (after which you need to re-compile saveplace.el)? Stefan diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index bd95a60..dd2abf7 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -153,8 +153,8 @@ For example, you could write (declare (doc-string 2) (debug (&define name string-or-null-p [&optional [¬ keywordp] sexp - &optional [¬ keywordp] sexp - &optional [¬ keywordp] sexp] + &optional [¬ keywordp] sexp + &optional [¬ keywordp] sexp] [&rest [keywordp sexp]] def-body)) (indent 1)) @@ -180,7 +180,8 @@ For example, you could write (extra-args nil) (extra-keywords nil) (variable nil) ;The PLACE where the state is stored. - (setter nil) ;The function (if any) to set the mode var. + (setter `(setq ,mode)) ;The beginning of the exp to set the mode var. + (getter mode) ;The exp to get the mode value. (modefun mode) ;The minor mode function name we're defining. (require t) (after-hook nil) @@ -195,7 +196,10 @@ For example, you could write (pcase keyw (`:init-value (setq init-value (pop body))) (`:lighter (setq lighter (purecopy (pop body)))) - (`:global (setq globalp (pop body))) + (`:global (setq globalp (pop body)) + (when (and globalp (symbolp mode)) + (setq setter `(setq-default ,mode)) + (setq getter `(default-value ',mode)))) (`:extra-args (setq extra-args (pop body))) (`:set (setq set (list :set (pop body)))) (`:initialize (setq initialize (list :initialize (pop body)))) @@ -208,16 +212,18 @@ For example, you could write (or (symbolp tmp) (functionp tmp)))) ;; PLACE is not of the form (GET . SET). - (setq mode variable) - (setq mode (car variable)) - (setq setter (cdr variable)))) + (progn + (setq setter `(setf ,variable)) + (setq getter variable)) + (setq getter (car variable)) + (setq setter `(funcall #',(cdr variable))))) (`:after-hook (setq after-hook (pop body))) (_ (push keyw extra-keywords) (push (pop body) extra-keywords)))) (setq keymap-sym (if (and keymap (symbolp keymap)) keymap (intern (concat mode-name "-map")))) - (unless set (setq set '(:set 'custom-set-minor-mode))) + (unless set (setq set '(:set #'custom-set-minor-mode))) (unless initialize (setq initialize '(:initialize 'custom-initialize-default))) @@ -272,39 +278,30 @@ the mode if ARG is omitted or nil, and toggle it if ARG is `toggle'. ;; repeat-command still does the toggling correctly. (interactive (list (or current-prefix-arg 'toggle))) (let ((,last-message (current-message))) - (,@(if setter `(funcall #',setter) - (list (if (symbolp mode) 'setq 'setf) mode)) + (,@setter (if (eq arg 'toggle) - (not ,mode) + (not ,getter) ;; A nil argument also means ON now. (> (prefix-numeric-value arg) 0))) ,@body ;; The on/off hooks are here for backward compatibility only. - (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) + (run-hooks ',hook (if ,getter ',hook-on ',hook-off)) (if (called-interactively-p 'any) (progn - ,(if (and globalp (symbolp mode)) - ;; Unnecessary but harmless if mode set buffer-locally + ,(if (and globalp (not variable)) `(customize-mark-as-set ',mode)) ;; Avoid overwriting a message shown by the body, ;; but do overwrite previous messages. (unless (and (current-message) (not (equal ,last-message (current-message)))) - (let ((local - ,(if globalp - (if (symbolp mode) - `(if (local-variable-p ',mode) - " in current buffer" - "") - "") - " in current buffer"))) + (let ((local ,(if globalp "" " in current buffer"))) (message ,(format "%s %%sabled%%s" pretty-name) - (if ,mode "en" "dis") local))))) + (if ,getter "en" "dis") local))))) ,@(when after-hook `(,after-hook))) (force-mode-line-update) ;; Return the new setting. - ,mode) + ,getter) ;; Autoloading a define-minor-mode autoloads everything ;; up-to-here. @@ -325,15 +322,16 @@ No problems result if this variable is not bound. (t (error "Invalid keymap %S" m)))) ,(format "Keymap for `%s'." mode-name))) - ,(if (not (symbolp mode)) - (if (or lighter keymap) - (error ":lighter and :keymap unsupported with mode expression %s" mode)) - `(with-no-warnings - (add-minor-mode ',mode ',lighter - ,(if keymap keymap-sym - `(if (boundp ',keymap-sym) ,keymap-sym)) - nil - ,(unless (eq mode modefun) `',modefun))))))) + ,(let ((modevar (pcase getter (`(default-value ',v) v) (_ getter)))) + (if (not (symbolp modevar)) + (if (or lighter keymap) + (error ":lighter and :keymap unsupported with mode expression %S" getter)) + `(with-no-warnings + (add-minor-mode ',modevar ',lighter + ,(if keymap keymap-sym + `(if (boundp ',keymap-sym) ,keymap-sym)) + nil + ,(unless (eq mode modefun) `',modefun)))))))) ;;; ;;; make global minor mode