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: Thu, 28 Nov 2019 13:05:40 +0100 Message-ID: <874kyow6i3.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> <87wobq5gs0.fsf@gmail.com> <87o8wyl2wa.fsf@gmail.com> <87k17lfscs.fsf@gnus.org> <87h82pw3vr.fsf@gmail.com> <83y2w1p1f7.fsf@gnu.org> <87d0ddvxnk.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="214525"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: larsi@gnus.org To: 38317@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 28 13:07:26 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 1iaIZx-000tfk-Fi for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Nov 2019 13:07:25 +0100 Original-Received: from localhost ([::1]:48298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaIZv-0004VC-QQ for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Nov 2019 07:07:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52279) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iaIYi-0003zQ-4A for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2019 07:06:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iaIYd-0003BI-E6 for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2019 07:06:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50813) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iaIYd-0003Ab-8d for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2019 07:06:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iaIYc-0005QG-3v for bug-gnu-emacs@gnu.org; Thu, 28 Nov 2019 07:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Nov 2019 12:06: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.157494275220829 (code B ref 38317); Thu, 28 Nov 2019 12:06:02 +0000 Original-Received: (at 38317) by debbugs.gnu.org; 28 Nov 2019 12:05:52 +0000 Original-Received: from localhost ([127.0.0.1]:56786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iaIYR-0005Ps-TO for submit@debbugs.gnu.org; Thu, 28 Nov 2019 07:05:52 -0500 Original-Received: from mail-wm1-f54.google.com ([209.85.128.54]:38593) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iaIYP-0005Pe-Mb for 38317@debbugs.gnu.org; Thu, 28 Nov 2019 07:05:50 -0500 Original-Received: by mail-wm1-f54.google.com with SMTP id z19so11432941wmk.3 for <38317@debbugs.gnu.org>; Thu, 28 Nov 2019 04:05:49 -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=NjrhGaosaPVGHaPtved6wZWN3RBxQDe0I2togm4OizE=; b=bpwx6MY2BqC2yCF9W4OTVIB0XrrwpG7yly1GJe0o0G0NV9PK2Ej1kt6Fc0zh1KdxI7 KuHyjyVXcr8XshrFIZcSR1EQsxs68y7QrDZ1GHVomlSPzmcfFFF4xRSuzq0TrgCDKYr7 3pujQRNrwvm+pVmTlchD4DOgQf22+qIbCO4js37ENAqkEVX1It7AxxyYCE3kchP95QU0 g1qj4N3ifGXXsiMl5Jq0gk1lM6za65VQthxE7PjeXk0Jp509apPlu9BQBjiCgUShKPSB 8SheAe0g4ZnAnyg+WoIIH9Y7Jr1JBJ38qpqfq0WOw1gjTM9tAFajLQ/pJLyx+ouCahzS 6Xyg== 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=NjrhGaosaPVGHaPtved6wZWN3RBxQDe0I2togm4OizE=; b=eW+ZHyDy0a7XkgfQaH4YINOCdI4RENLGd5bf5M8W3QvXu8EQLtiZIhXLkD9tndQn3q sFEPcudJC8Cb2e1ynT6Kdr++FPAoAOUqh050+I9i+Mw9wXwdQCpEc1b2LTfUr4c5FYpu E/ZME0oE7Co556NLW4v8Z0skNg+lj3KdCGqUpCTXq5Ez/wemW/tXt0YTqK/1n3bd2xNl 3m6jppAQLm4My/9FAgGH25S4jkqHrAvXFwGQEG8O39hcyDv0Mcc38IXsb7anlg/Zv24b QIma0r3KrvlNY00t/a8zqe5RAUyC34b4UgzAAOOkvvy8uM0A40BQyTBhHakbgnzMBtnc BNLQ== X-Gm-Message-State: APjAAAXrTa6qRwebajRGrRcK26RdE5F9XBv2DfGqjD3U5k2jbkiuNJRO MgaeRW2bW+fG0MPFz3E66Zc= X-Google-Smtp-Source: APXvYqyOA3zhPBLDEy/vA50mKcRgcbBZYEyF9BRFAU36BTq8wXtKJ9JRlA0zdGUExYvHwNcw02hsGA== X-Received: by 2002:a1c:ca:: with SMTP id 193mr9174638wma.111.1574942742900; Thu, 28 Nov 2019 04:05:42 -0800 (PST) Original-Received: from lead ([2a02:8109:8ac0:2ff0:918e:a083:2c78:74e5]) by smtp.gmail.com with ESMTPSA id t16sm10699318wmt.38.2019.11.28.04.05.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Nov 2019 04:05:41 -0800 (PST) In-Reply-To: <87d0ddvxnk.fsf@gmail.com> (Federico Tedin's message of "Wed, 27 Nov 2019 22:04:31 +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:172595 Archived-At: --=-=-= Content-Type: text/plain I'm now attaching a new patch with feedback corrections from everyone in the thread (threads?). --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=minibuffer.patch Content-Description: patch >From 481f85d70463207c5ca5c43c287f1edcc6ed288e Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Thu, 28 Nov 2019 12:59:52 +0100 Subject: [PATCH 1/1] Make HIST arg of read-from-minibuffer work with buffer-local vars * lisp/simple.el (minibuffer-history-values): New function, should be used to access the minibuffer input history variable when the minibuffer might be active. If the variable is buffer-local, the previous buffer's value will be used. (goto-history-element): Use the new function to access the minibuffer history. (minibuffer-history-isearch-wrap): Use the new function to access the minibuffer history. * src/minibuf.c (read_minibuf): Switch to previous buffer temporarily before updating history list (Bug#38317). (read-from-minibuffer): Extend documentation to mention that the result of using the command will be added to the history list by default. * doc/lispref/minibuf.texi (Minibuffer History): Mention the possibility of using a buffer-local variable as history. * etc/NEWS: Announce changes. --- doc/lispref/minibuf.texi | 3 ++- etc/NEWS | 6 ++++++ lisp/simple.el | 18 +++++++++++++----- src/minibuf.c | 20 ++++++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 4a218fe737..dde30ce67f 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -547,7 +547,8 @@ Minibuffer History If you don't specify @var{history}, then the default history list @code{minibuffer-history} is used. For other standard history lists, see below. You can also create your own history list variable; just -initialize it to @code{nil} before the first use. +initialize it to @code{nil} before the first use. If the variable is +buffer local, then each buffer will have its own input history list. Both @code{read-from-minibuffer} and @code{completing-read} add new elements to the history list automatically, and provide commands to diff --git a/etc/NEWS b/etc/NEWS index cb73e46358..bc088129f8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -522,6 +522,12 @@ Note that this key binding will not work on MS-Windows systems if key binding with an upper case letter - if you can type it, you can bind it. ++++ +** 'read-from-minibuffer' now works with buffer-local history variables. +The HIST argument of 'read-from-minibuffer' now works correctly with +buffer-local variables. This means that different buffers can have +their own separated input history list if desired. + * Editing Changes in Emacs 27.1 diff --git a/lisp/simple.el b/lisp/simple.el index 2aac557154..ef36ff9f8a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2041,7 +2041,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-value)) (case-fold-search (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped ;; On some systems, ignore case for file names. @@ -2141,6 +2141,14 @@ minibuffer-default-add-completions (append def all) (cons def (delete def all))))) +(defun minibuffer-history-value () + "Return the value of the minibuffer input history list. +If `minibuffer-history-variable' points to a buffer-local variable and +the minibuffer is active, return the buffer-local value for the buffer +that was current when the minibuffer was activated." + (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 @@ -2169,8 +2177,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-value)) + (length (minibuffer-history-value)) 0)) (user-error "Beginning of history; no preceding item")) (unless (memq last-command '(next-history-element @@ -2192,7 +2200,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-value))))) (insert (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth)) (not minibuffer-returned-to-present)) @@ -2445,7 +2453,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-value))) (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..bdae01dbc5 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; @@ -698,7 +698,20 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, /* Add the value to the appropriate history list, if any. */ if (! (NILP (Vhistory_add_new_input) || NILP (histstring))) - call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring); + { + ptrdiff_t count2 = SPECPDL_INDEX (); + + /* If possible, switch back to the previous buffer first, in + case the history variable is buffer-local. */ + if (BUFFER_LIVE_P (XBUFFER (previous_buffer))) + { + record_unwind_current_buffer (); + Fset_buffer (previous_buffer); + } + + call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring); + unbind_to (count2, Qnil); + } /* If Lisp form desired instead of string, parse it. */ if (expflag) @@ -879,6 +892,9 @@ Fifth arg HIST, if non-nil, specifies a history list and optionally starting from 1 at the beginning of the list. If HIST is the symbol `t', history is not recorded. + If `history-add-new-input' is non-nil (the default), the result will + be added to the history list using `add-to-history'. + Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used as the default to `read' if READ is non-nil and the user enters empty input. But if READ is nil, this function does _not_ return -- 2.17.1 --=-=-=--