2015-01-14 04:12:56 +00:00
|
|
|
;;; funcs.el --- Python Layer functions File for Spacemacs
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
;; from http://pedrokroger.net/2010/07/configuring-emacs-as-a-python-ide-2/
|
|
|
|
(defun annotate-pdb ()
|
|
|
|
"Highlight break point lines."
|
|
|
|
(interactive)
|
2015-04-24 04:31:08 +00:00
|
|
|
(highlight-lines-matching-regexp "import i?pu?db")
|
|
|
|
(highlight-lines-matching-regexp "i?pu?db.set_trace()"))
|
2014-11-10 04:54:10 +00:00
|
|
|
|
|
|
|
(defun python-toggle-breakpoint ()
|
|
|
|
"Add a break point, highlight it."
|
|
|
|
(interactive)
|
2015-04-24 04:31:08 +00:00
|
|
|
(let ((trace (cond ((executable-find "ipdb") "import ipdb; ipdb.set_trace()")
|
|
|
|
((executable-find "pudb") "import pudb; pudb.set_trace()")
|
2015-05-02 22:54:22 +00:00
|
|
|
(t "import pdb; pdb.set_trace()")))
|
2014-11-10 04:54:10 +00:00
|
|
|
(line (thing-at-point 'line)))
|
|
|
|
(if (and line (string-match trace line))
|
|
|
|
(kill-whole-line)
|
|
|
|
(progn
|
|
|
|
(back-to-indentation)
|
|
|
|
(insert-string trace)
|
|
|
|
(insert-string "\n")
|
|
|
|
(python-indent-line)))))
|
2015-04-24 05:12:30 +00:00
|
|
|
|
|
|
|
;; from https://www.snip2code.com/Snippet/127022/Emacs-auto-remove-unused-import-statemen
|
|
|
|
(defun python-remove-unused-imports()
|
|
|
|
"Use Autoflake to remove unused function"
|
|
|
|
"autoflake --remove-all-unused-imports -i unused_imports.py"
|
|
|
|
(interactive)
|
2015-04-25 02:15:02 +00:00
|
|
|
(if (executable-find "autoflake")
|
|
|
|
(progn
|
|
|
|
(shell-command (format "autoflake --remove-all-unused-imports -i %s"
|
|
|
|
(shell-quote-argument (buffer-file-name))))
|
|
|
|
(revert-buffer t t t))
|
|
|
|
(message "Error: Cannot find autoflake executable.")))
|
2015-12-07 12:58:36 +00:00
|
|
|
|
|
|
|
(defun pyenv-mode-set-local-version ()
|
|
|
|
"Set pyenv version from \".python-version\" by looking in parent directories."
|
|
|
|
(interactive)
|
2015-12-20 03:33:24 +00:00
|
|
|
(let ((root-path (locate-dominating-file default-directory
|
|
|
|
".python-version")))
|
|
|
|
(when root-path
|
|
|
|
(let* ((file-path (expand-file-name ".python-version" root-path))
|
|
|
|
(version (with-temp-buffer
|
|
|
|
(insert-file-contents-literally file-path)
|
|
|
|
(current-word))))
|
|
|
|
(if (member version (pyenv-mode-versions))
|
|
|
|
(pyenv-mode-set version)
|
|
|
|
(message "pyenv: version `%s' is not installed (set by %s)"
|
|
|
|
version file-path))))))
|