my-complete-tag with my-ido-complete-tag.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 13 Jan 2015 00:19:46 +0200
changeset 1194 14d42e7c9224
parent 1193 4f46f97a10e9
child 1195 33fd66648b2a
my-complete-tag with my-ido-complete-tag.
.emacs-my
--- a/.emacs-my	Sat Jan 10 16:56:35 2015 +0200
+++ b/.emacs-my	Tue Jan 13 00:19:46 2015 +0200
@@ -2308,7 +2308,27 @@
   )
 
 (setq tags-add-tables t)
-(global-set-key [M-return] 'complete-tag)
+
+(defvar my-ido-tag-history nil
+  "History of tags selected using `my-ido-complete-tag'.")
+(defun my-ido-complete-tag (&optional substr)
+  "Find a tag using ido."
+  (tags-completion-table)
+  (let ( tag-names )
+    (mapatoms (lambda (x) (push (symbol-name x) tag-names)) tags-completion-table)
+    (ido-completing-read "Tag: " tag-names nil t substr 'my-ido-tag-history)))
+(defun my-complete-tag (prefix point)
+  (interactive "P\nd")
+  (if prefix
+      (funcall #'complete-tag)
+    (let ( (bounds (find-tag-default-bounds)) tag )
+      (if (or (not bounds) (< point (car bounds)) (< (cdr bounds) point))
+          (setq tag (my-ido-complete-tag))
+        (setq tag (my-ido-complete-tag (buffer-substring (car bounds) (cdr bounds))))
+        (delete-region (car bounds) (cdr bounds)))
+      (insert tag))))
+
+(global-set-key [M-return] #'my-complete-tag)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (message "CEDET, semantic, SRecord")