title: emacs elisp send line if no region active python-mode
body: <p>I want to create a command where the region is sent if active, and if not, the current line/statement is evaluated and point is taken further to the next statement.</p>
  
  <p>I started with <a href="https://lists.gnu.org/archive/html/help-gnu-emacs/2010-08/msg00429.html" rel="nofollow">This solution.</a>
  Now I can't get the (python-shell-send-region) to work though as I don't know how to pass the beginning and end of the region to it. </p>
  
  <p>So far I have this:</p>
  
  <pre><code> (defun my-python-send-region (&amp;optional beg end)   
     (interactive)   
      (if (use-region-p)
        (python-shell-send-region)    (let ((beg (cond (beg beg)
                      ((region-active-p)
                       (region-beginning))
                      (t (line-beginning-position))))
           (end (cond (end end)
                      ((region-active-p)
                       (copy-marker (region-end)))
                      (t (line-end-position)))))
       (python-shell-send-region beg end)
       (python-nav-forward-statement))))
  
   (add-hook 'python-mode-hook
         (lambda ()
       (define-key python-mode-map "\C-cn" 'my-python-send-region)))
  </code></pre>
  
  <p>UPDATE: 
  With Andreas' and Legoscia's suggestions I changed the structure a bit. </p>
  
  <p>Now I get an error <em>(Invalid function: (setq beg (point))</em> for: </p>
  
  <pre><code> (defun my-python-send-region (&amp;optional beg end)
    (interactive)
    (if (use-region-p)
      (python-shell-send-region (region-beginning) (region-end))
     ((setq beg (point))
      (python-nav-end-of-statement)
      (setq end (point))
      (python-shell-send-region (beg) (end)))
      (python-nav-forward-statement))))
  </code></pre>
  
  <p>However, this works:</p>
  
  <pre><code> (defun my-python-send-region (&amp;optional beg end)
   (interactive)
   (setq beg (point))
   (python-nav-end-of-statement)
   (setq end (point))
   (python-shell-send-region beg end))
  </code></pre>