This package includes some extensions on top of the great Emacs verilog-mode.
- Tree-sitter support (requires Emacs 29)
- Improve syntax highlighting
- Hierarchy extraction and navigation
- LSP configuration for
lsp-modeandeglot - Support for many linters via
flycheck - Improve
imenuentries: detect instances, classes and methods - Code navigation functions for RTL and Verification environments
- Beautify modules and instances
- Extended collection of custom and
yasnippettemplates insertion viahydra - Many additional misc utilities
Latest verilog-mode version is required since verilog-ext relies on much of its functionality to work correctly.
Using straight and use-package:
(straight-use-package 'use-package)
(use-package verilog-mode
:straight (:repo "veripool/verilog-mode"))For other installation methods refer to verilog-mode installation options.
verilog-ext makes use of several binaries as backend engines to support IDE-like functionality. In addition, some third party Emacs Lisp packages serve as frontends for those binaries.
List of required binaries:
- Definitions and references navigation:
global,gtags,universal-ctags,python,pygments - Jump to parent module:
ag,ripgrep - Hierarchy extraction:
vhier - Linting:
verilator,iverilog,verible-verilog-lint,slang,svlint,xrun/hal - LSP:
hdl_checker,svlangserver,verible-verilog-ls,svls,veridian
Installation of required Emacs-lisp packages:
(use-package projectile)
(use-package ggtags)
(use-package ag)
(use-package ripgrep)
(use-package company)
(use-package yasnippet)
(use-package hydra)
(use-package outshine)
(use-package flycheck)
(use-package apheleia)
(use-package lsp-mode)
(use-package eglot)For the time being verilog-ext is still work in progress and is not yet available at MELPA.
To install it via straight:
(straight-use-package 'use-package)
(use-package
:straight (:repo "gmlarumbe/verilog-ext"))$ cd ~/.emacs.d
$ git clone https://github.com/gmlarumbe/verilog-extAnd add the following snippet to your .emacs or init.el:
(add-to-list 'load-path (expand-file-name "~/.emacs.d/verilog-ext"))
(require 'verilog-ext)Requires Emacs 29, installation of tree-sitter and Verilog grammar.
To install tree-sitter there are different options:
- Via npm
- Manually:
$ git clone https://github.com/tree-sitter/tree-sitter.git
$ cd tree-sitter
$ make && sudo make installInstallation of grammar can be automated through the script:
$ .github/scripts/install-ts-grammar.shThat will install libtree-sitter-verilog.so at $HOME/.emacs.d/tree-sitter.
By default verilog-ext does not create any keybindings. Following snippet shows a configuration example with use-package:
(use-package verilog-ext
:straight (:host github :repo "gmlarumbe/verilog-ext")
:after verilog-mode
:demand
:bind (:map verilog-mode-map
;; Default keys override
("TAB" . verilog-ext-electric-verilog-tab)
("M-d" . verilog-ext-kill-word)
("M-f" . verilog-ext-forward-word)
("M-b" . verilog-ext-backward-word)
("C-<backspace>" . verilog-ext-backward-kill-word)
;; Features
("M-i" . verilog-ext-imenu-list)
("C-c C-p" . verilog-ext-preprocess)
("C-c C-f" . verilog-ext-flycheck-mode-toggle)
("C-c C-t" . verilog-ext-hydra/body)
("C-c C-v" . verilog-ext-vhier-current-file)
;; Code beautifying
("C-M-i" . verilog-ext-indent-block-at-point)
("C-c b" . verilog-ext-module-at-point-beautify)
;; Dwim navigation
("C-M-a" . verilog-ext-nav-beg-of-defun-dwim)
("C-M-e" . verilog-ext-nav-end-of-defun-dwim)
("C-M-d" . verilog-ext-nav-down-dwim)
("C-M-u" . verilog-ext-nav-up-dwim)
("C-M-p" . verilog-ext-nav-prev-dwim)
("C-M-n" . verilog-ext-nav-next-dwim)
;; Module navigation
("C-M-." . verilog-ext-jump-to-parent-module)
;; Port connections
("C-c c" . verilog-ext-toggle-connect-port)
("C-c C-c" . verilog-ext-connect-ports-recursively))
:init
(setq verilog-ext-snippets-dir "~/.emacs.d/straight/repos/verilog-ext/snippets")
(setq verilog-ext-flycheck-eldoc-toggle t)
(setq verilog-ext-flycheck-verible-rules '("-line-length"))
:config
(verilog-ext-flycheck-set-linter 'verilog-verible)
(verilog-ext-add-snippets))The package includes the major-mode verilog-ts-mode for syntax highligting and indentation.
There is some WIP, e.g. Imenu or navigation functions.
Font-lock based improved fontification.
| verilog-mode | verilog-ext |
|---|---|
|
|
Extract hierarchy of module at current buffer via Verilog-Perl vhier.
Visualize with outline-minor-mode and outshine.
Functions:
verilog-ext-vhier-current-filefor hierarchy extractionvhier-outshine-modefor hierarchy navigation
Auto-configure various SystemVerilog language servers for lsp-mode and eglot:
Functions:
verilog-ext-lsp-set-serververilog-ext-eglot-set-server
Support via flycheck for the following linters:
- Verilator
- Icarus Verilog
- Verible
- Slang
- Svlint
- Cadence HAL
Functions:
verilog-ext-flycheck-mode-toggle: enable/disable current linter. Select linter withprefix-arg/(C-u).
Support detection of instances and methods inside classes.
| Instances | Methods |
|---|---|
|
|
imenu-listis a recommended package to visualize different levels of nesting in the hierarchy.
Navigate through instances inside a module forward/backwards.
Jump to parent module via ag/ripgrep.
Functions:
verilog-ext-find-module-instance-fwdverilog-ext-find-module-instance-bwdverilog-ext-jump-to-parent-moduleverilog-ext-instance-at-point
Jump to definition/reference of module at point via ggtags and xref.
Functions:
verilog-ext-jump-to-module-at-pointverilog-ext-jump-to-module-at-point-defverilog-ext-jump-to-module-at-point-ref
Context aware functions (do what I mean) depending on the file being edited. Modules (RTL) navigate through instances while classes (Verification) navigate through methods/defuns.
Functions:
verilog-ext-nav-down-dwimverilog-ext-nav-up-dwimverilog-ext-nav-beg-of-defun-dwimverilog-ext-nav-end-of-defun-dwimverilog-ext-nav-next-dwimverilog-ext-nav-prev-dwim
Indent and align parameters and ports, interactively and in batch.
Functions:
verilog-ext-module-at-point-beautifyverilog-ext-beautify-current-bufferverilog-ext-beautify-filesverilog-ext-beautify-files-current-dir
-
Select between snippets that cover most frequently used SystemVerilog constructs:
-
Insert instances in current module from file:
-
Create basic testbench environment from DUT file:
Functions:
verilog-ext-hydra/body
-
Code formatter setup via apheleia
verilog-ext-code-formatter-setup
-
Preprocess files based on binary:
verilator,iverilogorvppreprocverilog-ext-preprocess
-
Setup
companyto complete with verilog keywords -
Wrapper functions to stop cursor at underscores without breaking indentation
verilog-ext-forward-wordverilog-ext-backward-wordverilog-ext-kill-wordverilog-ext-backward-kill-word
-
Typedef handling for syntax-higlighting and alignment via
verilog-pretty-declarationsverilog-ext-typedef-project-update
-
Toggle connections of ports under instance at point
verilog-ext-toggle-connect-portverilog-ext-connect-ports-recursivelyverilog-ext-clean-port-blanks
-
Timestamp mode updating (after setting header timestamp regexp)
verilog-ext-time-stamp-mode
-
Auto convert block comments to names:
verilog-ext-block-end-comments-to-names-mode
-
Makefile based development:
verilog-ext-makefile-createverilog-ext-makefile-compile
Contributions are welcome! Just stick to common Elisp conventions and run the ERT suite after testing your changes and before submitting a new PR.
For new functionality add new ERT tests if possible.
To run the ERT test suite change directory to the verilog-ext root and run the ert-tests.sh script:
$ cd ~/.emacs.d/verilog-ext
$ .github/scripts/ert-tests.shIf there is a missing dependency, check the file .github/scripts/setup-env.sh used by GitHub Actions to configure your environment.






