2739 except: |
2739 except: |
2740 doc = '' |
2740 doc = '' |
2741 return doc" |
2741 return doc" |
2742 "Python code to setup documentation retrieval.") |
2742 "Python code to setup documentation retrieval.") |
2743 |
2743 |
2744 (defvar my/python-eldoc-string-code "__PYDOC_get_full_help('''%s''')" |
2744 (defvar my-python/eldoc-string-code "__PYDOC_get_full_help('''%s''')" |
2745 "Python code used to get a string with the documentation of an object.") |
2745 "Python code used to get a string with the documentation of an object.") |
2746 |
2746 |
2747 (defvar my/python-eldoc-string-code2 "help(%s); pass" |
2747 (defun my-python/eldoc-at-point (&optional symbol) |
|
2748 "Show full docs for symbol at point." |
|
2749 (interactive |
|
2750 (let ((symbol (python-info-current-symbol t)) |
|
2751 (enable-recursive-minibuffers t)) |
|
2752 (list (read-string (if symbol |
|
2753 (format "Describe symbol (default %s): " symbol) |
|
2754 "Describe symbol: ") |
|
2755 nil nil symbol)))) |
|
2756 (let ( (python-eldoc-string-code my-python/eldoc-string-code) |
|
2757 (python-eldoc-setup-code my-python/eldoc-setup-code) ) |
|
2758 (switch-to-buffer (get-buffer-create "*Python-doc*")) |
|
2759 (read-only-mode -1) |
|
2760 (buffer-disable-undo) |
|
2761 (erase-buffer) |
|
2762 (insert (python-eldoc--get-doc-at-point symbol)) |
|
2763 (goto-char (point-min)) |
|
2764 (when (re-search-forward "^u?['\"]" (line-end-position) t) |
|
2765 (replace-match "")) |
|
2766 (while (re-search-forward "\\\\n" nil t) |
|
2767 (replace-match "\n")) |
|
2768 (goto-char (point-min)) |
|
2769 (while (re-search-forward "\\\\'" nil t) |
|
2770 (replace-match "['\"]")) |
|
2771 (goto-char (point-max)) |
|
2772 (when (eq ?' (char-before)) |
|
2773 (delete-char -1)) |
|
2774 (read-only-mode 1) |
|
2775 (goto-char (point-min)))) |
|
2776 |
|
2777 (defvar my-python/eldoc-string-code2 "help(%s); pass" |
2748 "Python code used to get a string with the documentation of an object.") |
2778 "Python code used to get a string with the documentation of an object.") |
|
2779 |
|
2780 (defun my-python/eldoc-at-point2 (&optional symbol) |
|
2781 "Show full docs for symbol at point." |
|
2782 (interactive |
|
2783 (let ((symbol (python-info-current-symbol t)) |
|
2784 (enable-recursive-minibuffers t)) |
|
2785 (list (read-string (if symbol |
|
2786 (format "Describe symbol (default %s): " symbol) |
|
2787 "Describe symbol: ") |
|
2788 nil nil symbol)))) |
|
2789 (let ( ) |
|
2790 (switch-to-buffer (get-buffer-create "*Python-doc*")) |
|
2791 (read-only-mode -1) |
|
2792 (buffer-disable-undo) |
|
2793 (erase-buffer) |
|
2794 (insert (python-shell-send-string-no-output (format my-python/eldoc-string-code2 symbol) (python-shell-get-process))) |
|
2795 (goto-char (point-min)) |
|
2796 (when (re-search-forward "^u?'" (line-end-position) t) |
|
2797 (replace-match "")) |
|
2798 (while (re-search-forward "\\\\n" nil t) |
|
2799 (replace-match "\n")) |
|
2800 (goto-char (point-min)) |
|
2801 (while (re-search-forward "\\\\'" nil t) |
|
2802 (replace-match "'")) |
|
2803 (goto-char (point-max)) |
|
2804 (when (eq ?' (char-before)) |
|
2805 (delete-char -1)) |
|
2806 (read-only-mode 1) |
|
2807 (goto-char (point-min)))) |
|
2808 |
|
2809 (defun my-python/send-paragraph () |
|
2810 (interactive) |
|
2811 (save-excursion |
|
2812 (mark-paragraph) |
|
2813 (python-shell-send-region (point) (mark)))) |
2749 |
2814 |
2750 ;; For built-in python.el |
2815 ;; For built-in python.el |
2751 (my--eval-after-load python |
2816 (my--eval-after-load python |
2752 (add-to-list 'python-shell-setup-codes 'my/python-eldoc-setup-code) ; Used inside (python-shell-send-setup-code) |
2817 (add-to-list 'python-shell-setup-codes 'my-python/eldoc-setup-code) ; Used inside (python-shell-send-setup-code) |
2753 (defun my/python-eldoc-at-point (&optional symbol) |
2818 (define-key python-mode-map "\C-c\C-d" 'my-python/eldoc-at-point) |
2754 "Show full docs for symbol at point." |
2819 (define-key python-mode-map "\C-c\C-g" 'my-python/eldoc-at-point2) |
2755 (interactive |
|
2756 (let ((symbol (python-info-current-symbol t)) |
|
2757 (enable-recursive-minibuffers t)) |
|
2758 (list (read-string (if symbol |
|
2759 (format "Describe symbol (default %s): " symbol) |
|
2760 "Describe symbol: ") |
|
2761 nil nil symbol)))) |
|
2762 (let ( (python-eldoc-string-code my/python-eldoc-string-code) |
|
2763 (python-eldoc-setup-code my/python-eldoc-setup-code) ) |
|
2764 (switch-to-buffer (get-buffer-create "*Python-doc*")) |
|
2765 (read-only-mode -1) |
|
2766 (buffer-disable-undo) |
|
2767 (erase-buffer) |
|
2768 (insert (python-eldoc--get-doc-at-point symbol)) |
|
2769 (goto-char (point-min)) |
|
2770 (when (re-search-forward "^u?['\"]" (line-end-position) t) |
|
2771 (replace-match "")) |
|
2772 (while (re-search-forward "\\\\n" nil t) |
|
2773 (replace-match "\n")) |
|
2774 (goto-char (point-min)) |
|
2775 (while (re-search-forward "\\\\'" nil t) |
|
2776 (replace-match "['\"]")) |
|
2777 (goto-char (point-max)) |
|
2778 (when (eq ?' (char-before)) |
|
2779 (delete-char -1)) |
|
2780 (read-only-mode 1) |
|
2781 (goto-char (point-min)))) |
|
2782 (define-key python-mode-map "\C-c\C-d" 'my/python-eldoc-at-point) |
|
2783 (defun my/python-eldoc-at-point2 (&optional symbol) |
|
2784 "Show full docs for symbol at point." |
|
2785 (interactive |
|
2786 (let ((symbol (python-info-current-symbol t)) |
|
2787 (enable-recursive-minibuffers t)) |
|
2788 (list (read-string (if symbol |
|
2789 (format "Describe symbol (default %s): " symbol) |
|
2790 "Describe symbol: ") |
|
2791 nil nil symbol)))) |
|
2792 (let ( ) |
|
2793 (switch-to-buffer (get-buffer-create "*Python-doc*")) |
|
2794 (read-only-mode -1) |
|
2795 (buffer-disable-undo) |
|
2796 (erase-buffer) |
|
2797 (insert (python-shell-send-string-no-output (format my/python-eldoc-string-code2 symbol) (python-shell-get-process))) |
|
2798 (goto-char (point-min)) |
|
2799 (when (re-search-forward "^u?'" (line-end-position) t) |
|
2800 (replace-match "")) |
|
2801 (while (re-search-forward "\\\\n" nil t) |
|
2802 (replace-match "\n")) |
|
2803 (goto-char (point-min)) |
|
2804 (while (re-search-forward "\\\\'" nil t) |
|
2805 (replace-match "'")) |
|
2806 (goto-char (point-max)) |
|
2807 (when (eq ?' (char-before)) |
|
2808 (delete-char -1)) |
|
2809 (read-only-mode 1) |
|
2810 (goto-char (point-min)))) |
|
2811 (define-key python-mode-map "\C-c\C-g" 'my/python-eldoc-at-point2) |
|
2812 |
|
2813 (defun my-python/send-paragraph () |
|
2814 (interactive) |
|
2815 (save-excursion |
|
2816 (mark-paragraph) |
|
2817 (python-shell-send-region (point) (mark)))) |
|
2818 (define-key python-mode-map [?\C-c ?\C-h] 'my-python/send-paragraph)) |
2820 (define-key python-mode-map [?\C-c ?\C-h] 'my-python/send-paragraph)) |
2819 |
2821 |
2820 (defgroup my/python nil |
2822 (defgroup my/python nil |
2821 "My Python extentions in Emacs." |
2823 "My Python extentions in Emacs." |
2822 :group 'python) |
2824 :group 'python) |
2823 |
2825 |
2824 (defvar my/python-pylint-command "pylint" |
2826 (defvar my-python/pylint-command "pylint" |
2825 "Command to run pylint executable.") |
2827 "Command to run pylint executable.") |
2826 (defvar my/python-pylint-args "-f parseable" |
2828 (defvar my-python/pylint-args "-f parseable" |
2827 "Arguments to pass to pylint executable.") |
2829 "Arguments to pass to pylint executable.") |
2828 |
2830 |
2829 (defvar my/python-pep8-command "pep8" |
2831 (defvar my-python/pep8-command "pep8" |
2830 "Command to run pep8 executable.") |
2832 "Command to run pep8 executable.") |
2831 (defvar my/python-pep8-args "" |
2833 (defvar my-python/pep8-args "" |
2832 "Arguments to pass to pep8 executable.") |
2834 "Arguments to pass to pep8 executable.") |
2833 |
2835 |
2834 (defvar my/python-pyflakes-command "pyflakes" |
2836 (defvar my-python/pyflakes-command "pyflakes" |
2835 "Command to run pyflakes executable.") |
2837 "Command to run pyflakes executable.") |
2836 (defvar my/python-pyflakes-args "" |
2838 (defvar my-python/pyflakes-args "" |
2837 "Arguments to pass to pyflakes executable.") |
2839 "Arguments to pass to pyflakes executable.") |
2838 |
2840 |
2839 (defvar my/python-checker-alist |
2841 (defvar my-python/checker-alist |
2840 '((pylint . (my/python-pylint-command my/python-pylint-args)) |
2842 '((pylint . (my-python/pylint-command my-python/pylint-args)) |
2841 (pep8 . (my/python-pep8-command my/python-pep8-args)) |
2843 (pep8 . (my-python/pep8-command my-python/pep8-args)) |
2842 (pyflakes . (my/python-pyflakes-command my/python-pyflakes-args))) |
2844 (pyflakes . (my-python/pyflakes-command my-python/pyflakes-args))) |
2843 "Known Python source code checkers.") |
2845 "Known Python source code checkers.") |
2844 |
2846 |
2845 (defcustom my/python-default-checker 'pyflakes |
2847 (defcustom my-python/default-checker 'pyflakes |
2846 "Default Python source code checker. See `my/python-checker-alist' for full alist." |
2848 "Default Python source code checker. See `my-python/checker-alist' for full alist." |
2847 :group 'my/python |
2849 :group 'my/python |
2848 :type (cons 'choice (mapcar (lambda (e) (cons 'const e)) my/python-checker-alist))) |
2850 :type (cons 'choice (mapcar (lambda (e) (cons 'const e)) my-python/checker-alist))) |
2849 |
2851 |
2850 (defvar my/python-check-history nil) |
2852 (defvar my-python/check-history nil) |
2851 |
2853 |
2852 (defun my/python-check (&optional checker) |
2854 (defun my-python/check (&optional checker) |
2853 (interactive |
2855 (interactive |
2854 (list |
2856 (list |
2855 (completing-read "Select cheker: " (mapcar (lambda (e) (car e)) my/python-checker-alist) nil t (symbol-name my/python-default-checker) 'my/python-check-history))) |
2857 (completing-read "Select cheker: " (mapcar (lambda (e) (car e)) my-python/checker-alist) nil t (symbol-name my-python/default-checker) 'my-python/check-history))) |
2856 (let ( entry ) |
2858 (let ( entry ) |
2857 (unless (setq entry (cdr (assoc (intern-soft checker) my/python-checker-alist))) |
2859 (unless (setq entry (cdr (assoc (intern-soft checker) my-python/checker-alist))) |
2858 (error "Unknown checker...")) |
2860 (error "Unknown checker...")) |
2859 (compilation-start (format "%s %s %s" (symbol-value (car entry)) (symbol-value (cadr entry)) (shell-quote-argument (buffer-file-name)))))) |
2861 (compilation-start (format "%s %s %s" (symbol-value (car entry)) (symbol-value (cadr entry)) (shell-quote-argument (buffer-file-name)))))) |
2860 |
2862 |
2861 (my--eval-after-load python |
2863 (my--eval-after-load python |
2862 (define-key python-mode-map [?\C-c ?\C-v] #'my/python-check)) |
2864 (define-key python-mode-map [?\C-c ?\C-v] #'my-python/check)) |
2863 |
2865 |
2864 ;; For 3rd party python-mode.el. |
2866 ;; For 3rd party python-mode.el. |
2865 (my--eval-after-load python-mode |
2867 (my--eval-after-load python-mode |
2866 (when (and (boundp 'py-version) (equal py-version "5.1.0")) |
2868 (when (and (boundp 'py-version) (equal py-version "5.1.0")) |
2867 ;; (py-toggle-shells 'cpython) |
2869 ;; (py-toggle-shells 'cpython) |