diff options
| author | Stefan Monnier | 2013-04-16 13:28:11 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-04-16 13:28:11 -0400 |
| commit | 351edece98dcafbfa9237ffc07a63b181877d6ac (patch) | |
| tree | 6d235b0c39ec355fa4698f491b8964378df74336 | |
| parent | 613f948181f88d8180f136c73cdfd8d811329452 (diff) | |
| download | emacs-351edece98dcafbfa9237ffc07a63b181877d6ac.tar.gz emacs-351edece98dcafbfa9237ffc07a63b181877d6ac.zip | |
* 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.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/abbrev.el | 42 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 14 |
3 files changed, 46 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3df05a7a37a..68ac8721bb2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2013-04-16 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * progmodes/python.el (python-mode-skeleton-abbrev-table): Rename from | ||
| 4 | python-mode-abbrev-table. | ||
| 5 | (python-skeleton-define): Adjust accordingly. | ||
| 6 | (python-mode-abbrev-table): New table that inherits from it so that | ||
| 7 | python-skeleton-autoinsert does not affect non-skeleton abbrevs. | ||
| 8 | |||
| 9 | * abbrev.el (abbrev--symbol): New function, extracted from abbrev-symbol. | ||
| 10 | (abbrev-symbol): Use it. | ||
| 11 | (abbrev--before-point): Use it since we already handle inheritance. | ||
| 12 | |||
| 1 | 2013-04-16 Leo Liu <sdl.web@gmail.com> | 13 | 2013-04-16 Leo Liu <sdl.web@gmail.com> |
| 2 | 14 | ||
| 3 | * progmodes/octave-mod.el (octave-mode-map): Remove redundant key | 15 | * progmodes/octave-mod.el (octave-mode-map): Remove redundant key |
diff --git a/lisp/abbrev.el b/lisp/abbrev.el index bd09653103f..cc7ebe489f7 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el | |||
| @@ -669,6 +669,26 @@ either a single abbrev table or a list of abbrev tables." | |||
| 669 | tables)))) | 669 | tables)))) |
| 670 | 670 | ||
| 671 | 671 | ||
| 672 | (defun abbrev--symbol (abbrev table) | ||
| 673 | "Return the symbol representing abbrev named ABBREV in TABLE. | ||
| 674 | This symbol's name is ABBREV, but it is not the canonical symbol of that name; | ||
| 675 | it is interned in the abbrev-table TABLE rather than the normal obarray. | ||
| 676 | The value is nil if that abbrev is not defined." | ||
| 677 | (let* ((case-fold (not (abbrev-table-get table :case-fixed))) | ||
| 678 | ;; In case the table doesn't set :case-fixed but some of the | ||
| 679 | ;; abbrevs do, we have to be careful. | ||
| 680 | (sym | ||
| 681 | ;; First try without case-folding. | ||
| 682 | (or (intern-soft abbrev table) | ||
| 683 | (when case-fold | ||
| 684 | ;; We didn't find any abbrev, try case-folding. | ||
| 685 | (let ((sym (intern-soft (downcase abbrev) table))) | ||
| 686 | ;; Only use it if it doesn't require :case-fixed. | ||
| 687 | (and sym (not (abbrev-get sym :case-fixed)) | ||
| 688 | sym)))))) | ||
| 689 | (if (symbol-value sym) | ||
| 690 | sym))) | ||
| 691 | |||
| 672 | (defun abbrev-symbol (abbrev &optional table) | 692 | (defun abbrev-symbol (abbrev &optional table) |
| 673 | "Return the symbol representing abbrev named ABBREV. | 693 | "Return the symbol representing abbrev named ABBREV. |
| 674 | This symbol's name is ABBREV, but it is not the canonical symbol of that name; | 694 | 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. | |||
| 678 | The default is to try buffer's mode-specific abbrev table, then global table." | 698 | The default is to try buffer's mode-specific abbrev table, then global table." |
| 679 | (let ((tables (abbrev--active-tables table)) | 699 | (let ((tables (abbrev--active-tables table)) |
| 680 | sym) | 700 | sym) |
| 681 | (while (and tables (not (symbol-value sym))) | 701 | (while (and tables (not sym)) |
| 682 | (let* ((table (pop tables)) | 702 | (let* ((table (pop tables))) |
| 683 | (case-fold (not (abbrev-table-get table :case-fixed)))) | ||
| 684 | (setq tables (append (abbrev-table-get table :parents) tables)) | 703 | (setq tables (append (abbrev-table-get table :parents) tables)) |
| 685 | ;; In case the table doesn't set :case-fixed but some of the | 704 | (setq sym (abbrev--symbol abbrev table)))) |
| 686 | ;; abbrevs do, we have to be careful. | 705 | sym)) |
| 687 | (setq sym | ||
| 688 | ;; First try without case-folding. | ||
| 689 | (or (intern-soft abbrev table) | ||
| 690 | (when case-fold | ||
| 691 | ;; We didn't find any abbrev, try case-folding. | ||
| 692 | (let ((sym (intern-soft (downcase abbrev) table))) | ||
| 693 | ;; Only use it if it doesn't require :case-fixed. | ||
| 694 | (and sym (not (abbrev-get sym :case-fixed)) | ||
| 695 | sym))))))) | ||
| 696 | (if (symbol-value sym) | ||
| 697 | sym))) | ||
| 698 | 706 | ||
| 699 | 707 | ||
| 700 | (defun abbrev-expansion (abbrev &optional table) | 708 | (defun abbrev-expansion (abbrev &optional table) |
| @@ -748,7 +756,7 @@ then ABBREV is looked up in that table only." | |||
| 748 | (setq start (match-beginning 1)) | 756 | (setq start (match-beginning 1)) |
| 749 | (setq end (match-end 1))))) | 757 | (setq end (match-end 1))))) |
| 750 | (setq name (buffer-substring start end)) | 758 | (setq name (buffer-substring start end)) |
| 751 | (let ((abbrev (abbrev-symbol name table))) | 759 | (let ((abbrev (abbrev--symbol name table))) |
| 752 | (when abbrev | 760 | (when abbrev |
| 753 | (setq enable-fun (abbrev-get abbrev :enable-function)) | 761 | (setq enable-fun (abbrev-get abbrev :enable-function)) |
| 754 | (and (or (not enable-fun) (funcall enable-fun)) | 762 | (and (or (not enable-fun) (funcall enable-fun)) |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d1009534e49..fde7fadd061 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2654,8 +2654,8 @@ the if condition." | |||
| 2654 | (defvar python-skeleton-available '() | 2654 | (defvar python-skeleton-available '() |
| 2655 | "Internal list of available skeletons.") | 2655 | "Internal list of available skeletons.") |
| 2656 | 2656 | ||
| 2657 | (define-abbrev-table 'python-mode-abbrev-table () | 2657 | (define-abbrev-table 'python-mode-skeleton-abbrev-table () |
| 2658 | "Abbrev table for Python mode." | 2658 | "Abbrev table for Python mode skeletons." |
| 2659 | :case-fixed t | 2659 | :case-fixed t |
| 2660 | ;; Allow / inside abbrevs. | 2660 | ;; Allow / inside abbrevs. |
| 2661 | :regexp "\\(?:^\\|[^/]\\)\\<\\([[:word:]/]+\\)\\W*" | 2661 | :regexp "\\(?:^\\|[^/]\\)\\<\\([[:word:]/]+\\)\\W*" |
| @@ -2668,13 +2668,13 @@ the if condition." | |||
| 2668 | (defmacro python-skeleton-define (name doc &rest skel) | 2668 | (defmacro python-skeleton-define (name doc &rest skel) |
| 2669 | "Define a `python-mode' skeleton using NAME DOC and SKEL. | 2669 | "Define a `python-mode' skeleton using NAME DOC and SKEL. |
| 2670 | The skeleton will be bound to python-skeleton-NAME and will | 2670 | The skeleton will be bound to python-skeleton-NAME and will |
| 2671 | be added to `python-mode-abbrev-table'." | 2671 | be added to `python-mode-skeleton-abbrev-table'." |
| 2672 | (declare (indent 2)) | 2672 | (declare (indent 2)) |
| 2673 | (let* ((name (symbol-name name)) | 2673 | (let* ((name (symbol-name name)) |
| 2674 | (function-name (intern (concat "python-skeleton-" name)))) | 2674 | (function-name (intern (concat "python-skeleton-" name)))) |
| 2675 | `(progn | 2675 | `(progn |
| 2676 | (define-abbrev python-mode-abbrev-table ,name "" ',function-name | 2676 | (define-abbrev python-mode-skeleton-abbrev-table |
| 2677 | :system t) | 2677 | ,name "" ',function-name :system t) |
| 2678 | (setq python-skeleton-available | 2678 | (setq python-skeleton-available |
| 2679 | (cons ',function-name python-skeleton-available)) | 2679 | (cons ',function-name python-skeleton-available)) |
| 2680 | (define-skeleton ,function-name | 2680 | (define-skeleton ,function-name |
| @@ -2682,6 +2682,10 @@ be added to `python-mode-abbrev-table'." | |||
| 2682 | (format "Insert %s statement." name)) | 2682 | (format "Insert %s statement." name)) |
| 2683 | ,@skel)))) | 2683 | ,@skel)))) |
| 2684 | 2684 | ||
| 2685 | (define-abbrev-table 'python-mode-abbrev-table () | ||
| 2686 | "Abbrev table for Python mode." | ||
| 2687 | :parents (list python-mode-skeleton-abbrev-table)) | ||
| 2688 | |||
| 2685 | (defmacro python-define-auxiliary-skeleton (name doc &optional &rest skel) | 2689 | (defmacro python-define-auxiliary-skeleton (name doc &optional &rest skel) |
| 2686 | "Define a `python-mode' auxiliary skeleton using NAME DOC and SKEL. | 2690 | "Define a `python-mode' auxiliary skeleton using NAME DOC and SKEL. |
| 2687 | The skeleton will be bound to python-skeleton-NAME." | 2691 | The skeleton will be bound to python-skeleton-NAME." |