forked from gmlarumbe/verilog-ext
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog-ext-which-func.el
77 lines (61 loc) · 2.79 KB
/
verilog-ext-which-func.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; verilog-ext-which-func.el --- Verilog-ext Which Func -*- lexical-binding: t -*-
;; Copyright (C) 2022-2023 Gonzalo Larumbe
;; Author: Gonzalo Larumbe <[email protected]>
;; URL: https://github.com/gmlarumbe/verilog-ext
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Basic `which-func' setup
;;; Code:
(require 'which-func)
(require 'verilog-ext-nav)
(defvar-local verilog-ext-which-func-extra nil
"Variable to hold extra information for `which-func'.")
(defun verilog-ext-which-func-shorten-block (block-type)
"Return shortened name of BLOCK-TYPE, if possible."
(cond ((string= "function" block-type) "func")
((string= "task" block-type) "task")
((string= "class" block-type) "cls")
((string= "module" block-type) "mod")
((string= "interface" block-type) "itf")
((string= "package" block-type) "pkg")
((string= "program" block-type) "pgm")
((string= "generate" block-type) "gen")
(t block-type)))
(defun verilog-ext-which-func-function ()
"Retrieve `which-func' candidates."
(let (data)
(cond ((and verilog-ext-file-allows-instances
(setq data (verilog-ext-instance-at-point)))
(setq verilog-ext-which-func-extra (cadr data))
(car data))
((setq data (verilog-ext-block-at-point))
(setq verilog-ext-which-func-extra (alist-get 'name data))
(verilog-ext-which-func-shorten-block (alist-get 'type data)))
(t
(setq verilog-ext-which-func-extra nil)
""))))
(defun verilog-ext-which-func ()
"Hook for `verilog-mode' to enable `which-func'."
(when (eq major-mode 'verilog-mode)
(setq-local which-func-functions '(verilog-ext-which-func-function))
(setq-local which-func-format
`("["
(:propertize which-func-current
face (which-func :weight bold)
mouse-face mode-line-highlight)
":"
(:propertize verilog-ext-which-func-extra
face which-func
mouse-face mode-line-highlight)
"]"))))
(provide 'verilog-ext-which-func)
;;; verilog-ext-which-func.el ends here