From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#66604: [PATCH] Gud LLDB completions Date: Wed, 18 Oct 2023 18:57:44 +0200 Message-ID: References: <13AC7AD2-230A-4FAC-81D9-75FBE53456F8@gmail.com> <586BC992-4776-4C8B-9700-821FF04A1046@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1698"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66604@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 18 18:59:13 2023 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 1qt9t2-0000G8-Fd for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Oct 2023 18:59:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qt9sV-0003Ky-Fm; Wed, 18 Oct 2023 12:58:39 -0400 Original-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 1qt9sS-0003KP-Tf for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 12:58:36 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qt9sS-0002cG-KS for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 12:58:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qt9ss-0001hE-5c for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 12:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Oct 2023 16:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66604 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66604-submit@debbugs.gnu.org id=B66604.16976483036452 (code B ref 66604); Wed, 18 Oct 2023 16:59:02 +0000 Original-Received: (at 66604) by debbugs.gnu.org; 18 Oct 2023 16:58:23 +0000 Original-Received: from localhost ([127.0.0.1]:34574 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt9sF-0001g0-1Q for submit@debbugs.gnu.org; Wed, 18 Oct 2023 12:58:23 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:61454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt9sC-0001fO-2S for 66604@debbugs.gnu.org; Wed, 18 Oct 2023 12:58:21 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99c1c66876aso1148418366b.2 for <66604@debbugs.gnu.org>; Wed, 18 Oct 2023 09:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697648266; x=1698253066; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=i5SgSraTtEGFl+syu7cdEu5MPmYg60dDmyUdZ9TteMU=; b=LK93ONeHzQc73nJro+4cRbmEoVN5jXB/75+hOT5Ax8st7LglfIji+zuY2tR4Rm/6Yx oZJx8CZypsEXcLn2bqa+GD0okuM7XCJ+drZfCpJRTEIaXF1KYvp0Kfr8tT0uzpr/pSjh uD/P1m4LDkphB35iQtQpDAnnSNR91vHmHSqWXdjBxeLuO+7yUiXV0hF1JM4JCFJlTp9i nzaF5+FfDfViv06f/ncHNDHNgS7pjfDQZMYTsc8XagjAbk5IO6aWtnU7mABnoIGAIwcI cleMsEwh735cxv5qilA3uMjPrZwce+lA3z5Of4V582aJ0uEUKsbdGX7A1As3ZIKbCzrA k6Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697648266; x=1698253066; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i5SgSraTtEGFl+syu7cdEu5MPmYg60dDmyUdZ9TteMU=; b=a7RWUAqVEePaB8mtUP/ev8/luoxGRl18gk5F0vmq/NkrnEqpAjrpBb6VFeTjSwvs9k SmiQc9IF6Xmn8/52V0QU/R4eE3WGPd3LmZMH5KwDqg12WcwxVofqE1QS7B4/fn9RWv/l L6a3fExU0Xg3Eext4lyez/+xJ+2JMXxV/T84cIVmBfa7BTZo8EtQ4bf8FhkADXG/zJAV 0a/IdNW0ER2WLYDquXcpIInIWJcCRGI9awObx4jPxG0dafdekFu4QPN1bB5/vJGKA8la d8IVxg98BPtENlWkkX2JEfNEZeNFQkbj2OQCZgRhuoZPa7UyGK+INk3KIwn6QVFpGoU/ x1yA== X-Gm-Message-State: AOJu0YxyL0ofaCotf+pQARMftplGwi944xQIzUKhu/poWq4O7rUnR4Nm 5vSRQfEn7OibhWOTzoiO9wu9wCVw9j8= X-Google-Smtp-Source: AGHT+IHUmE/0upgRFpenieZyKxwM2FV5yryVBceSAOVG6XSJdbrr/T8kdhnXsBSbfeB+MbFT1IaG5A== X-Received: by 2002:a17:907:25c1:b0:9be:ef46:6b9c with SMTP id ae1-20020a17090725c100b009beef466b9cmr4425571ejc.70.1697648266171; Wed, 18 Oct 2023 09:57:46 -0700 (PDT) Original-Received: from Mini.fritz.box (p4fe3a178.dip0.t-ipconnect.de. [79.227.161.120]) by smtp.gmail.com with ESMTPSA id lf16-20020a170906ae5000b0099cd1c0cb21sm1988068ejb.129.2023.10.18.09.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 09:57:45 -0700 (PDT) In-Reply-To: <586BC992-4776-4C8B-9700-821FF04A1046@gmail.com> ("Mattias =?UTF-8?Q?Engdeg=C3=A5rd?="'s message of "Wed, 18 Oct 2023 18:05:55 +0200") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272669 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mattias Engdeg=C3=A5rd writes: > 18 okt. 2023 kl. 17.23 skrev Gerd M=C3=B6llmann : > >> Does the attached also work? It would have the advantage of being more >> readable. The Python part. > > Yes, it works. > A minor request is that if there is only a single completion, then a spac= e should be added after completing the word. For example, > > (lldb) sett > > should add the 5 characters "ings " to the input. Yeah, that's right. Could ypu please try the attached patch? This of works for me, but a bit unnerving its that Corfu pops up after tryping 3 character with a single candidate, but that's something I can live with, I guess. Maybe it's even normal, now that i think of it. What completion are you using? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Gud-LLDB-completions-bug-66604.patch Content-Description: patch adding space >From 36b4f27ee0a97880b9eb19c1f6f2c9f1f6b22437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Wed, 18 Oct 2023 09:24:45 +0200 Subject: [PATCH] Gud LLDB completions (bug#66604) * etc/emacs_lldb.py: Remove xcomplete. * lisp/progmodes/gud.el: Implement lldb command completions. --- etc/emacs_lldb.py | 30 ------------- lisp/progmodes/gud.el | 97 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 33 deletions(-) diff --git a/etc/emacs_lldb.py b/etc/emacs_lldb.py index f2c7a7987c7..fa8d95d7b5b 100644 --- a/etc/emacs_lldb.py +++ b/etc/emacs_lldb.py @@ -203,35 +203,6 @@ def xdebug_print(debugger, command, result, internal_dict): """Print Lisp_Objects using safe_debug_print()""" debugger.HandleCommand(f"expr safe_debug_print({command})") -# According to SBCommanInterpreter.cpp, the return value of -# HandleCompletions is as follows: -# -# Index 1 to the end contain all the completions. -# -# At index 0: -# -# If all completions have a common prefix, this is the shortest -# completion, with the common prefix removed from it. -# -# If it is the completion for a whole word, a space is added at the -# end. -# -# So, the prefix is what could be added to make the command partially -# complete. -# -# If there is no common prefix, index 0 has an empty string "". - -def xcomplete(debugger, command, result, internal_dict): - """Print completions for COMMAND.""" - interpreter = debugger.GetCommandInterpreter() - string_list = lldb.SBStringList() - interpreter.HandleCompletion(command, len(command), len(command), - -1, string_list) - list = "" - for i in range(string_list.GetSize()): - list += '"' + string_list.GetStringAtIndex(i) + '" ' - result.AppendMessage("(" + list + ")") - ######################################################################## # Formatters @@ -336,7 +307,6 @@ def enable_type_category(debugger, category): def __lldb_init_module(debugger, internal_dict): define_command(debugger, xbacktrace) define_command(debugger, xdebug_print) - define_command(debugger, xcomplete) define_type_summary(debugger, "Lisp_Object", type_summary_Lisp_Object) define_type_synthetic(debugger, "Lisp_Object", Lisp_Object_Provider) enable_type_category(debugger, "Emacs") diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index ea5a3580629..5470c0ef11f 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -3850,7 +3850,7 @@ gud-tooltip-tips ;; 'gud-lldb-history' and 'gud-gud-lldb-command-name' are required -;; because gud-symbol uses their values if they are present. Their +;; because 'gud-symbol' uses their values if they are present. Their ;; names are deduced from the minor-mode name. (defvar gud-lldb-history nil) @@ -3859,7 +3859,7 @@ gud-gud-lldb-command-name :type 'string) (defun gud-lldb-marker-filter (string) - "Deduce interesting stuff from output STRING." + "Deduce interesting stuff from process output STRING." (cond (;; Process 72668 stopped ;; * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 ;; frame #0: ...) at emacs.c:1310:9 [opt] @@ -3879,6 +3879,91 @@ gud-lldb-marker-filter (setq gud-overlay-arrow-position nil))) string) +;; According to SBCommanInterpreter.cpp, the return value of +;; HandleCompletions is as follows: +;; +;; Index 1 to the end contain all the completions. +;; +;; At index 0: +;; +;; If all completions have a common prefix, this is the shortest +;; completion, with the common prefix removed from it. +;; +;; If it is the completion for a whole word, a space is added at the +;; end. +;; +;; So, the prefix is what could be added to make the command partially +;; complete. +;; +;; If there is no common prefix, index 0 has an empty string "". + +(defun gud-lldb-fetch-completions () + "Return the data to complete the LLDB command before point." + (let* ((process (get-buffer-process gud-comint-buffer)) + (start (process-mark process)) + (end (point)) + (to-complete (buffer-substring-no-properties start end)) + (output-buffer (get-buffer-create "*lldb-completions*"))) + ;; Send the completion command with output to our buffer + (with-current-buffer output-buffer + (erase-buffer)) + (comint-redirect-send-command-to-process + (format "script --language python -- gud_complete('%s')" + to-complete) + output-buffer process nil t) + ;; Wait for output + (unwind-protect + (while (not comint-redirect-completed) + (accept-process-output process)) + (comint-redirect-cleanup)) + ;; Process the completion output. + (with-current-buffer output-buffer + (goto-char (point-min)) + (when (search-forward "gud-completions:" nil t) + (let ((completions (read (current-buffer)))) + (if (string-suffix-p " " (car completions)) + (list (concat (cl-second completions) " ")) + (cdr completions))))))) + +(defun gud-lldb-completions (_context _command) + "Completion table for LLDB commands." + (gud-lldb-fetch-completions)) + +(defun gud-lldb-completion-at-point () + "Return the data to complete the LLDB command before point." + (let* ((end (point)) + (line-start (comint-line-beginning-position)) + (start (save-excursion + (skip-chars-backward "^ " line-start) + (point)))) + (list (copy-marker start t) end + (completion-table-dynamic + (apply-partially #'gud-lldb-completions + (buffer-substring line-start start)))))) + +(defvar gud-lldb-def-python-completion-function + " +def gud_complete(s): + interpreter = lldb.debugger.GetCommandInterpreter() + string_list = lldb.SBStringList() + interpreter.HandleCompletion(s, len(s), len(s), -1, string_list) + print('gud-completions: (') + for i in range(string_list.GetSize()): + print(f'\"{string_list.GetStringAtIndex(i)}\" ') + print(')') +" + "LLDB command to define a Python function for completion.") + +(defun gud-lldb-send-python (python) + (gud-basic-call "script --language python --") + (mapc #'gud-basic-call (split-string python "\n")) + (gud-basic-call "exit()")) + +(defun gud-lldb-initialize () + "Initialize the LLDB process as needed for this debug session." + (gud-lldb-send-python gud-lldb-def-python-completion-function) + (gud-basic-call "script --language python -- print('Gud initialized')")) + ;;;###autoload (defun lldb (command-line) "Run lldb passing it COMMAND-LINE as arguments. @@ -3979,11 +4064,17 @@ lldb nil "Run the program.") + (add-hook 'completion-at-point-functions + #'gud-lldb-completion-at-point + nil 'local) + (keymap-local-set "" #'completion-at-point) + (gud-set-repeat-map-property 'gud-gdb-repeat-map) (setq comint-prompt-regexp (rx line-start "(lldb)" (0+ blank))) + (setq comint-process-echoes t) (setq paragraph-start comint-prompt-regexp) (setq gud-running nil) - (setq gud-filter-pending-text nil) + (gud-lldb-initialize) (run-hooks 'lldb-mode-hook)) (provide 'gud) -- 2.42.0 --=-=-=--