Emacs defadvice for python-mode function

In python mode, there is a function called py-execute-region that sends the selected area of ​​code to the Python buffer for evaluation. After evaluating, the cursor is in the Python buffer, but I would prefer it to remain in the script buffer, so I can continue to create more code. I wrote a simple advisory function:

(defadvice py-execute-region                                                
   (after py-execute-region-other-window activate)                          
   """ After execution, return cursor to script buffer """                  
   (other-window 1)                                                         
) 

But that doesn’t mean anything. I tried other options, such as using "around" rather than "after"; setting the variable to the name of the script buffer, and then the pop buffer to this buffer and the like. No success! I wonder how obvious this is to mechanics ... Thanks!

+5
source share
4 answers

In this case, the solution is

(custom-set-variables
 '(py-shell-switch-buffers-on-execute nil))
+8
source

Use tips to wrap a function on a call save-window-excursionthat will restore the previous window after the command completes.

(defadvice py-execute-region
   (around preserve-window-configuration activate)
   "After execution, return cursor to script buffer"
   (save-window-excursion ad-do-it))

Keep in mind that if the Python buffer has not yet been shown, it will still be hidden after the command completes. To fix this, you can add another tip to bring up the window for switching between buffers and other end windows:

(defadvice py-execute-region
   (after show-pybuf-other-window activate)
   "After execution, show the python buffer in another window."
   (switch-to-buffer-other-window "[PYTHON BUFFER NAME]"))

Also, make sure that you are not using """triple quotes"""elisp. I do not think they work.

+2
source

, , . , . , :

1)

2) , ,

3) : (ad-deactivate 'py-execute-region)

4) : (ad-activate 'py-execute-region)

4 , 2. 2, 4 ( , ).

+1

, - find-file, , . Emacs Lisp, .

(defadvice py-execute-region                                                
   (after py-execute-region-other-window activate)                          
   (interactive)
   (other-window 1)                                                         
)
+1

All Articles