[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 95f076e 150/215: Improve IPDB completion
From: |
Rocky Bernstein |
Subject: |
[elpa] master 95f076e 150/215: Improve IPDB completion |
Date: |
Sat, 30 Jul 2016 14:49:01 +0000 (UTC) |
branch: master
commit 95f076eca7638b60802c7f1391c05ca703d86f59
Author: Clément Pit--Claudel <address@hidden>
Commit: Clément Pit--Claudel <address@hidden>
Improve IPDB completion
Fail gracefully if point isn't at prompt, and get prefix from iPython
instead of relying on bounds-of-thing-at-point.
Fixes #75.
---
realgud/debugger/ipdb/core.el | 71 +++++++++++++++--------------------------
1 file changed, 25 insertions(+), 46 deletions(-)
diff --git a/realgud/debugger/ipdb/core.el b/realgud/debugger/ipdb/core.el
index e8a1a8c..46193be 100644
--- a/realgud/debugger/ipdb/core.el
+++ b/realgud/debugger/ipdb/core.el
@@ -195,63 +195,42 @@ breakpoints, etc.)."
;; (setcdr (assq 'ipdb-debugger-support-minor-mode minor-mode-map-alist)
;; ipdb-debugger-support-minor-mode-map-when-deactive))
+(defconst realgud:ipdb-complete-script
+ (concat
+ "from IPython import get_ipython;"
+ "comp = '''%s''';"
+ "prefix, candidates = get_ipython().Completer.complete(line_buffer = comp);"
+ "print(';'.join([prefix] + candidates))"))
+
(defun realgud:ipdb-backend-complete ()
"Send a command to the ipdb buffer and parse the output.
The idea here is to rely on the
`comint-redirect-send-command-to-process' function to send a
-python command that will return the completions for the given
-input. Specifically, here is the python code:
-
->>> from IPython import get_ipython
->>> comp = '''%s'''
->>> ';'.join(get_ipython().complete(comp.split()[-1] if len(comp)else '',
comp)[1])
-
-This returns a list of strings that match the current word (hence
-why we need the `bounds-of-thing-at-point')."
+python command `realgud:ipdb-complete-script' that will return
+the completions for the given input."
(interactive)
(let ((buffer (current-buffer))
(cmdbuf (realgud-get-cmdbuf))
(process (get-buffer-process (current-buffer)))
- (end-position (point))
- (bounds (bounds-of-thing-at-point 'word))
- )
+ (start-pos (save-excursion (comint-goto-process-mark) (point)))
+ (end-pos (point)))
;; get the input string
- (save-excursion
- (comint-goto-process-mark)
- (let* ((start-position (point))
- (input-str (buffer-substring-no-properties start-position
- end-position))
- )
- (when (not (= (length input-str) 0))
- (let* ((python-str (concat
- "from IPython import get_ipython; "
- "comp = '''%s''';"
- "';'.join(get_ipython()"
- ".complete(comp.split()[-1] if len(comp)"
- "else '', comp)[1])"))
- (command-str (format python-str input-str))
- (output-str (with-temp-buffer
- (let ((tmpbuf (current-buffer)))
- (comint-redirect-send-command-to-process
- command-str tmpbuf process nil t)
- ;; Wait for the process to complete
- (set-buffer (process-buffer process))
- (while (null comint-redirect-completed)
- (accept-process-output nil 0 5)) ;; wait 5ms
- (set-buffer tmpbuf)
- (buffer-substring (1+ (point-min))
- (1- (1- (point-max)))))))
- )
-
- ;; we need to change the start position to that of the current word
- ;; since python returns just the word (and not the whole line)
- (if (car bounds) (setq start-position (car bounds)))
-
- (list start-position
- end-position
- (split-string output-str ";"))))))))
+ (when (> end-pos start-pos)
+ (let* ((input-str (buffer-substring-no-properties start-pos end-pos))
+ (command-str (format realgud:ipdb-complete-script input-str))
+ (output-str (with-temp-buffer
+ (comint-redirect-send-command-to-process
+ command-str (current-buffer) process nil t)
+ ;; Wait for the process to complete
+ (with-current-buffer (process-buffer process)
+ (while (null comint-redirect-completed)
+ (accept-process-output nil 0 5))) ;; wait 5ms
+ (buffer-substring (point-min) (1- (point-max)))))
+ (output-values (split-string output-str ";"))
+ (prefix (car output-values)))
+ (list (- end-pos (length prefix)) end-pos (cdr output-values))))))
(defun realgud:ipdb-completion-at-point ()
(let ((ipdb (realgud:ipdb-backend-complete)))
- [elpa] master e049c12 124/215: Merge pull request #89 from cpitclaudel/87-improve-delete-command, (continued)
- [elpa] master e049c12 124/215: Merge pull request #89 from cpitclaudel/87-improve-delete-command, Rocky Bernstein, 2016/07/30
- [elpa] master 91704f9 141/215: Automatically attach to a command buffer when enabling short-key-mode, Rocky Bernstein, 2016/07/30
- [elpa] master 40e73bc 123/215: Merge pull request #92 from cpitclaudel/82-add-safe-mode, Rocky Bernstein, 2016/07/30
- [elpa] master f3426ed 072/215: Merge branch 'master' of github.com:rocky/emacs-dbgr, Rocky Bernstein, 2016/07/30
- [elpa] master 4e85910 088/215: Add pytest error message pattern in python debuggers, Rocky Bernstein, 2016/07/30
- [elpa] master 01617c5 100/215: ipdb: add regex test, Rocky Bernstein, 2016/07/30
- [elpa] master 5395757 091/215: More cleanup from last two commits., Rocky Bernstein, 2016/07/30
- [elpa] master 1e2fe55 098/215: Add rspec loc pattern.., Rocky Bernstein, 2016/07/30
- [elpa] master ea5dcba 094/215: ipdb: add new debugger based on pdb, Rocky Bernstein, 2016/07/30
- [elpa] master d1c1176 146/215: Simplify the implementation of realgud:cmdbuf-associate, Rocky Bernstein, 2016/07/30
- [elpa] master 95f076e 150/215: Improve IPDB completion,
Rocky Bernstein <=
- [elpa] master d45788c 152/215: Merge pull request #106 from rocky/75-ipdb-completion, Rocky Bernstein, 2016/07/30
- [elpa] master 032ea4b 143/215: Merge branch 'master' of github.com:rocky/emacs-dbgr, Rocky Bernstein, 2016/07/30
- [elpa] master 549f6f0 135/215: Merge pull request #98 from rocky/83-better-scope-keybindings, Rocky Bernstein, 2016/07/30
- [elpa] master aedea61 138/215: Merge pull request #101 from rocky/bp-icon-in-fringe, Rocky Bernstein, 2016/07/30
- [elpa] master 87d1ada 137/215: Refactor and improve breakpoint UI, Rocky Bernstein, 2016/07/30
- [elpa] master d6b879d 042/215: Merge branch 'trepanjs', Rocky Bernstein, 2016/07/30
- [elpa] master f3420e9 151/215: Merge pull request #105 from rocky/new-README, Rocky Bernstein, 2016/07/30
- [elpa] master 1c3d8c2 171/215: Add a bit of padding around the logo to make GitHub happy, Rocky Bernstein, 2016/07/30
- [elpa] master 678ec6b 139/215: Use `buffer-live-p' instead of `buffer-name' in `buffer-killed?', Rocky Bernstein, 2016/07/30
- [elpa] master daac75b 175/215: Add a C-u interface to break and clear, Rocky Bernstein, 2016/07/30