X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/cb753c3ace486a17e1f3fbb3cbee29dfd20ae68d..2d44e7fef7e7388759518cba1a424495119679d1:/packages/company/company-template.el diff --git a/packages/company/company-template.el b/packages/company/company-template.el index 6ffd648f3..576b246ec 100644 --- a/packages/company/company-template.el +++ b/packages/company/company-template.el @@ -1,6 +1,6 @@ ;;; company-template.el -;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2009, 2010, 2013 Free Software Foundation, Inc. ;; Author: Nikolaj Schumacher @@ -21,7 +21,7 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(require 'cl-lib) (defface company-template-field '((((background dark)) (:background "yellow" :foreground "black")) @@ -32,8 +32,11 @@ (defvar company-template-nav-map (let ((keymap (make-sparse-keymap))) (define-key keymap [tab] 'company-template-forward-field) + (define-key keymap (kbd "TAB") 'company-template-forward-field) keymap)) +(defvar-local company-template--buffer-templates nil) + ;; interactive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun company-template-templates-at (pos) @@ -55,8 +58,8 @@ (let* ((start (point)) (templates (company-template-templates-at (point))) (minimum (apply 'max (mapcar 'overlay-end templates))) - (fields (loop for templ in templates - append (overlay-get templ 'company-template-fields)))) + (fields (cl-loop for templ in templates + append (overlay-get templ 'company-template-fields)))) (dolist (pos (mapcar 'overlay-start fields)) (and pos (> pos (point)) @@ -67,15 +70,12 @@ (company-template-remove-field (company-template-field-at start)))) (defun company-template-field-at (&optional point) - (loop for ovl in (overlays-at (or point (point))) - when (overlay-get ovl 'company-template-parent) - return ovl)) + (cl-loop for ovl in (overlays-at (or point (point))) + when (overlay-get ovl 'company-template-parent) + return ovl)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defvar company-template--buffer-templates nil) -(make-variable-buffer-local 'company-template--buffer-templates) - (defun company-template-declare-template (beg end) (let ((ov (make-overlay beg end))) ;; (overlay-put ov 'face 'highlight) @@ -97,7 +97,7 @@ "Add new field to template TEMPL at POS, inserting TEXT. When DISPLAY is non-nil, set the respective property on the overlay. Leave point at the end of the field." - (assert templ) + (cl-assert templ) (goto-char pos) (insert text) (when (> (point) (overlay-end templ)) @@ -134,7 +134,7 @@ Leave point at the end of the field." ;; hooks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun company-template-insert-hook (ovl after-p &rest ignore) +(defun company-template-insert-hook (ovl after-p &rest _ignore) "Called when a snippet input prompt is modified." (unless after-p (company-template-remove-field ovl t))) @@ -150,6 +150,8 @@ Leave point at the end of the field." (let* ((end (point-marker)) (beg (- (point) (length call))) (cnt 0)) + (when (re-search-backward ")" beg t) + (delete-region (match-end 0) end)) (goto-char beg) (when (search-forward "(" end 'move) (if (eq (char-after) ?\)) @@ -161,7 +163,7 @@ Leave point at the end of the field." (save-excursion (company-template-add-field templ (match-beginning 1) (format "arg%d" cnt) sig)) - (incf cnt))) + (cl-incf cnt))) (company-template-move-to-first templ)))))) (provide 'company-template)