-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
verilog-ext-hs.el
101 lines (83 loc) · 3.48 KB
/
verilog-ext-hs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; verilog-ext-hs.el --- Verilog-ext Hideshow -*- lexical-binding: t -*-
;; Copyright (C) 2022-2024 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:
;; `hideshow' configuration for code folding.
;;; Code:
(require 'verilog-ext-utils)
(require 'hideshow)
(defconst verilog-ext-hs-block-start-keywords-re
(eval-when-compile
(concat "\\("
"\\(" (regexp-opt '("(" "{" "[")) "\\)"
"\\|"
"\\(" (verilog-regexp-words
'("begin"
"fork"
"clocking"
"function"
"covergroup"
"property"
"task"
"generate"
"`ifdef" "`ifndef"))
"\\)" "\\)")))
(defconst verilog-ext-hs-block-end-keywords-re
(eval-when-compile
(concat "\\("
"\\(" (regexp-opt '(")" "}" "]")) "\\)"
"\\|"
"\\(" (verilog-regexp-words
'("end"
"join" "join_any" "join_none"
"endclocking"
"endfunction"
"endgroup"
"endproperty"
"endtask"
"endgenerate"
"`endif"))
"\\)" "\\)")))
(defun verilog-ext-hs-setup ()
"Configure `hideshow'."
(dolist (mode '((verilog-mode . verilog-forward-sexp-function)
(verilog-ts-mode . verilog-ts-forward-sexp)))
(add-to-list 'hs-special-modes-alist `(,(car mode)
,verilog-ext-hs-block-start-keywords-re
,verilog-ext-hs-block-end-keywords-re
nil
,(cdr mode))))
(dolist (hook '(verilog-mode-hook verilog-ts-mode-hook))
(add-hook hook #'hs-minor-mode))
;; Workaround to enable `hideshow' on first file visit with lazy loading using
;; :config section with `use-package'
(when (member major-mode '(verilog-mode verilog-ts-mode))
(hs-minor-mode 1)))
(defun verilog-ext-hs-toggle-hiding (&optional e)
"Wrapper for `hs-toggle-hiding' depending on current Verilog `major-mode'.
For `verilog-mode' use a modified syntax table. For `verilog-ts-mode' use
existing one.
Toggle hiding/showing of a block.
See `hs-hide-block' and `hs-show-block'.
Argument E should be the event that triggered this action."
(interactive (list last-nonmenu-event))
(cond ((eq major-mode 'verilog-mode)
(verilog-ext-with-syntax-table-tick-word
(hs-toggle-hiding e)))
((eq major-mode 'verilog-ts-mode)
(hs-toggle-hiding e))
(t
(error "Wrong major-mode to run `verilog-ext-hideshow-toggle'"))))
(provide 'verilog-ext-hs)
;;; verilog-ext-hs.el ends here