mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-17 10:27:41 +00:00
* 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.
This commit is contained in:
parent
613f948181
commit
351edece98
3 changed files with 46 additions and 22 deletions
|
|
@ -1,3 +1,15 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Reference in a new issue