From ed885f166108945b8e99d09feaac53ee470a3f2c Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 13 Aug 2016 22:13:56 -0400 Subject: [PATCH v1] Use completion-at-point in verilog-mode There were some functions in verilog-mode that implemented in-buffer completion, but this needlessly duplicates completion-at-point functionality, and the popup window management had problems (see Bug #23842). * lisp/progmodes/verilog-mode.el (verilog-toggle-completions): Mark obsolete, it does the same job as `completion-cycle-threshold'. (verilog-completion-at-point): New function. (verilog-show-completions): Remove, replace calls with `completion-help-at-point'. (verilog-complete-word): Remove, replace calls with `completion-at-point'. --- lisp/progmodes/verilog-mode.el | 109 +++++++++-------------------------------- 1 file changed, 23 insertions(+), 86 deletions(-) diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el index fd2e96a..e5b9ee8 100644 --- a/lisp/progmodes/verilog-mode.el +++ b/lisp/progmodes/verilog-mode.el @@ -1374,8 +1374,8 @@ verilog-mode-map (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) (define-key map "\M-\r" `electric-verilog-terminate-and-indent) - (define-key map "\M-\t" 'verilog-complete-word) - (define-key map "\M-?" 'verilog-show-completions) + (define-key map "\M-\t" 'completion-at-point) + (define-key map "\M-?" 'completion-help-at-point) ;; Note \C-c and letter are reserved for users (define-key map "\C-c`" 'verilog-lint-off) (define-key map "\C-c*" 'verilog-delete-auto-star-implicit) @@ -1498,7 +1498,7 @@ verilog-mode-map :help "Take a signal vector on the current line and expand it to multiple lines"] ["Insert begin-end block" verilog-insert-block :help "Insert begin ... end"] - ["Complete word" verilog-complete-word + ["Complete word" completion-at-point :help "Complete word at point"] "----" ["Recompute AUTOs" verilog-auto @@ -3762,7 +3762,7 @@ verilog-mode Some other functions are: - \\[verilog-complete-word] Complete word with appropriate possibilities. + \\[completion-at-point] Complete word with appropriate possibilities. \\[verilog-mark-defun] Mark function. \\[verilog-beg-of-defun] Move to beginning of current function. \\[verilog-end-of-defun] Move to end of current function. @@ -3876,6 +3876,9 @@ verilog-mode verilog-forward-sexp-function) hs-special-modes-alist)))) + (add-hook 'completion-at-point-functions + #'verilog-completion-at-point nil 'local) + ;; Stuff for autos (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local) ;; verilog-mode-hook call added by define-derived-mode @@ -7143,10 +7146,9 @@ verilog-pred (defvar verilog-buffer-to-use nil) (defvar verilog-flag nil) (defvar verilog-toggle-completions nil - "True means \\\\[verilog-complete-word] should try all possible completions one by one. -Repeated use of \\[verilog-complete-word] will show you all of them. -Normally, when there is more than one possible completion, -it displays a list of all possible completions.") + "Obsolete, use `completion-cycle-threshold' instead.") +(make-obsolete-variable + 'verilog-toggle-completions 'completion-cycle-threshold "25.2") (defvar verilog-type-keywords @@ -7429,85 +7431,20 @@ verilog-last-word-numb (defvar verilog-last-word-shown nil) (defvar verilog-last-completions nil) -(defun verilog-complete-word () - "Complete word at current point. -\(See also `verilog-toggle-completions', `verilog-type-keywords', -and `verilog-separator-keywords'.)" - ;; FIXME: Provide completion-at-point-function. - (interactive) - (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) - (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) - (verilog-str (buffer-substring b e)) - ;; The following variable is used in verilog-completion - (verilog-buffer-to-use (current-buffer)) - (allcomp (if (and verilog-toggle-completions - (string= verilog-last-word-shown verilog-str)) - verilog-last-completions - (all-completions verilog-str 'verilog-completion))) - (match (if verilog-toggle-completions - "" (try-completion - verilog-str (mapcar (lambda (elm) - (cons elm 0)) allcomp))))) - ;; Delete old string - (delete-region b e) - - ;; Toggle-completions inserts whole labels - (if verilog-toggle-completions - (progn - ;; Update entry number in list - (setq verilog-last-completions allcomp - verilog-last-word-numb - (if (>= verilog-last-word-numb (1- (length allcomp))) - 0 - (1+ verilog-last-word-numb))) - (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb)) - ;; Display next match or same string if no match was found - (if (not (null allcomp)) - (insert "" verilog-last-word-shown) - (insert "" verilog-str) - (message "(No match)"))) - ;; The other form of completion does not necessarily do that. - - ;; Insert match if found, or the original string if no match - (if (or (null match) (equal match 't)) - (progn (insert "" verilog-str) - (message "(No match)")) - (insert "" match)) - ;; Give message about current status of completion - (cond ((equal match 't) - (if (not (null (cdr allcomp))) - (message "(Complete but not unique)") - (message "(Sole completion)"))) - ;; Display buffer if the current completion didn't help - ;; on completing the label. - ((and (not (null (cdr allcomp))) (= (length verilog-str) - (length match))) - (with-output-to-temp-buffer "*Completions*" - (display-completion-list allcomp)) - ;; Wait for a key press. Then delete *Completion* window - (momentary-string-display "" (point)) - (delete-window (get-buffer-window (get-buffer "*Completions*"))) - ))))) - -(defun verilog-show-completions () - "Show all possible completions at current point." - (interactive) +(defun verilog-completion-at-point () + "Used as an element of `completion-at-point-functions'. +\(See also `verilog-type-keywords' and +`verilog-separator-keywords'.)" (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) - (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) - (verilog-str (buffer-substring b e)) - ;; The following variable is used in verilog-completion - (verilog-buffer-to-use (current-buffer)) - (allcomp (if (and verilog-toggle-completions - (string= verilog-last-word-shown verilog-str)) - verilog-last-completions - (all-completions verilog-str 'verilog-completion)))) - ;; Show possible completions in a temporary buffer. - (with-output-to-temp-buffer "*Completions*" - (display-completion-list allcomp)) - ;; Wait for a key press. Then delete *Completion* window - (momentary-string-display "" (point)) - (delete-window (get-buffer-window (get-buffer "*Completions*"))))) - + (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) + (verilog-str (buffer-substring b e)) + ;; The following variable is used in verilog-completion + (verilog-buffer-to-use (current-buffer)) + (allcomp (if (and verilog-toggle-completions + (string= verilog-last-word-shown verilog-str)) + verilog-last-completions + (all-completions verilog-str 'verilog-completion)))) + (list b e allcomp))) (defun verilog-get-default-symbol () "Return symbol around current point as a string." -- 2.9.2