mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 09:31:39 -05:00
Make ein:pytools-jump-to-source-command more robust
This commit is contained in:
parent
853a9ec50e
commit
05a437b1ad
2 changed files with 20 additions and 12 deletions
|
@ -54,19 +54,25 @@
|
|||
kernel
|
||||
(format "__import__('ein').find_source('%s')" object)
|
||||
(lambda (string object)
|
||||
(let* ((filename-lineno (split-string string "\n"))
|
||||
(filename (car filename-lineno))
|
||||
(lineno (string-to-number (cadr filename-lineno))))
|
||||
(unless (equal filename "")
|
||||
(find-file-other-window filename)
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- lineno))
|
||||
(ein:log 'info "Jumping to the source of %s...Done" object))))
|
||||
(if (string-match "^WARNING: .*" string)
|
||||
(ein:log 'info "Jumping to the source of %s...Not found" object)
|
||||
(let* ((filename-lineno (split-string string "\n"))
|
||||
(filename (car filename-lineno))
|
||||
(lineno (string-to-number (cadr filename-lineno))))
|
||||
(unless (equal filename "")
|
||||
(find-file-other-window filename)
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- lineno))
|
||||
(ein:log 'info "Jumping to the source of %s...Done" object)))))
|
||||
(list object)))
|
||||
|
||||
(defun ein:pytools-jump-to-source-command ()
|
||||
(interactive)
|
||||
(ein:pytools-jump-to-source (ein:pytools-get-kernel) (ein:object-at-point)))
|
||||
(let ((kernel (ein:pytools-get-kernel))
|
||||
(object (ein:object-at-point)))
|
||||
(assert (ein:kernel-ready-p kernel) nil "Kernel is not ready.")
|
||||
(assert object nil "Object at point not found.")
|
||||
(ein:pytools-jump-to-source kernel object)))
|
||||
|
||||
(provide 'ein-pytools)
|
||||
|
||||
|
|
8
ein.py
8
ein.py
|
@ -25,6 +25,8 @@ def find_source(name):
|
|||
"""Given an object as string, `name`, print its place in source code."""
|
||||
from IPython.core.interactiveshell import InteractiveShell
|
||||
inst = InteractiveShell.instance()
|
||||
(filename, lineno, use_temp) = inst._find_edit_target(name, {}, [])
|
||||
print filename
|
||||
print lineno
|
||||
ret = inst._find_edit_target(name, {}, [])
|
||||
if ret:
|
||||
(filename, lineno, use_temp) = ret
|
||||
print filename
|
||||
print lineno
|
||||
|
|
Loading…
Add table
Reference in a new issue