Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added python compile command #806

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contrib/lang/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ Send code to inferior process commands:
<kbd>CTRL+j</kbd> | next item in REPL history
<kbd>CTRL+k</kbd> | previous item in REPL history

### Running Python Script in Comint Mode

To run a Python script like you would in the shell
press <kbd>SPC c C RET</kbd> to start the Python script in
Comint mode. This is useful when working with multiple Python files
since the REPL does not reload changes made in other modules.

### Testing in Python

`Spacemacs` uses [nose][nose] as a test runner. An improved version of
Expand Down
23 changes: 23 additions & 0 deletions contrib/lang/python/extensions.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'(
nose
pylookup
python-compile
))

;; Initialize the extensions
Expand Down Expand Up @@ -66,3 +67,25 @@
(setq pylookup-dir (concat dir "/pylookup")
pylookup-program (concat pylookup-dir "/pylookup.py")
pylookup-db-file (concat pylookup-dir "/pylookup.db"))))))

(defun python/init-python-compile ()
"Initialize Compile command for python buffers"
;; set compile command to buffer-file-name
;; if buffer-file-name exists
;; otherwise error occurs on e.g. org export including python src
(add-hook 'python-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(if buffer-file-name
(format "python %s" (file-name-nondirectory buffer-file-name))))))

(defadvice compile (before ad-compile-smart activate)
"Advises `compile' so it sets the argument COMINT to t
in `python-mode' files"
(when (derived-mode-p major-mode 'python-mode)
(save-excursion
(save-match-data
(goto-char (point-min))
;; set COMINT argument to `t'.
(ad-set-arg 1 t)))))
)