comparison lisp/progmodes/python.el @ 91085:880960b70474

Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-283
author Miles Bader <miles@gnu.org>
date Sun, 11 Nov 2007 00:56:44 +0000
parents 4bc33ffdda1a d227ffcaa3fe
children 53108e6cea98
comparison
equal deleted inserted replaced
91084:a4347a111894 91085:880960b70474
2034 2034
2035 (defvar python-skeletons nil 2035 (defvar python-skeletons nil
2036 "Alist of named skeletons for Python mode. 2036 "Alist of named skeletons for Python mode.
2037 Elements are of the form (NAME . EXPANDER-FUNCTION).") 2037 Elements are of the form (NAME . EXPANDER-FUNCTION).")
2038 2038
2039 (defvar python-mode-abbrev-table nil 2039 (define-abbrev-table 'python-mode-abbrev-table ()
2040 "Abbrev table for Python mode. 2040 "Abbrev table for Python mode.
2041 The default contents correspond to the elements of `python-skeletons'.") 2041 The default contents correspond to the elements of `python-skeletons'."
2042 (define-abbrev-table 'python-mode-abbrev-table ()) 2042 ;; Allow / in abbrevs.
2043 :regexp "\\<\\([[:word:]/]+\\)\\W*")
2043 2044
2044 (eval-when-compile 2045 (eval-when-compile
2045 ;; Define a user-level skeleton and add it to `python-skeletons' and 2046 ;; Define a user-level skeleton and add it to `python-skeletons' and
2046 ;; the abbrev table. 2047 ;; the abbrev table.
2047 (defmacro def-python-skeleton (name &rest elements) 2048 (defmacro def-python-skeleton (name &rest elements)
2048 (let* ((name (symbol-name name)) 2049 (let* ((name (symbol-name name))
2049 (function (intern (concat "python-insert-" name)))) 2050 (function (intern (concat "python-insert-" name))))
2050 `(progn 2051 `(progn
2051 (add-to-list 'python-skeletons ',(cons name function)) 2052 (add-to-list 'python-skeletons ',(cons name function))
2052 (if python-use-skeletons 2053 (define-abbrev python-mode-abbrev-table ,name "" ',function
2053 (define-abbrev python-mode-abbrev-table ,name "" ',function nil t)) 2054 :system t :case-fixed t
2055 :enable-function (lambda () python-use-skeletons))
2054 (define-skeleton ,function 2056 (define-skeleton ,function
2055 ,(format "Insert Python \"%s\" template." name) 2057 ,(format "Insert Python \"%s\" template." name)
2056 ,@elements))))) 2058 ,@elements)))))
2057 (put 'def-python-skeleton 'lisp-indent-function 2) 2059 (put 'def-python-skeleton 'lisp-indent-function 2)
2058 2060
2203 2205
2204 ;;;; Modes. 2206 ;;;; Modes.
2205 2207
2206 (defvar outline-heading-end-regexp) 2208 (defvar outline-heading-end-regexp)
2207 (defvar eldoc-documentation-function) 2209 (defvar eldoc-documentation-function)
2208
2209 ;; Stuff to allow expanding abbrevs with non-word constituents.
2210 (defun python-abbrev-pc-hook ()
2211 "Set the syntax table before possibly expanding abbrevs."
2212 (remove-hook 'post-command-hook 'python-abbrev-pc-hook t)
2213 (set-syntax-table python-mode-syntax-table))
2214
2215 (defvar python-abbrev-syntax-table
2216 (copy-syntax-table python-mode-syntax-table)
2217 "Syntax table used when expanding abbrevs.")
2218
2219 (defun python-pea-hook ()
2220 "Reset the syntax table after possibly expanding abbrevs."
2221 (set-syntax-table python-abbrev-syntax-table)
2222 (add-hook 'post-command-hook 'python-abbrev-pc-hook nil t))
2223 (modify-syntax-entry ?/ "w" python-abbrev-syntax-table)
2224
2225 (defvar python-mode-running) ;Dynamically scoped var. 2210 (defvar python-mode-running) ;Dynamically scoped var.
2226 2211
2227 ;;;###autoload 2212 ;;;###autoload
2228 (define-derived-mode python-mode fundamental-mode "Python" 2213 (define-derived-mode python-mode fundamental-mode "Python"
2229 "Major mode for editing Python files. 2214 "Major mode for editing Python files.
2307 nil)) 2292 nil))
2308 (set (make-local-variable 'skeleton-further-elements) 2293 (set (make-local-variable 'skeleton-further-elements)
2309 '((< '(backward-delete-char-untabify (min python-indent 2294 '((< '(backward-delete-char-untabify (min python-indent
2310 (current-column)))) 2295 (current-column))))
2311 (^ '(- (1+ (current-indentation)))))) 2296 (^ '(- (1+ (current-indentation))))))
2312 (add-hook 'pre-abbrev-expand-hook 'python-pea-hook nil t)
2313 (if (featurep 'hippie-exp) 2297 (if (featurep 'hippie-exp)
2314 (set (make-local-variable 'hippie-expand-try-functions-list) 2298 (set (make-local-variable 'hippie-expand-try-functions-list)
2315 (cons 'python-try-complete hippie-expand-try-functions-list))) 2299 (cons 'python-try-complete hippie-expand-try-functions-list)))
2316 ;; Python defines TABs as being 8-char wide. 2300 ;; Python defines TABs as being 8-char wide.
2317 (set (make-local-variable 'tab-width) 8) 2301 (set (make-local-variable 'tab-width) 8)