From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: 66604@debbugs.gnu.org
Subject: bug#66604: [PATCH] Gud LLDB completions
Date: Wed, 18 Oct 2023 18:57:44 +0200 [thread overview]
Message-ID: <m2a5sfool3.fsf@Mini.fritz.box> (raw)
In-Reply-To: <586BC992-4776-4C8B-9700-821FF04A1046@gmail.com> ("Mattias Engdegård"'s message of "Wed, 18 Oct 2023 18:05:55 +0200")
[-- Attachment #1: Type: text/plain, Size: 801 bytes --]
Mattias Engdegård <mattias.engdegard@gmail.com> writes:
> 18 okt. 2023 kl. 17.23 skrev Gerd Möllmann <gerd.moellmann@gmail.com>:
>
>> 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 space should be added after completing the word. For example,
>
> (lldb) sett<TAB>
>
> 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?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch adding space --]
[-- Type: text/x-patch, Size: 7329 bytes --]
From 36b4f27ee0a97880b9eb19c1f6f2c9f1f6b22437 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd.moellmann@gmail.com>
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 + ")")
-
\f
########################################################################
# 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
\f
;; '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 "<tab>" #'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
next prev parent reply other threads:[~2023-10-18 16:57 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 11:25 bug#66604: [PATCH] Gud LLDB completions Gerd Möllmann
2023-10-18 13:37 ` Mattias Engdegård
2023-10-18 14:42 ` Gerd Möllmann
2023-10-18 15:14 ` Mattias Engdegård
2023-10-18 15:23 ` Gerd Möllmann
2023-10-18 16:05 ` Mattias Engdegård
2023-10-18 16:57 ` Gerd Möllmann [this message]
2023-10-18 18:55 ` Gerd Möllmann
2023-10-19 10:34 ` Mattias Engdegård
2023-10-19 10:48 ` Gerd Möllmann
2023-10-19 11:36 ` Mattias Engdegård
2023-10-19 11:50 ` Gerd Möllmann
2023-10-19 12:29 ` Mattias Engdegård
2023-10-19 13:08 ` Gerd Möllmann
2023-10-19 13:22 ` Mattias Engdegård
2023-10-20 6:04 ` Gerd Möllmann
2023-10-20 10:42 ` Mattias Engdegård
2023-10-20 11:12 ` Gerd Möllmann
2023-10-20 11:50 ` Mattias Engdegård
2023-10-20 11:59 ` Gerd Möllmann
2023-10-20 17:28 ` Gerd Möllmann
2023-10-20 17:47 ` Gerd Möllmann
2023-10-21 10:32 ` Gerd Möllmann
2023-10-21 10:51 ` Mattias Engdegård
2023-10-21 12:33 ` Gerd Möllmann
2023-10-21 10:37 ` Mattias Engdegård
2023-10-21 10:50 ` Gerd Möllmann
2023-10-23 5:31 ` Gerd Möllmann
2023-10-23 17:18 ` Mattias Engdegård
2023-10-23 17:57 ` Gerd Möllmann
2023-10-23 20:51 ` Mattias Engdegård
2023-10-24 4:35 ` Gerd Möllmann
2023-10-24 8:47 ` Mattias Engdegård
2023-10-24 8:52 ` Gerd Möllmann
2023-10-24 10:00 ` Mattias Engdegård
2023-10-24 10:27 ` Gerd Möllmann
2023-10-24 18:12 ` Mattias Engdegård
2023-10-25 4:29 ` Gerd Möllmann
2023-10-18 15:24 ` Gerd Möllmann
2023-10-19 6:31 ` Visuwesh
2023-10-19 6:56 ` Gerd Möllmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2a5sfool3.fsf@Mini.fritz.box \
--to=gerd.moellmann@gmail.com \
--cc=66604@debbugs.gnu.org \
--cc=mattias.engdegard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.