From unknown Thu Aug 14 21:57:09 2025 X-Loop: help-debbugs@gnu.org Subject: bug#77989: [PATCH] Use future history to select current script for pdb et al Resent-From: "Paul D. Nelson" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Apr 2025 15:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 77989 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 77989@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.174533411031554 (code B ref -1); Tue, 22 Apr 2025 15:02:01 +0000 Received: (at submit) by debbugs.gnu.org; 22 Apr 2025 15:01:50 +0000 Received: from localhost ([127.0.0.1]:49305 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u7F89-0008Cr-Qt for submit@debbugs.gnu.org; Tue, 22 Apr 2025 11:01:50 -0400 Received: from lists.gnu.org ([2001:470:142::17]:42354) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u7F86-0008Cb-1r for submit@debbugs.gnu.org; Tue, 22 Apr 2025 11:01:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u7F7r-0002Ku-SH for bug-gnu-emacs@gnu.org; Tue, 22 Apr 2025 11:01:33 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u7F7m-0005n1-0o for bug-gnu-emacs@gnu.org; Tue, 22 Apr 2025 11:01:31 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-ac2902f7c2aso804240366b.1 for ; Tue, 22 Apr 2025 08:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745334081; x=1745938881; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=pEvW3mcmYuKCqb3rmD/WXm6LIXYPoGdwnUO0n7I8qHg=; b=WIv8I4+u7q2eFyMQp3uK/CwStJkZppn+RdSdU3h6ftvY+eDilfNWWgdQ2MIR7yo2nw g9qr+aeX7RMDdhRauZP2t+1PYx8lEsTekm1csa5Fx+c/ij2zTdhaNEMYvvdEfTkgh6iD 9G9D59BXPW0cNDOdaR9l/Ms+rep5hQbA4qp0GktGlTwafsuVVlOYnlVCYtS6uWCE5lUV zJ3CZETo79RCL7tX4cYw8tCLURLsFA8ouuLG5sXV2UGHEXvIJDnXH2VKg0gqdYJVS1m+ f+VAklaUi6aUSEnQzPQi4WWCXu38gS1GgeyB6ihKAK+HLGt6Ve/55FKhzb1Y/uS8NCQ1 jwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745334081; x=1745938881; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pEvW3mcmYuKCqb3rmD/WXm6LIXYPoGdwnUO0n7I8qHg=; b=RIK2V3SVLdbJINPvTDpoAwLU+zqHbPCzmATyDN4+0qVQo6LnjBT7Q/NHXc1xfRIk0o 9PPKn7X5UynNIQez4kBG3+tu5gmV9eisGBAboGGpABSfT1xosr4oUTMPEKSSYERA1aNh 45LnFyv4RD2s7duZDWfSp5pX1TRrzR7HuyYmBxnHvBe+JXr3j/Osgp/pnj+JWFrWDHs7 xkF/4IlCl5lLTF7C1hH74XQl32EMvxKjQ1NrbjNW1qBi2c+wbejqvICvKrm5IKSS44dn prZVxwRuCEC+NOl9Shk4P88Ouad9icrzXUIDdfb1P4Lbw1wsDG3Flw2h4eKyb8WF1a28 lneg== X-Gm-Message-State: AOJu0YwmtMLthLBU4ZFJ/ymG7jVx2TGwOvan38nXf/fvJpp1qDetTJey wsVkB/tOGp5MEgxocmHit1UDUumz8IT0yB7LL9/aF9w+c+9mC8VBV+osrqlu X-Gm-Gg: ASbGncs6aKCqsZf2MMqaHo9wQW+SN84P75teY8CmK+cQz1fpYyZcZFyw6Sltn/YsAE6 7Czkvs7+IhTS+y8NUV4WSLCbKlZ2CC1yUv7Z+ys324RO9hL/4L+NxVZd5tOsrMorhhIDJ68K7C8 aM8N5F28uuwvuvDHT5lQc45mjFOPlG0558gLXrnDA4fak1aOKg9FZ9auPFY5zqY1oI3HXZ22nq5 j68uGmT7xBw4KpTqmnOAZTItnysy6QIPM0m/IBdULFnngfN0BIbed140ozZCUrtaa5qQTVH+MKj HX1USALDSyfL361end6emTh4Hg+sU+gyX3TSuGnoAALO X-Google-Smtp-Source: AGHT+IEBNzh/JqE83x4VgTYIWHi4zuSlhBJZfQmpWCBU0uWjf7prtY/sGFFuoadIYh6lV7BGDguIQQ== X-Received: by 2002:a17:907:7255:b0:acb:33ba:2889 with SMTP id a640c23a62f3a-acb74dd0838mr1420441666b.41.1745334081102; Tue, 22 Apr 2025 08:01:21 -0700 (PDT) Received: from localhost ([130.225.21.26]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-acb6ec4c6b5sm656187966b.49.2025.04.22.08.01.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 08:01:20 -0700 (PDT) From: "Paul D. Nelson" Date: Tue, 22 Apr 2025 17:01:18 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=ultrono@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain The simplest way I know to debug the current Python script is: 1. Copy the name of the current file (C-x C-j C-0 w) 2. M-x pdb RET yank RET (possibly after deleting previous file name) This seems like a good place to introduce a "future history" operation. The attached patch does so, via a new optional argument to gud-query-cmdline. The above then simplifies to M-x pdb RET M-n RET. Existing behavior is unchanged. I added the same feature to other gdb commands for which it seemed to make sense (perldb, guiler). Feedback or other suggestions would be welcome. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-forward-history-support-for-some-debuggers.patch >From 81382b69b83298d5bc098cc49f373d57a0909b42 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Mon, 21 Apr 2025 22:14:53 +0200 Subject: [PATCH] Add "forward history" support for some debuggers * lisp/progmodes/gud.el (gud-query-cmdline): Add an optional default-list parameter to allow passing a list of "forward history" suggestions to the minibuffer. (perldb, pdb, guiler): Use buffer file name to suggest a default debugging command via "forward history". * doc/emacs/building.texi (Starting GUD): Document the new feature. --- doc/emacs/building.texi | 3 +++ etc/NEWS | 8 ++++++++ lisp/progmodes/gud.el | 31 +++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index 02ca71f069b..39c5e79a870 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -674,6 +674,9 @@ Starting GUD using the minibuffer. The minibuffer's initial contents contain the standard executable name and options for the debugger, and sometimes also a guess for the name of the executable file you want to debug. +For @code{pdb}, @code{perldb}, and @code{guiler}, if the current buffer +visits a file, pressing @kbd{M-n} (@code{next-history-element}) +in the prompt suggests a full command line including that file name. Shell wildcards and variables are not allowed in this command line. Emacs assumes that the first command argument which does not start with a @samp{-} is the executable file name. diff --git a/etc/NEWS b/etc/NEWS index 56a45068daf..3519bc928ff 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1940,6 +1940,14 @@ normal file name starts with "file:", you can disable the URI recognition by invoking 'sqlite-open' with the new optional argument DISABLE-URI non-nil. +** GUD + +--- +*** pdb, perldb, and guiler suggest debugging the current file via 'M-n'. +When starting these debuggers (e.g., 'M-x pdb') while visiting a file, +pressing 'M-n' in the command prompt suggests a command line including +the file name, using the minibuffer's "future history". + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 3cca55be3a7..7108673dddc 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -757,7 +757,11 @@ gud-minibuffer-local-map :parent minibuffer-local-map "C-i" #'comint-dynamic-complete-filename) -(defun gud-query-cmdline (minor-mode &optional init) +(defun gud-query-cmdline (minor-mode &optional init default-list) + "Prompt for a command to run the debugger. +MINOR-MODE is the name of the debugger to run. INIT is the initial +command, before any history is available. DEFAULT-LIST is a list of +default commands, accessible via \\[next-history-element]." (let* ((hist-sym (gud-symbol 'history nil minor-mode)) (cmd-name (gud-val 'command-name minor-mode))) (unless (boundp hist-sym) (set hist-sym nil)) @@ -780,7 +784,8 @@ gud-query-cmdline (setq file f))) file))))) gud-minibuffer-local-map nil - hist-sym))) + hist-sym + default-list))) (defvar gdb-first-prompt t) @@ -1671,8 +1676,13 @@ perldb The directory containing the perl program becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'perldb - (concat (or (buffer-file-name) "-E 0") " ")))) + (list + (gud-query-cmdline + 'perldb + (concat (or (buffer-file-name) "-E 0") " ") + (when-let* ((file (buffer-file-name))) + (list (concat gud-perldb-command-name " " + (shell-quote-argument file) " ")))))) (gud-common-init command-line 'gud-perldb-massage-args 'gud-perldb-marker-filter) @@ -1802,7 +1812,11 @@ pdb The directory containing this file becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'pdb))) + (list (gud-query-cmdline + 'pdb nil + (when-let* ((file (buffer-file-name))) + (list (concat gud-pdb-command-name " " + (shell-quote-argument file))))))) (gud-common-init command-line nil 'gud-pdb-marker-filter) (setq-local gud-minor-mode 'pdb) @@ -1889,7 +1903,12 @@ guiler The directory containing FILE becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'guiler))) + (list + (gud-query-cmdline + 'guiler nil + (when-let* ((file (buffer-file-name))) + (list (concat gud-guiler-command-name " " + (shell-quote-argument file))))))) (gud-common-init command-line nil 'gud-guiler-marker-filter) (setq-local gud-minor-mode 'guiler) -- 2.39.3 (Apple Git-145) --=-=-=-- From unknown Thu Aug 14 21:57:09 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: "Paul D. Nelson" Subject: bug#77989: closed (Re: bug#77989: [PATCH] Use future history to select current script for pdb et al) Message-ID: References: <86jz77t5vb.fsf@gnu.org> X-Gnu-PR-Message: they-closed 77989 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 77989@debbugs.gnu.org Date: Sat, 26 Apr 2025 13:23:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1745673783-1482-1" This is a multi-part message in MIME format... ------------=_1745673783-1482-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #77989: [PATCH] Use future history to select current script for pdb et al which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 77989@debbugs.gnu.org. --=20 77989: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D77989 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1745673783-1482-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 77989-done) by debbugs.gnu.org; 26 Apr 2025 13:22:29 +0000 Received: from localhost ([127.0.0.1]:59449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u8fUD-0000Ln-7g for submit@debbugs.gnu.org; Sat, 26 Apr 2025 09:22:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42170) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u8fU9-0000LC-OD for 77989-done@debbugs.gnu.org; Sat, 26 Apr 2025 09:22:26 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8fU3-0004Cm-6q; Sat, 26 Apr 2025 09:22:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=jUwZYEvTYttxulUcqcp6AWcvLhA3XB1Q7LfTvhUFo2s=; b=KIdR2bnjbIXP lu92Y/wzz3mjMZPEbm3lJch2orqTlJort8DSy2BFoQwnCrVDFnga56cH4xK16+/hTY3O8So7DakEz 2142X/aLqsFqBCnRqwaI2bQZv3dgsb065XeL0ewtD+8hHR+ewTXTrz5XcTZJM7na9eNXJgphSCBVq aSNcYyhSTGamCTWmj3XHl9+UpbDdlv2XHjhpWTORgJ3J2D+hQDSGm6s79UVHN1xkcUFzYNtmTefn/ n4o3KGvm3w6Z+uOdWSdLSCjAMX5+MeIBHKdya57LxAqNXIlhFMStO97Z8h1c4O80AedzDYvPHjWuw Q1uOmQSa+w9wEiwTT7zHow==; Date: Sat, 26 Apr 2025 16:22:16 +0300 Message-Id: <86jz77t5vb.fsf@gnu.org> From: Eli Zaretskii To: "Paul D. Nelson" In-Reply-To: (ultrono@gmail.com) Subject: Re: bug#77989: [PATCH] Use future history to select current script for pdb et al References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77989-done Cc: 77989-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: "Paul D. Nelson" > Date: Tue, 22 Apr 2025 17:01:18 +0200 > > The simplest way I know to debug the current Python script is: > > 1. Copy the name of the current file (C-x C-j C-0 w) > 2. M-x pdb RET yank RET (possibly after deleting previous file name) > > This seems like a good place to introduce a "future history" operation. > The attached patch does so, via a new optional argument to > gud-query-cmdline. The above then simplifies to M-x pdb RET M-n RET. > > Existing behavior is unchanged. I added the same feature to other gdb > commands for which it seemed to make sense (perldb, guiler). Feedback > or other suggestions would be welcome. Thanks, installed on the master branch, and closing the bug. ------------=_1745673783-1482-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 22 Apr 2025 15:01:50 +0000 Received: from localhost ([127.0.0.1]:49305 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u7F89-0008Cr-Qt for submit@debbugs.gnu.org; Tue, 22 Apr 2025 11:01:50 -0400 Received: from lists.gnu.org ([2001:470:142::17]:42354) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u7F86-0008Cb-1r for submit@debbugs.gnu.org; Tue, 22 Apr 2025 11:01:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u7F7r-0002Ku-SH for bug-gnu-emacs@gnu.org; Tue, 22 Apr 2025 11:01:33 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u7F7m-0005n1-0o for bug-gnu-emacs@gnu.org; Tue, 22 Apr 2025 11:01:31 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-ac2902f7c2aso804240366b.1 for ; Tue, 22 Apr 2025 08:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745334081; x=1745938881; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=pEvW3mcmYuKCqb3rmD/WXm6LIXYPoGdwnUO0n7I8qHg=; b=WIv8I4+u7q2eFyMQp3uK/CwStJkZppn+RdSdU3h6ftvY+eDilfNWWgdQ2MIR7yo2nw g9qr+aeX7RMDdhRauZP2t+1PYx8lEsTekm1csa5Fx+c/ij2zTdhaNEMYvvdEfTkgh6iD 9G9D59BXPW0cNDOdaR9l/Ms+rep5hQbA4qp0GktGlTwafsuVVlOYnlVCYtS6uWCE5lUV zJ3CZETo79RCL7tX4cYw8tCLURLsFA8ouuLG5sXV2UGHEXvIJDnXH2VKg0gqdYJVS1m+ f+VAklaUi6aUSEnQzPQi4WWCXu38gS1GgeyB6ihKAK+HLGt6Ve/55FKhzb1Y/uS8NCQ1 jwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745334081; x=1745938881; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pEvW3mcmYuKCqb3rmD/WXm6LIXYPoGdwnUO0n7I8qHg=; b=RIK2V3SVLdbJINPvTDpoAwLU+zqHbPCzmATyDN4+0qVQo6LnjBT7Q/NHXc1xfRIk0o 9PPKn7X5UynNIQez4kBG3+tu5gmV9eisGBAboGGpABSfT1xosr4oUTMPEKSSYERA1aNh 45LnFyv4RD2s7duZDWfSp5pX1TRrzR7HuyYmBxnHvBe+JXr3j/Osgp/pnj+JWFrWDHs7 xkF/4IlCl5lLTF7C1hH74XQl32EMvxKjQ1NrbjNW1qBi2c+wbejqvICvKrm5IKSS44dn prZVxwRuCEC+NOl9Shk4P88Ouad9icrzXUIDdfb1P4Lbw1wsDG3Flw2h4eKyb8WF1a28 lneg== X-Gm-Message-State: AOJu0YwmtMLthLBU4ZFJ/ymG7jVx2TGwOvan38nXf/fvJpp1qDetTJey wsVkB/tOGp5MEgxocmHit1UDUumz8IT0yB7LL9/aF9w+c+9mC8VBV+osrqlu X-Gm-Gg: ASbGncs6aKCqsZf2MMqaHo9wQW+SN84P75teY8CmK+cQz1fpYyZcZFyw6Sltn/YsAE6 7Czkvs7+IhTS+y8NUV4WSLCbKlZ2CC1yUv7Z+ys324RO9hL/4L+NxVZd5tOsrMorhhIDJ68K7C8 aM8N5F28uuwvuvDHT5lQc45mjFOPlG0558gLXrnDA4fak1aOKg9FZ9auPFY5zqY1oI3HXZ22nq5 j68uGmT7xBw4KpTqmnOAZTItnysy6QIPM0m/IBdULFnngfN0BIbed140ozZCUrtaa5qQTVH+MKj HX1USALDSyfL361end6emTh4Hg+sU+gyX3TSuGnoAALO X-Google-Smtp-Source: AGHT+IEBNzh/JqE83x4VgTYIWHi4zuSlhBJZfQmpWCBU0uWjf7prtY/sGFFuoadIYh6lV7BGDguIQQ== X-Received: by 2002:a17:907:7255:b0:acb:33ba:2889 with SMTP id a640c23a62f3a-acb74dd0838mr1420441666b.41.1745334081102; Tue, 22 Apr 2025 08:01:21 -0700 (PDT) Received: from localhost ([130.225.21.26]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-acb6ec4c6b5sm656187966b.49.2025.04.22.08.01.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 08:01:20 -0700 (PDT) From: "Paul D. Nelson" To: bug-gnu-emacs@gnu.org Subject: [PATCH] Use future history to select current script for pdb et al Date: Tue, 22 Apr 2025 17:01:18 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=ultrono@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain The simplest way I know to debug the current Python script is: 1. Copy the name of the current file (C-x C-j C-0 w) 2. M-x pdb RET yank RET (possibly after deleting previous file name) This seems like a good place to introduce a "future history" operation. The attached patch does so, via a new optional argument to gud-query-cmdline. The above then simplifies to M-x pdb RET M-n RET. Existing behavior is unchanged. I added the same feature to other gdb commands for which it seemed to make sense (perldb, guiler). Feedback or other suggestions would be welcome. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-forward-history-support-for-some-debuggers.patch >From 81382b69b83298d5bc098cc49f373d57a0909b42 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Mon, 21 Apr 2025 22:14:53 +0200 Subject: [PATCH] Add "forward history" support for some debuggers * lisp/progmodes/gud.el (gud-query-cmdline): Add an optional default-list parameter to allow passing a list of "forward history" suggestions to the minibuffer. (perldb, pdb, guiler): Use buffer file name to suggest a default debugging command via "forward history". * doc/emacs/building.texi (Starting GUD): Document the new feature. --- doc/emacs/building.texi | 3 +++ etc/NEWS | 8 ++++++++ lisp/progmodes/gud.el | 31 +++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index 02ca71f069b..39c5e79a870 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -674,6 +674,9 @@ Starting GUD using the minibuffer. The minibuffer's initial contents contain the standard executable name and options for the debugger, and sometimes also a guess for the name of the executable file you want to debug. +For @code{pdb}, @code{perldb}, and @code{guiler}, if the current buffer +visits a file, pressing @kbd{M-n} (@code{next-history-element}) +in the prompt suggests a full command line including that file name. Shell wildcards and variables are not allowed in this command line. Emacs assumes that the first command argument which does not start with a @samp{-} is the executable file name. diff --git a/etc/NEWS b/etc/NEWS index 56a45068daf..3519bc928ff 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1940,6 +1940,14 @@ normal file name starts with "file:", you can disable the URI recognition by invoking 'sqlite-open' with the new optional argument DISABLE-URI non-nil. +** GUD + +--- +*** pdb, perldb, and guiler suggest debugging the current file via 'M-n'. +When starting these debuggers (e.g., 'M-x pdb') while visiting a file, +pressing 'M-n' in the command prompt suggests a command line including +the file name, using the minibuffer's "future history". + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 3cca55be3a7..7108673dddc 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -757,7 +757,11 @@ gud-minibuffer-local-map :parent minibuffer-local-map "C-i" #'comint-dynamic-complete-filename) -(defun gud-query-cmdline (minor-mode &optional init) +(defun gud-query-cmdline (minor-mode &optional init default-list) + "Prompt for a command to run the debugger. +MINOR-MODE is the name of the debugger to run. INIT is the initial +command, before any history is available. DEFAULT-LIST is a list of +default commands, accessible via \\[next-history-element]." (let* ((hist-sym (gud-symbol 'history nil minor-mode)) (cmd-name (gud-val 'command-name minor-mode))) (unless (boundp hist-sym) (set hist-sym nil)) @@ -780,7 +784,8 @@ gud-query-cmdline (setq file f))) file))))) gud-minibuffer-local-map nil - hist-sym))) + hist-sym + default-list))) (defvar gdb-first-prompt t) @@ -1671,8 +1676,13 @@ perldb The directory containing the perl program becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'perldb - (concat (or (buffer-file-name) "-E 0") " ")))) + (list + (gud-query-cmdline + 'perldb + (concat (or (buffer-file-name) "-E 0") " ") + (when-let* ((file (buffer-file-name))) + (list (concat gud-perldb-command-name " " + (shell-quote-argument file) " ")))))) (gud-common-init command-line 'gud-perldb-massage-args 'gud-perldb-marker-filter) @@ -1802,7 +1812,11 @@ pdb The directory containing this file becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'pdb))) + (list (gud-query-cmdline + 'pdb nil + (when-let* ((file (buffer-file-name))) + (list (concat gud-pdb-command-name " " + (shell-quote-argument file))))))) (gud-common-init command-line nil 'gud-pdb-marker-filter) (setq-local gud-minor-mode 'pdb) @@ -1889,7 +1903,12 @@ guiler The directory containing FILE becomes the initial working directory and source-file directory for your debugger." (interactive - (list (gud-query-cmdline 'guiler))) + (list + (gud-query-cmdline + 'guiler nil + (when-let* ((file (buffer-file-name))) + (list (concat gud-guiler-command-name " " + (shell-quote-argument file))))))) (gud-common-init command-line nil 'gud-guiler-marker-filter) (setq-local gud-minor-mode 'guiler) -- 2.39.3 (Apple Git-145) --=-=-=-- ------------=_1745673783-1482-1--