From 351edece98dcafbfa9237ffc07a63b181877d6ac Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 16 Apr 2013 13:28:11 -0400 Subject: [PATCH] * lisp/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. * lisp/abbrev.el (abbrev--symbol): New function, extracted from abbrev-symbol. (abbrev-symbol): Use it. (abbrev--before-point): Use it since we already handle inheritance. --- lisp/ChangeLog | 12 ++++++++++++ lisp/abbrev.el | 42 ++++++++++++++++++++++++---------------- lisp/progmodes/python.el | 14 +++++++++----- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3df05a7a37..68ac8721bb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2013-04-16 Stefan Monnier + + * 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 * progmodes/octave-mod.el (octave-mode-map): Remove redundant key diff --git a/lisp/abbrev.el b/lisp/abbrev.el index bd09653103..cc7ebe489f 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -669,6 +669,26 @@ either a single abbrev table or a list of abbrev tables." 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; @@ -678,23 +698,11 @@ Optional second arg TABLE is abbrev table to look it up in. 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) @@ -748,7 +756,7 @@ then ABBREV is looked up in that table only." (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)) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d1009534e4..fde7fadd06 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2654,8 +2654,8 @@ the if condition." (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*" @@ -2668,13 +2668,13 @@ the if condition." (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 @@ -2682,6 +2682,10 @@ be added to `python-mode-abbrev-table'." (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." -- 2.20.1