Some contributions and ideas by Alexander Schmolck: add a keybinding

to call pychecker on the current file, add a face for pseudo
keywords self, None, True, False, and Ellipsis.  Specifically,

(py-pychecker-command, py-pychecker-command-args): New variables.

(py-pseudo-keyword-face): New face variable, defaulting to a copy of
font-lock-keyword-face.

(python-font-lock-keywords): Add an entry for self, None, True, False,
Ellipsis to be rendered in py-pseudo-keyword-face.

(py-pychecker-history): New variable.

(py-mode-map): Bind C-c C-w to py-pychecker-run.

(py-pychecker-run): New command.
This commit is contained in:
Barry Warsaw 2002-04-22 21:48:20 +00:00
parent 030a5cebf4
commit 29a90f0a7a

View file

@ -286,6 +286,18 @@ relative path, the value of variable `default-directory' for the
buffer is prepended to come up with a file name.") buffer is prepended to come up with a file name.")
(make-variable-buffer-local 'py-master-file) (make-variable-buffer-local 'py-master-file)
(defcustom py-pychecker-command "pychecker"
"*Shell command used to run Pychecker."
:type 'string
:group 'python
:tag "Pychecker Command")
(defcustom py-pychecker-command-args '("--stdlib")
"*List of string arguments to be passed to pychecker."
:type '(repeat string)
:group 'python
:tag "Pychecker Command Args")
;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -298,6 +310,16 @@ buffer is prepended to come up with a file name.")
There are many flavors of Emacs out there, with different levels of There are many flavors of Emacs out there, with different levels of
support for features needed by `python-mode'.") support for features needed by `python-mode'.")
;; Face for None, True, False, self, and Ellipsis
(defvar py-pseudo-keyword-face 'py-pseudo-keyword-face
"Face for pseudo keywords in Python mode, like self, True, False, Ellipsis.")
(make-face 'py-pseudo-keyword-face)
(defun py-font-lock-mode-hook ()
(or (face-differs-from-default-p 'py-pseudo-keyword-face)
(copy-face 'font-lock-keyword-face 'py-pseudo-keyword-face)))
(add-hook 'font-lock-mode-hook 'py-font-lock-mode-hook)
(defvar python-font-lock-keywords (defvar python-font-lock-keywords
(let ((kw1 (mapconcat 'identity (let ((kw1 (mapconcat 'identity
'("and" "assert" "break" "class" '("and" "assert" "break" "class"
@ -327,6 +349,9 @@ support for features needed by `python-mode'.")
;; functions ;; functions
'("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" '("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
1 font-lock-function-name-face) 1 font-lock-function-name-face)
;; pseudo-keywords
'("\\b\\(self\\|None\\|True\\|False\\|Ellipsis\\)\\b"
1 py-pseudo-keyword-face)
)) ))
"Additional expressions to highlight in Python mode.") "Additional expressions to highlight in Python mode.")
(put 'python-mode 'font-lock-defaults '(python-font-lock-keywords)) (put 'python-mode 'font-lock-defaults '(python-font-lock-keywords))
@ -337,6 +362,7 @@ support for features needed by `python-mode'.")
Currently-active file is at the head of the list.") Currently-active file is at the head of the list.")
(defvar py-pdbtrack-is-tracking-p nil) (defvar py-pdbtrack-is-tracking-p nil)
(defvar py-pychecker-history nil)
@ -509,6 +535,7 @@ Currently-active file is at the head of the list.")
;; information ;; information
(define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report) (define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
(define-key py-mode-map "\C-c\C-v" 'py-version) (define-key py-mode-map "\C-c\C-v" 'py-version)
(define-key py-mode-map "\C-c\C-w" 'py-pychecker-run)
;; shadow global bindings for newline-and-indent w/ the py- version. ;; shadow global bindings for newline-and-indent w/ the py- version.
;; BAW - this is extremely bad form, but I'm not going to change it ;; BAW - this is extremely bad form, but I'm not going to change it
;; for now. ;; for now.
@ -1424,9 +1451,7 @@ is inserted at the end. See also the command `py-clear-queue'."
(if err-p (if err-p
(pop-to-buffer py-exception-buffer))) (pop-to-buffer py-exception-buffer)))
)) ))
;; TBD: delete the buffer ))
)
)
;; Clean up after ourselves. ;; Clean up after ourselves.
(kill-buffer buf))) (kill-buffer buf)))
@ -2609,12 +2634,30 @@ A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
;; Skip's python-help commands. The guts of this function is stolen ;; Pychecker
;; from XEmacs's symbol-near-point, but without the useless (defun py-pychecker-run (command)
;; regexp-quote call on the results, nor the interactive bit. Also, "*Run pychecker (default on the file currently visited)."
;; we've added the temporary syntax table setting, which Skip (interactive
;; originally had broken out into a separate function. Note that (let ((default
;; Emacs doesn't have the original function. (format "%s %s %s" py-pychecker-command
(mapconcat 'identity py-pychecker-command-args " ")
(buffer-file-name))))
(list
(read-shell-command "Run pychecker like this: "
default
py-pychecker-history))))
(save-some-buffers (not py-ask-about-save) nil)
(compile command))
;; pydoc commands. The guts of this function is stolen from XEmacs's
;; symbol-near-point, but without the useless regexp-quote call on the
;; results, nor the interactive bit. Also, we've added the temporary
;; syntax table setting, which Skip originally had broken out into a
;; separate function. Note that Emacs doesn't have the original
;; function.
(defun py-symbol-near-point () (defun py-symbol-near-point ()
"Return the first textual item to the nearest point." "Return the first textual item to the nearest point."
;; alg stolen from etag.el ;; alg stolen from etag.el