mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 17:11:41 -05:00
Move tooltip and help command to pytools
ein-notebook.el and ein-connect.el can share same command thanks to the generic getter function.
This commit is contained in:
parent
e2be2ab3b0
commit
f32a169920
6 changed files with 63 additions and 77 deletions
|
@ -625,24 +625,6 @@ Return `nil' always for non-code cells."
|
|||
prompt EWOC node."
|
||||
(ein:cell-set-autoexec cell (not (ein:cell-autoexec-p cell))))
|
||||
|
||||
(declare-function pos-tip-show "pos-tip")
|
||||
(declare-function popup-tip "popup")
|
||||
|
||||
(defun ein:cell-finish-tooltip (cell content -metadata-not-used-)
|
||||
;; See: Tooltip.prototype._show (tooltip.js)
|
||||
(let ((tooltip (ein:kernel-construct-help-string content))
|
||||
(defstring (ein:kernel-construct-defstring content))
|
||||
(name (plist-get content :name)))
|
||||
(if tooltip
|
||||
(cond
|
||||
((and window-system (featurep 'pos-tip))
|
||||
(pos-tip-show tooltip 'ein:pos-tip-face nil nil 0))
|
||||
((featurep 'popup)
|
||||
(popup-tip tooltip))
|
||||
(t (when (stringp defstring)
|
||||
(message (ein:trim (ansi-color-apply defstring))))))
|
||||
(ein:log 'info "no info for %s" name))))
|
||||
|
||||
(defmethod ein:cell-goto ((cell ein:basecell) &optional relpos)
|
||||
"Go to the input area of the given CELL.
|
||||
RELPOS is the position relative to the input area. Default is 0."
|
||||
|
|
|
@ -246,24 +246,9 @@ See also: `ein:connect-run-buffer', `ein:connect-eval-buffer'."
|
|||
'ein:connect-eval-string-internal
|
||||
'ein:shared-output-eval-string "0.1.2")
|
||||
|
||||
(defun ein:connect-request-tool-tip-command ()
|
||||
(interactive)
|
||||
(let ((notebook (ein:connect-get-notebook)))
|
||||
(ein:kernel-if-ready (ein:$notebook-kernel notebook)
|
||||
(let ((func (ein:object-at-point)))
|
||||
;; Set cell=nil. In fact, the argument cell is not used.
|
||||
;; FIXME: refactor `ein:notebook-request-tool-tip'
|
||||
(ein:notebook-request-tool-tip notebook nil func)))))
|
||||
|
||||
(defun ein:connect-request-help-command ()
|
||||
(interactive)
|
||||
(ein:notebook-request-help (ein:connect-get-notebook)))
|
||||
|
||||
(defun ein:connect-request-tool-tip-or-help-command (&optional pager)
|
||||
(interactive "P")
|
||||
(if pager
|
||||
(ein:connect-request-help-command)
|
||||
(ein:connect-request-tool-tip-command)))
|
||||
(define-obsolete-function-alias
|
||||
'ein:connect-request-tool-tip-or-help-command
|
||||
'ein:pytools-request-tooltip-or-help "0.1.2")
|
||||
|
||||
(defun ein:connect-complete-command ()
|
||||
(interactive)
|
||||
|
@ -344,7 +329,7 @@ change the cells to run."
|
|||
(define-key map "\C-c\C-l" 'ein:connect-reload-buffer)
|
||||
(define-key map "\C-c\C-r" 'ein:connect-eval-region)
|
||||
(define-key map (kbd "C-:") 'ein:shared-output-eval-string)
|
||||
(define-key map "\C-c\C-f" 'ein:connect-request-tool-tip-or-help-command)
|
||||
(define-key map "\C-c\C-f" 'ein:pytools-request-tooltip-or-help)
|
||||
(define-key map "\C-c\C-i" 'ein:connect-complete-command)
|
||||
(define-key map "\C-c\C-z" 'ein:connect-pop-to-notebook)
|
||||
(define-key map "\C-c\C-a" 'ein:connect-toggle-autoexec)
|
||||
|
|
|
@ -530,14 +530,14 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
|
|||
|
||||
(defun ein:kernel-construct-defstring (content)
|
||||
"Construct call signature from CONTENT of ``:object_info_reply``.
|
||||
Used in `ein:cell-finish-tooltip', etc."
|
||||
Used in `ein:pytools-finish-tooltip', etc."
|
||||
(or (plist-get content :call_def)
|
||||
(plist-get content :init_definition)
|
||||
(plist-get content :definition)))
|
||||
|
||||
(defun ein:kernel-construct-help-string (content)
|
||||
"Construct help string from CONTENT of ``:object_info_reply``.
|
||||
Used in `ein:cell-finish-tooltip', etc."
|
||||
Used in `ein:pytools-finish-tooltip', etc."
|
||||
(ein:log 'debug "KERNEL-CONSTRUCT-HELP-STRING")
|
||||
(let* ((defstring (ein:aand
|
||||
(ein:kernel-construct-defstring content)
|
||||
|
|
|
@ -941,43 +941,9 @@ next cell, or insert if none."
|
|||
do (ein:cell-execute cell))
|
||||
(ein:log 'error "Not in notebook buffer!")))
|
||||
|
||||
(defun ein:notebook-request-tool-tip (notebook cell func)
|
||||
(let ((kernel (ein:$notebook-kernel notebook))
|
||||
(callbacks
|
||||
(list :object_info_reply
|
||||
(cons #'ein:cell-finish-tooltip cell))))
|
||||
(ein:kernel-object-info-request kernel func callbacks)))
|
||||
|
||||
(defun ein:notebook-request-tool-tip-command ()
|
||||
(interactive)
|
||||
(ein:notebook-with-cell #'ein:codecell-p
|
||||
(ein:kernel-if-ready (ein:$notebook-kernel ein:%notebook%)
|
||||
(let ((func (ein:object-at-point)))
|
||||
(ein:notebook-request-tool-tip ein:%notebook% cell func)))))
|
||||
|
||||
(defun ein:notebook-request-help (notebook)
|
||||
(ein:kernel-if-ready (ein:$notebook-kernel notebook)
|
||||
(let ((func (ein:object-at-point)))
|
||||
(when func
|
||||
(ein:kernel-execute (ein:$notebook-kernel notebook)
|
||||
(format "%s?" func) ; = code
|
||||
nil ; = callbacks
|
||||
;; It looks like that magic command does
|
||||
;; not work in silent mode.
|
||||
:silent nil)))))
|
||||
|
||||
(defun ein:notebook-request-help-command ()
|
||||
(interactive)
|
||||
(ein:notebook-request-help ein:%notebook%))
|
||||
|
||||
(defun ein:notebook-request-tool-tip-or-help-command (&optional pager)
|
||||
"Show the help for the object at point using tooltip.
|
||||
When the prefix argument ``C-u`` is given, open the help in the
|
||||
pager buffer. You can explicitly specify the object by selecting it."
|
||||
(interactive "P")
|
||||
(if pager
|
||||
(ein:notebook-request-help-command)
|
||||
(ein:notebook-request-tool-tip-command)))
|
||||
(define-obsolete-function-alias
|
||||
'ein:notebook-request-tool-tip-or-help-command
|
||||
'ein:pytools-request-tooltip-or-help "0.1.2")
|
||||
|
||||
(defun ein:notebook-complete-at-point (notebook)
|
||||
(let ((kernel (ein:$notebook-kernel notebook))
|
||||
|
@ -1385,7 +1351,7 @@ Do not use `python-mode'. Use plain mode when MuMaMo is not installed::
|
|||
(define-key map (kbd "C-c <down>") 'ein:notebook-move-cell-down-command)
|
||||
(define-key map (kbd "M-<up>") 'ein:notebook-move-cell-up-command)
|
||||
(define-key map (kbd "M-<down>") 'ein:notebook-move-cell-down-command)
|
||||
(define-key map "\C-c\C-f" 'ein:notebook-request-tool-tip-or-help-command)
|
||||
(define-key map "\C-c\C-f" 'ein:pytools-request-tooltip-or-help)
|
||||
(define-key map "\C-c\C-i" 'ein:notebook-complete-command)
|
||||
(define-key map "\C-c\C-x" 'ein:tb-show)
|
||||
(define-key map "\C-c\C-r" 'ein:notebook-restart-kernel-command)
|
||||
|
|
|
@ -61,6 +61,56 @@ If OTHER-WINDOW is non-`nil', open the file in the other window."
|
|||
kernel
|
||||
(format "__import__('sys').path.append('%s')" ein:source-dir)))
|
||||
|
||||
|
||||
;;; Tooltip and help
|
||||
|
||||
(defun ein:pytools-request-tooltip (kernel func)
|
||||
(interactive (list (ein:get-kernel-or-error)
|
||||
(ein:object-at-point-or-error)))
|
||||
(ein:kernel-object-info-request
|
||||
kernel func (list :object_info_reply
|
||||
(cons #'ein:pytools-finish-tooltip nil))))
|
||||
|
||||
(declare-function pos-tip-show "pos-tip")
|
||||
(declare-function popup-tip "popup")
|
||||
|
||||
(defun ein:pytools-finish-tooltip (-ignore- content -metadata-not-used-)
|
||||
;; See: Tooltip.prototype._show (tooltip.js)
|
||||
(let ((tooltip (ein:kernel-construct-help-string content))
|
||||
(defstring (ein:kernel-construct-defstring content))
|
||||
(name (plist-get content :name)))
|
||||
(if tooltip
|
||||
(cond
|
||||
((and window-system (featurep 'pos-tip))
|
||||
(pos-tip-show tooltip 'ein:pos-tip-face nil nil 0))
|
||||
((featurep 'popup)
|
||||
(popup-tip tooltip))
|
||||
(t (when (stringp defstring)
|
||||
(message (ein:trim (ansi-color-apply defstring))))))
|
||||
(ein:log 'info "no info for %s" name))))
|
||||
|
||||
(defun ein:pytools-request-help (kernel func)
|
||||
(interactive (list (ein:get-kernel-or-error)
|
||||
(ein:object-at-point-or-error)))
|
||||
(ein:kernel-execute kernel
|
||||
(format "%s?" func) ; = code
|
||||
nil ; = callbacks
|
||||
;; It looks like that magic command does
|
||||
;; not work in silent mode.
|
||||
:silent nil))
|
||||
|
||||
(defun ein:pytools-request-tooltip-or-help (&optional pager)
|
||||
"Show the help for the object at point using tooltip.
|
||||
When the prefix argument ``C-u`` is given, open the help in the
|
||||
pager buffer. You can explicitly specify the object by selecting it."
|
||||
(interactive "P")
|
||||
(call-interactively (if pager
|
||||
#'ein:pytools-request-help
|
||||
#'ein:pytools-request-tooltip)))
|
||||
|
||||
|
||||
;;; Source jump
|
||||
|
||||
(defvar ein:pytools-jump-stack nil)
|
||||
|
||||
(defvar ein:pytools-jump-to-source-not-found-regexp
|
||||
|
|
|
@ -198,6 +198,9 @@ before previous opening parenthesis."
|
|||
(search-backward "(" (point-at-bol) t))
|
||||
(thing-at-point 'word))))))
|
||||
|
||||
(defun ein:object-at-point-or-error ()
|
||||
(or (ein:object-at-point) (error "No object found at the point")))
|
||||
|
||||
|
||||
;;; URL utils
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue