diff options
| author | Noam Postavsky | 2016-08-13 22:13:56 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2016-12-21 21:39:58 -0500 |
| commit | de0671096706bf7404cddce277b918c8d769f17b (patch) | |
| tree | bdcd1ebaef3702670e8bc41afc6d41ab0af9774a | |
| parent | acd65a7d948f77701f5bdc99c031ca8fdb1e976e (diff) | |
| download | emacs-de0671096706bf7404cddce277b918c8d769f17b.tar.gz emacs-de0671096706bf7404cddce277b918c8d769f17b.zip | |
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). We need to keep them for backwards compatibility with
older emacs versions, but use completion-at-point if available.
* lisp/progmodes/verilog-mode.el (verilog-toggle-completions): Mark as
obsolete if completion-cycle-threshold is available.
(verilog-mode-map, verilog-menu): Bind completion-at-point and
completion-help-at-point in preference to verilog-complete-word and
verilog-show-completions, respectively.
(verilog-mode): Add verilog-completion-at-point to
completion-at-point-functions.
(verilog-completion-at-point): New function.
(verilog-show-completions, verilog-complete-word): Use it to avoid code
duplication.
| -rw-r--r-- | lisp/progmodes/verilog-mode.el | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el index 5368b613569..4e9b43ba0d4 100644 --- a/lisp/progmodes/verilog-mode.el +++ b/lisp/progmodes/verilog-mode.el | |||
| @@ -1416,8 +1416,10 @@ If set will become buffer local.") | |||
| 1416 | (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) | 1416 | (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) |
| 1417 | (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) | 1417 | (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) |
| 1418 | (define-key map "\M-\r" `electric-verilog-terminate-and-indent) | 1418 | (define-key map "\M-\r" `electric-verilog-terminate-and-indent) |
| 1419 | (define-key map "\M-\t" 'verilog-complete-word) | 1419 | (define-key map "\M-\t" (if (fboundp 'completion-at-point) |
| 1420 | (define-key map "\M-?" 'verilog-show-completions) | 1420 | 'completion-at-point 'verilog-complete-word)) |
| 1421 | (define-key map "\M-?" (if (fboundp 'completion-help-at-point) | ||
| 1422 | 'completion-help-at-point 'verilog-show-completions)) | ||
| 1421 | ;; Note \C-c and letter are reserved for users | 1423 | ;; Note \C-c and letter are reserved for users |
| 1422 | (define-key map "\C-c`" 'verilog-lint-off) | 1424 | (define-key map "\C-c`" 'verilog-lint-off) |
| 1423 | (define-key map "\C-c*" 'verilog-delete-auto-star-implicit) | 1425 | (define-key map "\C-c*" 'verilog-delete-auto-star-implicit) |
| @@ -1448,7 +1450,7 @@ If set will become buffer local.") | |||
| 1448 | (easy-menu-define | 1450 | (easy-menu-define |
| 1449 | verilog-menu verilog-mode-map "Menu for Verilog mode" | 1451 | verilog-menu verilog-mode-map "Menu for Verilog mode" |
| 1450 | (verilog-easy-menu-filter | 1452 | (verilog-easy-menu-filter |
| 1451 | '("Verilog" | 1453 | `("Verilog" |
| 1452 | ("Choose Compilation Action" | 1454 | ("Choose Compilation Action" |
| 1453 | ["None" | 1455 | ["None" |
| 1454 | (progn | 1456 | (progn |
| @@ -1540,7 +1542,8 @@ If set will become buffer local.") | |||
| 1540 | :help "Take a signal vector on the current line and expand it to multiple lines"] | 1542 | :help "Take a signal vector on the current line and expand it to multiple lines"] |
| 1541 | ["Insert begin-end block" verilog-insert-block | 1543 | ["Insert begin-end block" verilog-insert-block |
| 1542 | :help "Insert begin ... end"] | 1544 | :help "Insert begin ... end"] |
| 1543 | ["Complete word" verilog-complete-word | 1545 | ["Complete word" ,(if (fboundp 'completion-at-point) |
| 1546 | 'completion-at-point 'verilog-complete-word) | ||
| 1544 | :help "Complete word at point"] | 1547 | :help "Complete word at point"] |
| 1545 | "----" | 1548 | "----" |
| 1546 | ["Recompute AUTOs" verilog-auto | 1549 | ["Recompute AUTOs" verilog-auto |
| @@ -3806,7 +3809,7 @@ AUTO expansion functions are, in part: | |||
| 3806 | 3809 | ||
| 3807 | Some other functions are: | 3810 | Some other functions are: |
| 3808 | 3811 | ||
| 3809 | \\[verilog-complete-word] Complete word with appropriate possibilities. | 3812 | \\[completion-at-point] Complete word with appropriate possibilities. |
| 3810 | \\[verilog-mark-defun] Mark function. | 3813 | \\[verilog-mark-defun] Mark function. |
| 3811 | \\[verilog-beg-of-defun] Move to beginning of current function. | 3814 | \\[verilog-beg-of-defun] Move to beginning of current function. |
| 3812 | \\[verilog-end-of-defun] Move to end of current function. | 3815 | \\[verilog-end-of-defun] Move to end of current function. |
| @@ -3920,6 +3923,9 @@ Key bindings specific to `verilog-mode-map' are: | |||
| 3920 | verilog-forward-sexp-function) | 3923 | verilog-forward-sexp-function) |
| 3921 | hs-special-modes-alist)))) | 3924 | hs-special-modes-alist)))) |
| 3922 | 3925 | ||
| 3926 | (add-hook 'completion-at-point-functions | ||
| 3927 | #'verilog-completion-at-point nil 'local) | ||
| 3928 | |||
| 3923 | ;; Stuff for autos | 3929 | ;; Stuff for autos |
| 3924 | (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local) | 3930 | (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local) |
| 3925 | ;; verilog-mode-hook call added by define-derived-mode | 3931 | ;; verilog-mode-hook call added by define-derived-mode |
| @@ -7198,6 +7204,9 @@ Region is defined by B and EDPOS." | |||
| 7198 | Repeated use of \\[verilog-complete-word] will show you all of them. | 7204 | Repeated use of \\[verilog-complete-word] will show you all of them. |
| 7199 | Normally, when there is more than one possible completion, | 7205 | Normally, when there is more than one possible completion, |
| 7200 | it displays a list of all possible completions.") | 7206 | it displays a list of all possible completions.") |
| 7207 | (when (boundp 'completion-cycle-threshold) | ||
| 7208 | (make-obsolete-variable | ||
| 7209 | 'verilog-toggle-completions 'completion-cycle-threshold "26.1")) | ||
| 7201 | 7210 | ||
| 7202 | 7211 | ||
| 7203 | (defvar verilog-type-keywords | 7212 | (defvar verilog-type-keywords |
| @@ -7480,21 +7489,33 @@ exact match, nil otherwise." | |||
| 7480 | (defvar verilog-last-word-shown nil) | 7489 | (defvar verilog-last-word-shown nil) |
| 7481 | (defvar verilog-last-completions nil) | 7490 | (defvar verilog-last-completions nil) |
| 7482 | 7491 | ||
| 7492 | (defun verilog-completion-at-point () | ||
| 7493 | "Used as an element of `completion-at-point-functions'. | ||
| 7494 | \(See also `verilog-type-keywords' and | ||
| 7495 | `verilog-separator-keywords'.)" | ||
| 7496 | (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | ||
| 7497 | (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | ||
| 7498 | (verilog-str (buffer-substring b e)) | ||
| 7499 | ;; The following variable is used in verilog-completion | ||
| 7500 | (verilog-buffer-to-use (current-buffer)) | ||
| 7501 | (allcomp (if (and verilog-toggle-completions | ||
| 7502 | (string= verilog-last-word-shown verilog-str)) | ||
| 7503 | verilog-last-completions | ||
| 7504 | (all-completions verilog-str 'verilog-completion)))) | ||
| 7505 | (list b e allcomp))) | ||
| 7506 | |||
| 7483 | (defun verilog-complete-word () | 7507 | (defun verilog-complete-word () |
| 7484 | "Complete word at current point. | 7508 | "Complete word at current point. |
| 7485 | \(See also `verilog-toggle-completions', `verilog-type-keywords', | 7509 | \(See also `verilog-toggle-completions', `verilog-type-keywords', |
| 7486 | and `verilog-separator-keywords'.)" | 7510 | and `verilog-separator-keywords'.)" |
| 7487 | ;; FIXME: Provide completion-at-point-function. | 7511 | ;; NOTE: This is just a fallback for Emacs versions lacking |
| 7512 | ;; `completion-at-point'. | ||
| 7488 | (interactive) | 7513 | (interactive) |
| 7489 | (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | 7514 | (let* ((comp-info (verilog-completion-at-point)) |
| 7490 | (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | 7515 | (b (nth 0 comp-info)) |
| 7516 | (e (nth 1 comp-info)) | ||
| 7491 | (verilog-str (buffer-substring b e)) | 7517 | (verilog-str (buffer-substring b e)) |
| 7492 | ;; The following variable is used in verilog-completion | 7518 | (allcomp (nth 2 comp-info)) |
| 7493 | (verilog-buffer-to-use (current-buffer)) | ||
| 7494 | (allcomp (if (and verilog-toggle-completions | ||
| 7495 | (string= verilog-last-word-shown verilog-str)) | ||
| 7496 | verilog-last-completions | ||
| 7497 | (all-completions verilog-str 'verilog-completion))) | ||
| 7498 | (match (if verilog-toggle-completions | 7519 | (match (if verilog-toggle-completions |
| 7499 | "" (try-completion | 7520 | "" (try-completion |
| 7500 | verilog-str (mapcar (lambda (elm) | 7521 | verilog-str (mapcar (lambda (elm) |
| @@ -7542,23 +7563,15 @@ and `verilog-separator-keywords'.)" | |||
| 7542 | 7563 | ||
| 7543 | (defun verilog-show-completions () | 7564 | (defun verilog-show-completions () |
| 7544 | "Show all possible completions at current point." | 7565 | "Show all possible completions at current point." |
| 7566 | ;; NOTE: This is just a fallback for Emacs versions lacking | ||
| 7567 | ;; `completion-help-at-point'. | ||
| 7545 | (interactive) | 7568 | (interactive) |
| 7546 | (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | 7569 | ;; Show possible completions in a temporary buffer. |
| 7547 | (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | 7570 | (with-output-to-temp-buffer "*Completions*" |
| 7548 | (verilog-str (buffer-substring b e)) | 7571 | (display-completion-list (nth 2 (verilog-completion-at-point)))) |
| 7549 | ;; The following variable is used in verilog-completion | 7572 | ;; Wait for a key press. Then delete *Completion* window |
| 7550 | (verilog-buffer-to-use (current-buffer)) | 7573 | (momentary-string-display "" (point)) |
| 7551 | (allcomp (if (and verilog-toggle-completions | 7574 | (delete-window (get-buffer-window (get-buffer "*Completions*")))) |
| 7552 | (string= verilog-last-word-shown verilog-str)) | ||
| 7553 | verilog-last-completions | ||
| 7554 | (all-completions verilog-str 'verilog-completion)))) | ||
| 7555 | ;; Show possible completions in a temporary buffer. | ||
| 7556 | (with-output-to-temp-buffer "*Completions*" | ||
| 7557 | (display-completion-list allcomp)) | ||
| 7558 | ;; Wait for a key press. Then delete *Completion* window | ||
| 7559 | (momentary-string-display "" (point)) | ||
| 7560 | (delete-window (get-buffer-window (get-buffer "*Completions*"))))) | ||
| 7561 | |||
| 7562 | 7575 | ||
| 7563 | (defun verilog-get-default-symbol () | 7576 | (defun verilog-get-default-symbol () |
| 7564 | "Return symbol around current point as a string." | 7577 | "Return symbol around current point as a string." |