From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Brian Leung via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#45606: [PATCH] Modify comint-read-input-ring to skip uninteresting text Date: Sat, 2 Jan 2021 04:56:54 +0100 (CET) Message-ID: <172138729.342110.1609559814855@ichabod.co-bxl> Reply-To: Brian Leung , Brian Leung Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_341911_1541531884.1609559446264" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38853"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mjbauer95@gmail.com To: 45606@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 02 04:58:13 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kvY3Q-0009yB-8K for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jan 2021 04:58:12 +0100 Original-Received: from localhost ([::1]:51328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kvY3O-0001S7-Pg for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Jan 2021 22:58:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvY3H-0001Rr-22 for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 22:58:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kvY3G-00023C-RP for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 22:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kvY3G-0002Zh-QW for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 22:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Brian Leung Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Jan 2021 03:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45606 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Bug Gnu Emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.16095598279727 (code B ref -1); Sat, 02 Jan 2021 03:58:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Jan 2021 03:57:07 +0000 Original-Received: from localhost ([127.0.0.1]:35155 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kvY2M-0002Wo-M2 for submit@debbugs.gnu.org; Fri, 01 Jan 2021 22:57:07 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:45466) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kvY2L-0002Wg-AK for submit@debbugs.gnu.org; Fri, 01 Jan 2021 22:57:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvY2K-0001Pp-Vj for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 22:57:04 -0500 Original-Received: from wilbur.contactoffice.com ([212.3.242.68]:43964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvY2I-0001Zk-5u for bug-gnu-emacs@gnu.org; Fri, 01 Jan 2021 22:57:04 -0500 Original-Received: from ichabod.co-bxl (ichabod.co-bxl [10.2.0.36]) by wilbur.contactoffice.com (Postfix) with ESMTP id 903567B4; Sat, 2 Jan 2021 04:56:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailfence.com; s=20160819-nLV10XS2; t=1609559817; bh=y2Zp1/aPVRmChCqEaUjHMW91Ccj6wiUcAI8S9U3DaKc=; h=Date:Subject:Reply-To:From:To:Cc:From; b=bscIbCuKwbJUQd/2gkU9sqJnlNilxhsTXDSA3HHUV2BC6+P9958SORcylGyXFKjaG PGA6i/E3F2UsEdPFInqBjeIceLMwVEMHMNY8lNzwKhTAAF4Wm3g/FVmJlTIBsyGBGV 9ejbofyrTG8QFVrURD5g6woWlBMUfFqLja/D7BTP968osZOEOAdKTK8izf/mSdKhzo lYU4B0Ry/4JifxNfFm23psexUA0RLhQ6tpdmQf0T/IQb8l/qIBxoQyhNt/EB+8+yht 29VzXbIWL0fk0QYc2/DkoBoBgc2XZ+H2jrxrbFsq9mnRqTXwraIVHsKxnorYqYcEe0 V8gP1sj1letMA== X-Priority: 3 X-Mailer: ContactOffice Mail X-ContactOffice-Account: com:225491745 Received-SPF: pass client-ip=212.3.242.68; envelope-from=leungbk@mailfence.com; helo=wilbur.contactoffice.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197161 Archived-At: ------=_Part_341911_1541531884.1609559446264 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I made the attached changes to handle zsh's history on Emacs' master branch= . This is a follow-up to Matthew Bauer's commit f7421039fb15123dbbda047e23504= dd1771183b5 which sought to support zsh's extended_history. Matthew, would = you confirm that these patches are OK? Thanks, Brian --=C2=A0 Sent with https://mailfence.com Secure and private email ------=_Part_341911_1541531884.1609559446264 Content-Type: text/x-diff; charset=us-ascii; name=0001-shell-mode-use-.zsh_history-as-a-history-file.patch Content-Transfer-Encoding: 7bit Content-Description: File Attachment: 0001-shell-mode-use-.zsh_history-as-a-history-file.patch Content-Disposition: attachment; filename=0001-shell-mode-use-.zsh_history-as-a-history-file.patch >From 258a325eb90cc516231714fb329a0ad876ea537f Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Fri, 1 Jan 2021 18:56:41 -0800 Subject: [PATCH 1/4] shell-mode: use "~/.zsh_history" as a history file * lisp/shell.el (shell-mode): Add "~/.zsh_history". --- lisp/shell.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/shell.el b/lisp/shell.el index c179dd24d3..0f866158fe 100644 --- a/lisp/shell.el +++ b/lisp/shell.el @@ -603,6 +603,7 @@ shell-mode (or hfile (cond ((string-equal shell "bash") "~/.bash_history") ((string-equal shell "ksh") "~/.sh_history") + ((string-equal shell "zsh") "~/.zsh_history") (t "~/.history"))))) (if (or (equal comint-input-ring-file-name "") (equal (file-truename comint-input-ring-file-name) -- 2.29.2 ------=_Part_341911_1541531884.1609559446264 Content-Type: text/x-diff; charset=us-ascii; name=0002-comint-read-input-ring-Use-comint-buffer-s-ring-file.patch Content-Transfer-Encoding: 7bit Content-Description: File Attachment: 0002-comint-read-input-ring-Use-comint-buffer-s-ring-file.patch Content-Disposition: attachment; filename=0002-comint-read-input-ring-Use-comint-buffer-s-ring-file.patch >From 5a6418f693bd71c3dc0cb398209b769c45e59f30 Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Fri, 1 Jan 2021 18:58:26 -0800 Subject: [PATCH 2/4] comint-read-input-ring: Use comint buffer's ring-file-prefix * lisp/comint.el (comint-read-input-ring): Bind `comint-input-ring-file-prefix' in anticipation of a buffer switch. --- lisp/comint.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 2e683a7572..f92b7b4a7b 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -979,6 +979,7 @@ comint-read-input-ring (ring (make-ring ring-size)) ;; Use possibly buffer-local values of these variables. (ring-separator comint-input-ring-separator) + (ring-file-prefix comint-input-ring-file-prefix) (history-ignore comint-input-history-ignore) (ignoredups comint-input-ignoredups)) (with-temp-buffer @@ -993,17 +994,17 @@ comint-read-input-ring (setq start (if (re-search-backward ring-separator nil t) (progn - (when (and comint-input-ring-file-prefix + (when (and ring-file-prefix (looking-at - comint-input-ring-file-prefix)) + ring-file-prefix)) ;; Skip zsh extended_history stamps (goto-char (match-end 0))) (match-end 0)) (progn (goto-char (point-min)) - (when (and comint-input-ring-file-prefix + (when (and ring-file-prefix (looking-at - comint-input-ring-file-prefix)) + ring-file-prefix)) (goto-char (match-end 0))) (point)))) (setq history (buffer-substring start end)) -- 2.29.2 ------=_Part_341911_1541531884.1609559446264 Content-Type: text/x-diff; charset=us-ascii; name=0003-comint-read-input-ring-skip-over-the-comint-input-ri.patch Content-Transfer-Encoding: 7bit Content-Description: File Attachment: 0003-comint-read-input-ring-skip-over-the-comint-input-ri.patch Content-Disposition: attachment; filename=0003-comint-read-input-ring-skip-over-the-comint-input-ri.patch >From 601431c612b1585cbf32f18d4de6287b83cfbdf2 Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Fri, 1 Jan 2021 19:04:27 -0800 Subject: [PATCH 3/4] comint-read-input-ring: skip over the comint-input-ring-separator * lisp/comint.el (comint-read-input-ring): Skip the separator. Because re-search-backward moves point to the beginning of the match, and since we don't want the separator appearing in the output, we skip over it. This is required to properly detect instances of the value that zsh uses for `comint-input-ring-file-prefix'; if the `comint-input-ring-file-prefix' is ':potato', the subsequent invocation `looking-at' sees '\n:potato' for all entries after the one at the very beginning of the history file. --- lisp/comint.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/comint.el b/lisp/comint.el index f92b7b4a7b..36fcbb9465 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -994,6 +994,7 @@ comint-read-input-ring (setq start (if (re-search-backward ring-separator nil t) (progn + (goto-char (match-end 0)) (when (and ring-file-prefix (looking-at ring-file-prefix)) -- 2.29.2 ------=_Part_341911_1541531884.1609559446264 Content-Type: text/x-diff; charset=us-ascii; name=0004-comint-read-input-ring-Tidy.patch Content-Transfer-Encoding: 7bit Content-Description: File Attachment: 0004-comint-read-input-ring-Tidy.patch Content-Disposition: attachment; filename=0004-comint-read-input-ring-Tidy.patch >From 125025c407e6995dd9239a51997082cb898acf3b Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Fri, 1 Jan 2021 19:41:26 -0800 Subject: [PATCH 4/4] comint-read-input-ring: Tidy * lisp/comint.el (comint-read-input-ring): Simplify. --- lisp/comint.el | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 36fcbb9465..3476fd146c 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -991,23 +991,14 @@ comint-read-input-ring (while (and (< count comint-input-ring-size) (re-search-backward ring-separator nil t) (setq end (match-beginning 0))) - (setq start - (if (re-search-backward ring-separator nil t) - (progn - (goto-char (match-end 0)) - (when (and ring-file-prefix - (looking-at - ring-file-prefix)) - ;; Skip zsh extended_history stamps - (goto-char (match-end 0))) - (match-end 0)) - (progn - (goto-char (point-min)) - (when (and ring-file-prefix - (looking-at - ring-file-prefix)) - (goto-char (match-end 0))) - (point)))) + (goto-char (if (re-search-backward ring-separator nil t) + (match-end 0) + (point-min))) + (when (and ring-file-prefix + (looking-at ring-file-prefix)) + ;; Skip zsh extended_history stamps + (goto-char (match-end 0))) + (setq start (point)) (setq history (buffer-substring start end)) (goto-char start) (when (and (not (string-match history-ignore history)) -- 2.29.2 ------=_Part_341911_1541531884.1609559446264--