comparison lisp/progmodes/etags.el @ 93680:5dee8473f368

Fix problem with completion for buffer-local tables. Reported by Radey Shouman <shouman@comcast.net>. (tags-complete-tag): Remove. (tags-lazy-completion-table): New function to replace it. (find-tag-tag, complete-tag): Update users.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 05 Apr 2008 03:31:50 +0000
parents 01d2b6c9032f
children 58a4ed015d25
comparison
equal deleted inserted replaced
93679:3636fd479ab3 93680:5dee8473f368
778 ;; Cache the result a buffer-local variable. 778 ;; Cache the result a buffer-local variable.
779 (setq tags-completion-table combined-table)) 779 (setq tags-completion-table combined-table))
780 (quit (message "Tags completion table construction aborted.") 780 (quit (message "Tags completion table construction aborted.")
781 (setq tags-completion-table nil))))) 781 (setq tags-completion-table nil)))))
782 782
783 (defun tags-complete-tag (string predicate what) 783 (defun tags-lazy-completion-table ()
784 "Completion function for tags. 784 (lexical-let ((buf (current-buffer)))
785 Does normal `try-completion', but builds `tags-completion-table' on 785 (lambda (string pred action)
786 demand." 786 (with-current-buffer buf
787 (save-excursion 787 (save-excursion
788 ;; If we need to ask for the tag table, allow that. 788 ;; If we need to ask for the tag table, allow that.
789 (let ((enable-recursive-minibuffers t)) 789 (let ((enable-recursive-minibuffers t))
790 (visit-tags-table-buffer)) 790 (visit-tags-table-buffer))
791 (if (eq what t) 791 (complete-with-action action (tags-completion-table) string pred))))))
792 (all-completions string (tags-completion-table) predicate)
793 (try-completion string (tags-completion-table) predicate))))
794 792
795 (defun find-tag-tag (string) 793 (defun find-tag-tag (string)
796 "Read a tag name, with defaulting and completion." 794 "Read a tag name, with defaulting and completion."
797 (let* ((completion-ignore-case (if (memq tags-case-fold-search '(t nil)) 795 (let* ((completion-ignore-case (if (memq tags-case-fold-search '(t nil))
798 tags-case-fold-search 796 tags-case-fold-search
803 (spec (completing-read (if default 801 (spec (completing-read (if default
804 (format "%s (default %s): " 802 (format "%s (default %s): "
805 (substring string 0 (string-match "[ :]+\\'" string)) 803 (substring string 0 (string-match "[ :]+\\'" string))
806 default) 804 default)
807 string) 805 string)
808 'tags-complete-tag 806 (tags-lazy-completion-table)
809 nil nil nil nil default))) 807 nil nil nil nil default)))
810 (if (equal spec "") 808 (if (equal spec "")
811 (or default (error "There is no default tag")) 809 (or default (error "There is no default tag"))
812 spec))) 810 spec)))
813 811
2051 tags-case-fold-search 2049 tags-case-fold-search
2052 case-fold-search)) 2050 case-fold-search))
2053 (pattern (funcall (or find-tag-default-function 2051 (pattern (funcall (or find-tag-default-function
2054 (get major-mode 'find-tag-default-function) 2052 (get major-mode 'find-tag-default-function)
2055 'find-tag-default))) 2053 'find-tag-default)))
2054 (comp-table (tags-lazy-completion-table))
2056 beg 2055 beg
2057 completion) 2056 completion)
2058 (or pattern 2057 (or pattern
2059 (error "Nothing to complete")) 2058 (error "Nothing to complete"))
2060 (search-backward pattern) 2059 (search-backward pattern)
2061 (setq beg (point)) 2060 (setq beg (point))
2062 (forward-char (length pattern)) 2061 (forward-char (length pattern))
2063 (setq completion (tags-complete-tag pattern nil nil)) 2062 (setq completion (try-completion pattern comp-table))
2064 (cond ((eq completion t)) 2063 (cond ((eq completion t))
2065 ((null completion) 2064 ((null completion)
2066 (message "Can't find completion for \"%s\"" pattern) 2065 (message "Can't find completion for \"%s\"" pattern)
2067 (ding)) 2066 (ding))
2068 ((not (string= pattern completion)) 2067 ((not (string= pattern completion))
2070 (insert completion)) 2069 (insert completion))
2071 (t 2070 (t
2072 (message "Making completion list...") 2071 (message "Making completion list...")
2073 (with-output-to-temp-buffer "*Completions*" 2072 (with-output-to-temp-buffer "*Completions*"
2074 (display-completion-list 2073 (display-completion-list
2075 (all-completions pattern 'tags-complete-tag nil) 2074 (all-completions pattern comp-table nil)
2076 pattern)) 2075 pattern))
2077 (message "Making completion list...%s" "done"))))) 2076 (message "Making completion list...%s" "done")))))
2078 2077
2079 (dolist (x '("^No tags table in use; use .* to select one$" 2078 (dolist (x '("^No tags table in use; use .* to select one$"
2080 "^There is no default tag$" 2079 "^There is no default tag$"