# HG changeset patch # User Stefan Monnier # Date 1208462994 0 # Node ID 1e40bf35d15ef13e7548357ced14227d489202b4 # Parent b6c3fde83add890545c99e13b40c8bef7e167b56 (python-mode-map): Use abbrev-table-menu. (python-use-skeletons): Remove, unused. (python-skeletons): Remove. Use the abbrev table instead. (python-mode-abbrev-table): Fix regexp; add enable-function and case-fixed. (def-python-skeleton): Simplify. (python-expand-template): Use the abbrev-table and abbrev-insert. (python-abbrev-pc-hook, python-abbrev-syntax-table, python-pea-hook): Remove. (python-mode): Don't set pre-abbrev-expand-hook. diff -r b6c3fde83add -r 1e40bf35d15e lisp/ChangeLog --- a/lisp/ChangeLog Thu Apr 17 19:54:57 2008 +0000 +++ b/lisp/ChangeLog Thu Apr 17 20:09:54 2008 +0000 @@ -1,5 +1,15 @@ 2008-04-17 Stefan Monnier + * progmodes/python.el (python-mode-map): Use abbrev-table-menu. + (python-use-skeletons): Remove, unused. + (python-skeletons): Remove. Use the abbrev table instead. + (python-mode-abbrev-table): Fix regexp; add enable-function and case-fixed. + (def-python-skeleton): Simplify. + (python-expand-template): Use the abbrev-table and abbrev-insert. + (python-abbrev-pc-hook, python-abbrev-syntax-table, python-pea-hook): + Remove. + (python-mode): Don't set pre-abbrev-expand-hook. + * skeleton.el: Set coding-tag. * abbrev.el (abbrev-insert): New function extracted from expand-abbrev. diff -r b6c3fde83add -r 1e40bf35d15e lisp/progmodes/python.el --- a/lisp/progmodes/python.el Thu Apr 17 19:54:57 2008 +0000 +++ b/lisp/progmodes/python.el Thu Apr 17 20:09:54 2008 +0000 @@ -296,9 +296,7 @@ ("Templates..." :help "Expand templates for compound statements" :filter (lambda (&rest junk) - (mapcar (lambda (elt) - (vector (car elt) (cdr elt) t)) - python-skeletons))) ; defined later + (abbrev-table-menu python-mode-abbrev-table))) "-" ["Start interpreter" python-shell :help "Run `inferior' Python in separate buffer"] @@ -2202,39 +2200,24 @@ ;;;; Skeletons -(defcustom python-use-skeletons nil - "Non-nil means template skeletons will be automagically inserted. -This happens when pressing \"if\", for example, to prompt for -the if condition." - :type 'boolean - :group 'python) - -(defvar python-skeletons nil - "Alist of named skeletons for Python mode. -Elements are of the form (NAME . EXPANDER-FUNCTION).") - (define-abbrev-table 'python-mode-abbrev-table () - "Abbrev table for Python mode. -The default contents correspond to the elements of `python-skeletons'." - ;; Allow / in abbrevs. - :regexp "\\<\\([[:word:]/]+\\)\\W*") + "Abbrev table for Python mode." + :case-fixed t + ;; Allow / inside abbrevs. + :regexp "\\(?:^\\|[^/]\\)\\<\\([[:word:]/]+\\)\\W*" + ;; Only expand in code. + :enable-function (lambda () (not (python-in-string/comment)))) (eval-when-compile - ;; Define a user-level skeleton and add it to `python-skeletons' and - ;; the abbrev table. + ;; Define a user-level skeleton and add it to the abbrev table. (defmacro def-python-skeleton (name &rest elements) (let* ((name (symbol-name name)) (function (intern (concat "python-insert-" name)))) `(progn - (add-to-list 'python-skeletons ',(cons name function)) ;; Usual technique for inserting a skeleton, but expand ;; to the original abbrev instead if in a comment or string. (define-abbrev python-mode-abbrev-table ,name "" - ;; Quote this to give a readable abbrev table. - '(lambda () - (if (python-in-string/comment) - (insert ,name) - (,function))) + ',function nil t) ; system abbrev (define-skeleton ,function ,(format "Insert Python \"%s\" template." name) @@ -2327,13 +2310,14 @@ (interactive (list (completing-read (format "Template to expand (default %s): " python-default-template) - python-skeletons nil t))) + python-mode-abbrev-table nil t nil nil + python-default-template))) (if (equal "" name) (setq name python-default-template) (setq python-default-template name)) - (let ((func (cdr (assoc name python-skeletons)))) - (if func - (funcall func) + (let ((sym (abbrev-symbol name python-mode-abbrev-table))) + (if sym + (abbrev-insert sym) (error "Undefined template: %s" name)))) ;;;; Bicycle Repair Man support @@ -2397,22 +2381,6 @@ (defvar eldoc-documentation-function) (defvar python-mode-running) ;Dynamically scoped var. -;; Stuff to allow expanding abbrevs with non-word constituents. -(defun python-abbrev-pc-hook () - "Reset the syntax table after possibly expanding abbrevs." - (remove-hook 'post-command-hook 'python-abbrev-pc-hook t) - (set-syntax-table python-mode-syntax-table)) - -(defvar python-abbrev-syntax-table - (copy-syntax-table python-mode-syntax-table) - "Syntax table used when expanding abbrevs.") - -(defun python-pea-hook () - "Set the syntax table before possibly expanding abbrevs." - (set-syntax-table python-abbrev-syntax-table) - (add-hook 'post-command-hook 'python-abbrev-pc-hook nil t)) -(modify-syntax-entry ?/ "w" python-abbrev-syntax-table) - ;;;###autoload (define-derived-mode python-mode fundamental-mode "Python" "Major mode for editing Python files. @@ -2503,7 +2471,6 @@ '((< '(backward-delete-char-untabify (min python-indent (current-column)))) (^ '(- (1+ (current-indentation)))))) - (add-hook 'pre-abbrev-expand-hook 'python-pea-hook nil t) (if (featurep 'hippie-exp) (set (make-local-variable 'hippie-expand-try-functions-list) (cons 'symbol-completion-try-complete