From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs,gmane.emacs.erc.general Subject: bug#46339: 28.0.50; ERC likely bug with `erc-previous-command' Date: Mon, 08 Feb 2021 03:07:37 -0800 Message-ID: <87wnvivmva.fsf@neverwas.me> References: <87im75u2cu.fsf@zoho.eu> Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10000"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: emacs-erc@gnu.org To: 46339@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 08 18:37:06 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 1l9ATC-0002RN-OU for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Feb 2021 18:37:06 +0100 Original-Received: from localhost ([::1]:37984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9ATA-0001mx-Rd for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Feb 2021 12:37:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l94Pp-0003Vc-KQ for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 06:09:20 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l94Pd-00041q-Nz for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 06:09:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l94Pd-0001ZL-Jn for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 06:09:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 08 Feb 2021 11:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46339 X-GNU-PR-Package: emacs Original-Received: via spool by 46339-submit@debbugs.gnu.org id=B46339.16127824815949 (code B ref 46339); Mon, 08 Feb 2021 11:09:01 +0000 Original-Received: (at 46339) by debbugs.gnu.org; 8 Feb 2021 11:08:01 +0000 Original-Received: from localhost ([127.0.0.1]:49934 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l94OW-0001XZ-Iv for submit@debbugs.gnu.org; Mon, 08 Feb 2021 06:08:01 -0500 Original-Received: from dal3relay173.mxroute.com ([64.40.27.173]:38097) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l94OU-0001XM-QN for 46339@debbugs.gnu.org; Mon, 08 Feb 2021 06:07:51 -0500 Original-Received: from filter004.mxroute.com ([149.28.56.236] 149.28.56.236.vultr.com) (Authenticated sender: mN4UYu2MZsgR) by dal3relay173.mxroute.com (ZoneMTA) with ESMTPSA id 17781535d0c0008aa5.001 for <46339@debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Mon, 08 Feb 2021 11:07:40 +0000 X-Zone-Loop: 29f3d167828ebed1a00a489aa160211a360c4854022a X-Originating-IP: [149.28.56.236] In-Reply-To: <87im75u2cu.fsf@zoho.eu> (Emanuel Berg's message of "Sat, 06 Feb 2021 07:39:13 +0100") X-AuthUser: masked@neverwas.me 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:199606 gmane.emacs.erc.general:1504 Archived-At: --=-=-= Content-Type: text/plain Emanuel Berg writes: > what does that mean? `erc-next-command' works so a bug is > perhaps likely. I think it's expecting an erc-input struct object, as passed by the hook erc-pre-send-functions. Would something like the following work? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Accept-string-argument-in-erc-add-to-input-ring.patch >From a805a4e507e19eb6c68fdd57ea7d8972b270aeb9 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 8 Feb 2021 02:34:18 -0800 Subject: [PATCH] Accept string argument in erc-add-to-input-ring * lisp/erc/erc-ring.el: (erc-add-to-input-ring) (erc-previous-command): Use existing API to grab input. * test/lisp/erc/erc-tests.el: (erc-ring-previous-command) See (bug#46339). --- lisp/erc/erc-ring.el | 18 ++++++----- test/lisp/erc/erc-tests.el | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el index 71a9f8ef3da..028ab1eead8 100644 --- a/lisp/erc/erc-ring.el +++ b/lisp/erc/erc-ring.el @@ -69,10 +69,13 @@ erc-input-ring-setup (setq erc-input-ring (make-ring comint-input-ring-size))) (setq erc-input-ring-index nil)) -(defun erc-add-to-input-ring (state) - "Add string S to the input ring and reset history position." +(defun erc-add-to-input-ring (state-or-string) + "Add STATE-OR-STRING to input ring and reset history position. +STATE-OR-STRING should be a string or an erc-input object." (unless erc-input-ring (erc-input-ring-setup)) - (ring-insert erc-input-ring (erc-input-string state)) + (ring-insert erc-input-ring (if (erc-input-p state-or-string) + (erc-input-string state-or-string) + state-or-string)) ; string (setq erc-input-ring-index nil)) (defun erc-clear-input-ring () @@ -101,11 +104,10 @@ erc-previous-command ;; area, push it on the history ring before moving back through ;; the input history, so it will be there when we return to the ;; front. - (if (null erc-input-ring-index) - (when (> (point-max) erc-input-marker) - (erc-add-to-input-ring (buffer-substring erc-input-marker - (point-max))) - (setq erc-input-ring-index 0))) + (when (and (null erc-input-ring-index) + (> (point-max) erc-input-marker)) + (erc-add-to-input-ring (erc-user-input)) + (setq erc-input-ring-index 0)) (setq erc-input-ring-index (if erc-input-ring-index (ring-plus1 erc-input-ring-index diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 26e14b98e91..d13397274aa 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -23,6 +23,7 @@ (require 'ert) (require 'erc) +(require 'erc-ring) (ert-deftest erc--read-time-period () (cl-letf (((symbol-function 'read-string) (lambda (&rest _) ""))) @@ -45,3 +46,66 @@ erc--read-time-period (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d"))) (should (equal (erc--read-time-period "foo: ") 86400)))) + +(ert-deftest erc-ring-previous-command-base-case () + (ert-info ("Create ring when nonexistent and do nothing") + (let (erc-input-ring + erc-input-ring-index) + (erc-previous-command) + (should (ring-p erc-input-ring)) + (should (zerop (ring-length erc-input-ring))) + (should-not erc-input-ring-index))) + (should-not erc-input-ring)) + +(ert-deftest erc-ring-previous-command () + (with-current-buffer (get-buffer-create "*#fake*") + (erc-mode) + (insert "\n\n") + (setq erc-input-marker (make-marker) ; these are all local + erc-insert-marker (make-marker) + erc-send-completed-hook nil) + (set-marker erc-insert-marker (point-max)) + (erc-display-prompt) + (should (= (point) erc-input-marker)) + (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring nil t) + ;; + (cl-letf (((symbol-function 'erc-process-input-line) + (lambda (&rest _) + (insert-before-markers + (erc-display-message-highlight 'notice "echo: one\n")))) + ((symbol-function 'erc-command-no-process-p) + (lambda (&rest _) t))) + (ert-info ("Create ring, populate, recall") + (insert "/one") + (erc-send-current-line) + (should (ring-p erc-input-ring)) + (should (zerop (ring-member erc-input-ring "/one"))) ; equal + (should (save-excursion (forward-line -1) (goto-char (point-at-bol)) + (looking-at-p "[*]+ echo: one"))) + (should-not erc-input-ring-index) + (erc-bol) + (should (looking-at "$")) + (erc-previous-command) + (erc-bol) + (should (looking-at "/one")) + (should (zerop erc-input-ring-index))) + (ert-info ("Back to one") + (should (= (ring-length erc-input-ring) (1+ erc-input-ring-index))) + (erc-previous-command) + (should-not erc-input-ring-index) + (erc-bol) + (should (looking-at "$")) + (should (equal (ring-ref erc-input-ring 0) "/one"))) + (ert-info ("Swap input after prompt with previous (#bug46339)") + (insert "abc") + (erc-previous-command) + (should (= 1 erc-input-ring-index)) + (erc-bol) + (should (looking-at "/one")) + (should (equal (ring-ref erc-input-ring 0) "abc")) + (should (equal (ring-ref erc-input-ring 1) "/one")) + (erc-next-command) + (erc-bol) + (should (looking-at "abc"))))) + (when noninteractive + (kill-buffer "*#fake*"))) -- 2.29.2 --=-=-=--