From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Federico Tedin Newsgroups: gmane.emacs.bugs Subject: bug#38317: Buffer-local variables don't work as history for read-from-minibuffer Date: Sun, 24 Nov 2019 00:12:15 +0100 Message-ID: <87wobq5gs0.fsf@gmail.com> References: <87eey0lxxm.fsf@gmail.com> <87v9rcqbls.fsf@gnus.org> <5a0c68d0-4d25-bf8d-fbe8-f106b0f92210@gmx.at> <875zjareo1.fsf@gnus.org> <874kyu72kl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="67427"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 38317@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 24 00:15:21 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iYecb-000HPe-CW for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Nov 2019 00:15:21 +0100 Original-Received: from localhost ([::1]:33144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iYeca-0002az-AP for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Nov 2019 18:15:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36419) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iYecO-0002af-2i for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2019 18:15:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iYecM-0002Q6-4J for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2019 18:15:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iYecL-0002Pl-4k for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2019 18:15:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iYecI-0007UO-Lx for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2019 18:15:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Nov 2019 23:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38317 X-GNU-PR-Package: emacs Original-Received: via spool by 38317-submit@debbugs.gnu.org id=B38317.157455088628747 (code B ref 38317); Sat, 23 Nov 2019 23:15:02 +0000 Original-Received: (at 38317) by debbugs.gnu.org; 23 Nov 2019 23:14:46 +0000 Original-Received: from localhost ([127.0.0.1]:57960 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iYebz-0007TZ-Oj for submit@debbugs.gnu.org; Sat, 23 Nov 2019 18:14:46 -0500 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:46901) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iYebq-0007TD-Kl for 38317@debbugs.gnu.org; Sat, 23 Nov 2019 18:14:39 -0500 Original-Received: by mail-wr1-f41.google.com with SMTP id z7so9544719wrl.13 for <38317@debbugs.gnu.org>; Sat, 23 Nov 2019 15:14:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=+xa+qOHl6vSbHtQE/NlGKdhQOOxh23wLfABzWEvNZJ0=; b=t80+e9rmyqeVgbgoG6NHCsyJlro+cNa0wrhiBEWAJ/jW1Y8VUklW/dGHvew7w0/X4v jJSN6ADxEZulfc262Bfi/XubBboLS/c8KOcZr2YAEB5EwIsyq5qXmdgwjNVfJVh03stT CuZmr/slcIuE3jHYuHRclQjq0wdkLeupuXrq9o+CZE0AXvodeo/Bmbhf/Ni6Sm/Yjai3 U6S8udHmMfAmYn258cD66VGHymgtRpbfoC+dNsi6omWciuLyYLbpvYjkiPQah2Q4Hkul ihxcHtSOtR1Eh3WY0Yy7Bj7gGjASwt8zxPQDg61PDOKvqg6YfLNwmZF4S68NgQTjNMVp gauA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=+xa+qOHl6vSbHtQE/NlGKdhQOOxh23wLfABzWEvNZJ0=; b=Rv+R08SMsDnMBuswpsP99Kyy246PfPLSR8FrLXnN9yRPAbcC9ND4HiVTzL8bX4NSOM mPN7VEwgqMF4g6BXkkeT8P0XKBtm2+7NyTz8yFOHvNZO9ClK3dF9hJv6rabmI0Syhk4R lkEaN10SHz42QPbsGeCH0Lnt69GeTm1/HG9itkjdSlvUuacjjAS6ucMbW2bxb9kPXHJl hDPJLxq+4nqImgsqosChyl84qGh/Ske9Syhs/qAn4OZI0JcAXX4fgTEN1N+uEe38LKfJ DEngoS8gLc0SuzYoQkgLsxI3koSBklOdP7Kx/BsZIg31NTwV1Vw0cmMkK9QQ3VpIMPcw QM9Q== X-Gm-Message-State: APjAAAVpQAxiq9rzi+Jcngyzwmo1k7sN/rOYOZhT0VdSiITh0PnVgopy 4ETAZ6O1d7UZVllkCgPYhzpcSxtNAzU= X-Google-Smtp-Source: APXvYqzcw/EA36kHbTKo0Nk/ysetePfYGaPZ4iwDH5KZq567H5ErN14ae3fEXbZg4jnl9mG/r5CHrw== X-Received: by 2002:a5d:6548:: with SMTP id z8mr25677729wrv.273.1574550868462; Sat, 23 Nov 2019 15:14:28 -0800 (PST) Original-Received: from lead (ip5f5bd750.dynamic.kabel-deutschland.de. [95.91.215.80]) by smtp.gmail.com with ESMTPSA id 2sm3709933wrq.31.2019.11.23.15.14.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Nov 2019 15:14:27 -0800 (PST) In-Reply-To: <874kyu72kl.fsf@gmail.com> (Federico Tedin's message of "Sat, 23 Nov 2019 21:36:10 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:172353 Archived-At: --=-=-= Content-Type: text/plain > So although `read_minibuf' does call `add-to-history' before returning > (and after setting the current buffer to be the minibuffer's), my input > wasn't added to any list (that I know of). This is strange, since > `add-to-history' seemed to work correctly with buffer-local variables > when I tested it separately. I would've expected the new history item to > be added to one of the minibuffer's `test-history' local variable. > > So I think the first step would be to make `read_minibuf' add the new > history item into the right place when HIST is buffer-local. Turns out `get_minibuffer' sets the minibuffer's buffer mode to `minibuffer-inactive-mode', which resets the minibuffer's local variables (though not 100% sure about this). I think the history items were being added to the minibuffer's local version of the variable, and then being deleted by that. I created a small patch that sets back the original buffer at the end of `read_minibuf', so that the history item is added in the right place. Then, I modified `goto-history-element' as Michael suggested, so that the function reads the buffer-local version of the variable, but not the minibuffer's (and updated `minibuffer-history-isearch-wrap' just in case as well). With this, M-p and M-n works again. I'm attaching a draft patch in case anyone wants to provide some feedback. Thanks! - Fede --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=minibuf.diff Content-Description: patch diff --git a/lisp/simple.el b/lisp/simple.el index c61ccd511c..e5f9e9e785 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2028,7 +2028,7 @@ previous-matching-history-element (null minibuffer-text-before-history)) (setq minibuffer-text-before-history (minibuffer-contents-no-properties))) - (let ((history (symbol-value minibuffer-history-variable)) + (let ((history (minibuffer-history-values)) (case-fold-search (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped ;; On some systems, ignore case for file names. @@ -2128,6 +2128,14 @@ minibuffer-default-add-completions (append def all) (cons def (delete def all))))) +(defun minibuffer-history-values () + "Return the minibuffer input history values. +If `minibuffer-history-variable' points to a buffer-local variable and +the minibuffer is active, return the buffer-local value for the buffer +selected in the window returned by `minibuffer-selected-window'." + (buffer-local-value minibuffer-history-variable + (window-buffer (minibuffer-selected-window)))) + (defun goto-history-element (nabs) "Puts element of the minibuffer history in the minibuffer. The argument NABS specifies the absolute history position in @@ -2156,8 +2164,8 @@ goto-history-element (user-error (if minibuffer-default "End of defaults; no next item" "End of history; no default available"))) - (if (> nabs (if (listp (symbol-value minibuffer-history-variable)) - (length (symbol-value minibuffer-history-variable)) + (if (> nabs (if (listp (minibuffer-history-values)) + (length (minibuffer-history-values)) 0)) (user-error "Beginning of history; no preceding item")) (unless (memq last-command '(next-history-element @@ -2179,7 +2187,7 @@ goto-history-element (setq minibuffer-returned-to-present t) (setq minibuffer-text-before-history nil)) (t (setq elt (nth (1- minibuffer-history-position) - (symbol-value minibuffer-history-variable))))) + (minibuffer-history-values))))) (insert (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth)) (not minibuffer-returned-to-present)) @@ -2432,7 +2440,7 @@ minibuffer-history-isearch-wrap ;; beginning/end of the history, wrap the search to the first/last ;; minibuffer history element. (if isearch-forward - (goto-history-element (length (symbol-value minibuffer-history-variable))) + (goto-history-element (length (minibuffer-history-values))) (goto-history-element 0)) (setq isearch-success t) (goto-char (if isearch-forward (minibuffer-prompt-end) (point-max)))) diff --git a/src/minibuf.c b/src/minibuf.c index 1e87c5044a..c4d2fae9b4 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -353,7 +353,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt, bool allow_props, bool inherit_input_method) { - Lisp_Object val; + Lisp_Object val, previous_buffer = Fcurrent_buffer (); ptrdiff_t count = SPECPDL_INDEX (); Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; Lisp_Object enable_multibyte; @@ -696,7 +696,12 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, else histstring = Qnil; - /* Add the value to the appropriate history list, if any. */ + /* Add the value to the appropriate history list, if any. If + possible, switch back to the previous buffer first, in case the + history variable was buffer-local. */ + if (BUFFER_LIVE_P (XBUFFER (previous_buffer))) + Fset_buffer (previous_buffer); + if (! (NILP (Vhistory_add_new_input) || NILP (histstring))) call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring); --=-=-=--