docstr: Bring up an editor and execute the resulting code.
  
  Usage:
    %edit [options] [args]
  
  %edit runs an external text editor. You will need to set the command for
  this editor via the ``TerminalInteractiveShell.editor`` option in your
  configuration file before it will work.
  
  This command allows you to conveniently edit multi-line code right in
  your IPython session.
  
  If called without arguments, %edit opens up an empty editor with a
  temporary file and will execute the contents of this file when you
  close it (don't forget to save it!).
  
  Options:
  
  -n <number>
    Open the editor at a specified line number. By default, the IPython
    editor hook uses the unix syntax 'editor +N filename', but you can
    configure this by providing your own modified hook if your favorite
    editor supports line-number specifications with a different syntax.
  
  -p
    Call the editor with the same data as the previous time it was used,
    regardless of how long ago (in your current session) it was.
  
  -r
    Use 'raw' input. This option only applies to input taken from the
    user's history.  By default, the 'processed' history is used, so that
    magics are loaded in their transformed version to valid Python.  If
    this option is given, the raw input as typed as the command line is
    used instead.  When you exit the editor, it will be executed by
    IPython's own processor.
  
  Arguments:
  
  If arguments are given, the following possibilites exist:
  
  - The arguments are numbers or pairs of colon-separated numbers (like
    1 4:8 9). These are interpreted as lines of previous input to be
    loaded into the editor. The syntax is the same of the %macro command.
  
  - If the argument doesn't start with a number, it is evaluated as a
    variable and its contents loaded into the editor. You can thus edit
    any string which contains python code (including the result of
    previous edits).
  
  - If the argument is the name of an object (other than a string),
    IPython will try to locate the file where it was defined and open the
    editor at the point where it is defined. You can use ``%edit function``
    to load an editor exactly at the point where 'function' is defined,
    edit it and have the file be executed automatically.
  
    If the object is a macro (see %macro for details), this opens up your
    specified editor with a temporary file containing the macro's data.
    Upon exit, the macro is reloaded with the contents of the file.
  
    Note: opening at an exact line is only supported under Unix, and some
    editors (like kedit and gedit up to Gnome 2.8) do not understand the
    '+NUMBER' parameter necessary for this feature. Good editors like
    (X)Emacs, vi, jed, pico and joe all do.
  
  - If the argument is not found as a variable, IPython will look for a
    file with that name (adding .py if necessary) and load it into the
    editor. It will execute its contents with execfile() when you exit,
    loading any code in the file into your interactive namespace.
  
  Unlike in the terminal, this is designed to use a GUI editor, and we do
  not know when it has closed. So the file you edit will not be
  automatically executed or printed.
  
  Note that %edit is also available through the alias %ed.
docstr_tok: ["Bring","up","an","editor","and","execute","the","resulting","code",".","Usage",":","%","edit","[","options","]","[","args","]","%","edit","runs","an","external","text","editor",".","You","will","need","to","set","the","command","for","this","editor","via","the","``","TerminalInteractiveShell.editor","``","option","in","your","configuration","file","before","it","will","work",".","This","command","allows","you","to","conveniently","edit","multi-line","code","right","in","your","IPython","session",".","If","called","without","arguments",",","%","edit","opens","up","an","empty","editor","with","a","temporary","file","and","will","execute","the","contents","of","this","file","when","you","close","it","(","do","n't","forget","to","save","it","!",")",".","Options",":","-n","<","number",">","Open","the","editor","at","a","specified","line","number",".","By","default",",","the","IPython","editor","hook","uses","the","unix","syntax","'editor","+N","filename","'",",","but","you","can","configure","this","by","providing","your","own","modified","hook","if","your","favorite","editor","supports","line-number","specifications","with","a","different","syntax",".","-p","Call","the","editor","with","the","same","data","as","the","previous","time","it","was","used",",","regardless","of","how","long","ago","(","in","your","current","session",")","it","was",".","-r","Use","'raw","'","input",".","This","option","only","applies","to","input","taken","from","the","user","'s","history",".","By","default",",","the","'processed","'","history","is","used",",","so","that","magics","are","loaded","in","their","transformed","version","to","valid","Python",".","If","this","option","is","given",",","the","raw","input","as","typed","as","the","command","line","is","used","instead",".","When","you","exit","the","editor",",","it","will","be","executed","by","IPython","'s","own","processor",".","Arguments",":","If","arguments","are","given",",","the","following","possibilites","exist",":","-","The","arguments","are","numbers","or","pairs","of","colon-separated","numbers","(","like","1","4:8","9",")",".","These","are","interpreted","as","lines","of","previous","input","to","be","loaded","into","the","editor",".","The","syntax","is","the","same","of","the","%","macro","command",".","-","If","the","argument","does","n't","start","with","a","number",",","it","is","evaluated","as","a","variable","and","its","contents","loaded","into","the","editor",".","You","can","thus","edit","any","string","which","contains","python","code","(","including","the","result","of","previous","edits",")",".","-","If","the","argument","is","the","name","of","an","object","(","other","than","a","string",")",",","IPython","will","try","to","locate","the","file","where","it","was","defined","and","open","the","editor","at","the","point","where","it","is","defined",".","You","can","use","``","%","edit","function","``","to","load","an","editor","exactly","at","the","point","where","'function","'","is","defined",",","edit","it","and","have","the","file","be","executed","automatically",".","If","the","object","is","a","macro","(","see","%","macro","for","details",")",",","this","opens","up","your","specified","editor","with","a","temporary","file","containing","the","macro","'s","data",".","Upon","exit",",","the","macro","is","reloaded","with","the","contents","of","the","file",".","Note",":","opening","at","an","exact","line","is","only","supported","under","Unix",",","and","some","editors","(","like","kedit","and","gedit","up","to","Gnome","2.8",")","do","not","understand","the","'+NUMBER","'","parameter","necessary","for","this","feature",".","Good","editors","like","(","X",")","Emacs",",","vi",",","jed",",","pico","and","joe","all","do",".","-","If","the","argument","is","not","found","as","a","variable",",","IPython","will","look","for","a","file","with","that","name","(","adding",".py","if","necessary",")","and","load","it","into","the","editor",".","It","will","execute","its","contents","with","execfile","(",")","when","you","exit",",","loading","any","code","in","the","file","into","your","interactive","namespace",".","Unlike","in","the","terminal",",","this","is","designed","to","use","a","GUI","editor",",","and","we","do","not","know","when","it","has","closed",".","So","the","file","you","edit","will","not","be","automatically","executed","or","printed",".","Note","that","%","edit","is","also","available","through","the","alias","%","ed","."]
code: def edit(self, parameter_s="", last_call=["", ""]):
      """Bring up an editor and execute the resulting code.
  
      Usage:
        %edit [options] [args]
  
      %edit runs an external text editor. You will need to set the command for
      this editor via the ``TerminalInteractiveShell.editor`` option in your
      configuration file before it will work.
  
      This command allows you to conveniently edit multi-line code right in
      your IPython session.
  
      If called without arguments, %edit opens up an empty editor with a
      temporary file and will execute the contents of this file when you
      close it (don't forget to save it!).
  
      Options:
  
      -n <number>
        Open the editor at a specified line number. By default, the IPython
        editor hook uses the unix syntax 'editor +N filename', but you can
        configure this by providing your own modified hook if your favorite
        editor supports line-number specifications with a different syntax.
  
      -p
        Call the editor with the same data as the previous time it was used,
        regardless of how long ago (in your current session) it was.
  
      -r
        Use 'raw' input. This option only applies to input taken from the
        user's history.  By default, the 'processed' history is used, so that
        magics are loaded in their transformed version to valid Python.  If
        this option is given, the raw input as typed as the command line is
        used instead.  When you exit the editor, it will be executed by
        IPython's own processor.
  
      Arguments:
  
      If arguments are given, the following possibilites exist:
  
      - The arguments are numbers or pairs of colon-separated numbers (like
        1 4:8 9). These are interpreted as lines of previous input to be
        loaded into the editor. The syntax is the same of the %macro command.
  
      - If the argument doesn't start with a number, it is evaluated as a
        variable and its contents loaded into the editor. You can thus edit
        any string which contains python code (including the result of
        previous edits).
  
      - If the argument is the name of an object (other than a string),
        IPython will try to locate the file where it was defined and open the
        editor at the point where it is defined. You can use ``%edit function``
        to load an editor exactly at the point where 'function' is defined,
        edit it and have the file be executed automatically.
  
        If the object is a macro (see %macro for details), this opens up your
        specified editor with a temporary file containing the macro's data.
        Upon exit, the macro is reloaded with the contents of the file.
  
        Note: opening at an exact line is only supported under Unix, and some
        editors (like kedit and gedit up to Gnome 2.8) do not understand the
        '+NUMBER' parameter necessary for this feature. Good editors like
        (X)Emacs, vi, jed, pico and joe all do.
  
      - If the argument is not found as a variable, IPython will look for a
        file with that name (adding .py if necessary) and load it into the
        editor. It will execute its contents with execfile() when you exit,
        loading any code in the file into your interactive namespace.
  
      Unlike in the terminal, this is designed to use a GUI editor, and we do
      not know when it has closed. So the file you edit will not be
      automatically executed or printed.
  
      Note that %edit is also available through the alias %ed.
      """
  
      opts, args = self.parse_options(parameter_s, "prn:")
  
      try:
          filename, lineno, _ = CodeMagics._find_edit_target(
              self.shell, args, opts, last_call
          )
      except MacroToEdit:
          # TODO: Implement macro editing over 2 processes.
          print("Macro editing not yet implemented in 2-process model.")
          return
  
      # Make sure we send to the client an absolute path, in case the working
      # directory of client and kernel don't match
      filename = os.path.abspath(filename)
  
      payload = {
          "source": "edit_magic",
          "filename": filename,
          "line_number": lineno,
      }
      self.shell.payload_manager.write_payload(payload)
  
imports: from __future__ import print_function
  import os
  import sys
  import time
  import warnings
  from threading import local
  from tornado import ioloop
  from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
  from IPython.core import page
  from IPython.core.autocall import ZMQExitAutocall
  from IPython.core.displaypub import DisplayPublisher
  from IPython.core.error import UsageError
  from IPython.core.magics import MacroToEdit, CodeMagics
  from IPython.core.magic import magics_class, line_magic, Magics
  from IPython.core import payloadpage
  from IPython.core.usage import default_banner
  from IPython.display import display, Javascript
  from ipykernel import get_connection_file, get_connection_info, connect_qtconsole
  from IPython.utils import openpy
  from ipykernel.jsonutil import json_clean, encode_images
  from IPython.utils.process import arg_split
  from ipython_genutils import py3compat
  from ipython_genutils.py3compat import unicode_type
  from traitlets import Instance, Type, Dict, CBool, CBytes, Any, default, observe
  from ipykernel.displayhook import ZMQShellDisplayHook
  from jupyter_core.paths import jupyter_runtime_dir
  from jupyter_client.session import extract_header, Session
label_desc: Use image node_id 1 for calling the KernelMagics obj's underlying member method code with example usage: obj.edit(parameter_s, last_call) without return types