+2013-04-16 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * progmodes/python.el (python-mode-skeleton-abbrev-table): Rename from
+ python-mode-abbrev-table.
+ (python-skeleton-define): Adjust accordingly.
+ (python-mode-abbrev-table): New table that inherits from it so that
+ python-skeleton-autoinsert does not affect non-skeleton abbrevs.
+
+ * abbrev.el (abbrev--symbol): New function, extracted from abbrev-symbol.
+ (abbrev-symbol): Use it.
+ (abbrev--before-point): Use it since we already handle inheritance.
+
2013-04-16 Leo Liu <sdl.web@gmail.com>
* progmodes/octave-mod.el (octave-mode-map): Remove redundant key
tables))))
+(defun abbrev--symbol (abbrev table)
+ "Return the symbol representing abbrev named ABBREV in TABLE.
+This symbol's name is ABBREV, but it is not the canonical symbol of that name;
+it is interned in the abbrev-table TABLE rather than the normal obarray.
+The value is nil if that abbrev is not defined."
+ (let* ((case-fold (not (abbrev-table-get table :case-fixed)))
+ ;; In case the table doesn't set :case-fixed but some of the
+ ;; abbrevs do, we have to be careful.
+ (sym
+ ;; First try without case-folding.
+ (or (intern-soft abbrev table)
+ (when case-fold
+ ;; We didn't find any abbrev, try case-folding.
+ (let ((sym (intern-soft (downcase abbrev) table)))
+ ;; Only use it if it doesn't require :case-fixed.
+ (and sym (not (abbrev-get sym :case-fixed))
+ sym))))))
+ (if (symbol-value sym)
+ sym)))
+
(defun abbrev-symbol (abbrev &optional table)
"Return the symbol representing abbrev named ABBREV.
This symbol's name is ABBREV, but it is not the canonical symbol of that name;
The default is to try buffer's mode-specific abbrev table, then global table."
(let ((tables (abbrev--active-tables table))
sym)
- (while (and tables (not (symbol-value sym)))
- (let* ((table (pop tables))
- (case-fold (not (abbrev-table-get table :case-fixed))))
+ (while (and tables (not sym))
+ (let* ((table (pop tables)))
(setq tables (append (abbrev-table-get table :parents) tables))
- ;; In case the table doesn't set :case-fixed but some of the
- ;; abbrevs do, we have to be careful.
- (setq sym
- ;; First try without case-folding.
- (or (intern-soft abbrev table)
- (when case-fold
- ;; We didn't find any abbrev, try case-folding.
- (let ((sym (intern-soft (downcase abbrev) table)))
- ;; Only use it if it doesn't require :case-fixed.
- (and sym (not (abbrev-get sym :case-fixed))
- sym)))))))
- (if (symbol-value sym)
- sym)))
+ (setq sym (abbrev--symbol abbrev table))))
+ sym))
(defun abbrev-expansion (abbrev &optional table)
(setq start (match-beginning 1))
(setq end (match-end 1)))))
(setq name (buffer-substring start end))
- (let ((abbrev (abbrev-symbol name table)))
+ (let ((abbrev (abbrev--symbol name table)))
(when abbrev
(setq enable-fun (abbrev-get abbrev :enable-function))
(and (or (not enable-fun) (funcall enable-fun))
(defvar python-skeleton-available '()
"Internal list of available skeletons.")
-(define-abbrev-table 'python-mode-abbrev-table ()
- "Abbrev table for Python mode."
+(define-abbrev-table 'python-mode-skeleton-abbrev-table ()
+ "Abbrev table for Python mode skeletons."
:case-fixed t
;; Allow / inside abbrevs.
:regexp "\\(?:^\\|[^/]\\)\\<\\([[:word:]/]+\\)\\W*"
(defmacro python-skeleton-define (name doc &rest skel)
"Define a `python-mode' skeleton using NAME DOC and SKEL.
The skeleton will be bound to python-skeleton-NAME and will
-be added to `python-mode-abbrev-table'."
+be added to `python-mode-skeleton-abbrev-table'."
(declare (indent 2))
(let* ((name (symbol-name name))
(function-name (intern (concat "python-skeleton-" name))))
`(progn
- (define-abbrev python-mode-abbrev-table ,name "" ',function-name
- :system t)
+ (define-abbrev python-mode-skeleton-abbrev-table
+ ,name "" ',function-name :system t)
(setq python-skeleton-available
(cons ',function-name python-skeleton-available))
(define-skeleton ,function-name
(format "Insert %s statement." name))
,@skel))))
+(define-abbrev-table 'python-mode-abbrev-table ()
+ "Abbrev table for Python mode."
+ :parents (list python-mode-skeleton-abbrev-table))
+
(defmacro python-define-auxiliary-skeleton (name doc &optional &rest skel)
"Define a `python-mode' auxiliary skeleton using NAME DOC and SKEL.
The skeleton will be bound to python-skeleton-NAME."