aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2008-04-17 20:09:54 +0000
committerStefan Monnier <[email protected]>2008-04-17 20:09:54 +0000
commit88bdb6c2e5553df50b622340a2b04ec2b8c637e3 (patch)
treebfcb2efbda6073100d934fc2568f9677e5c75ccc /lisp
parent1a5ed76f16b8f4fc3a9095cf1e61d6aa93f0be4a (diff)
(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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/python.el61
2 files changed, 24 insertions, 47 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 59cc4c71c9..03acc8b0d8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,15 @@
2008-04-17 Stefan Monnier <[email protected]>
+ * 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 --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e9f3dafa2f..15dc73daba 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -296,9 +296,7 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
("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 @@ Interactively, prompt for name."
;;;; Skeletons
-(defcustom python-use-skeletons nil
- "Non-nil means template skeletons will be automagically inserted.
-This happens when pressing \"if<SPACE>\", 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 @@ Interactively, prompt for the name with completion."
(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 @@ without confirmation."
(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 @@ with skeleton expansions for compound statement templates.
'((< '(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