Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions README

This file was deleted.

59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# verilog_emacsauto

## Introduction
This is one improved version of [original verilog mode](https://github.com/vim-scripts/verilog_emacsauto.vim)
There are several issues in origional version:
- doesn't work on windows
- need enter "any key" twice to continue
- doesn't work for systemverilog

## Installation

### vim-plug
```vimscript
Plug 'zhuzhzh/verilog_emacsauto.vim', {'for': ['verilog', 'systemverilog'] }
```

### Vundle
```vimscript
Plugin 'zhuzhzh/verilog_emacsauto.vim'
```

## Windows
In order to work on windows, you need to install unix bins for windows.
Actually, git-for-windows already contains it.
Please add the path like D:\Git\usr\bin to system variable PATH
The bin path including emacs also needs to be added to PATH
if it still doesn't work , please consider to use the absolute path.
```vimscript
function s:Add()
if &expandtab
let s:save_tabstop = &tabstop
let &tabstop=8
endif
" a tmp file is need 'cause emacs doesn't support the stdin to stdout flow
" maybe add /tmp to the temporary filename
w! %.emacsautotmp
!"D:\Program Files\emacs\bin\emacs.exe" -batch -l "D:\Program Files\emacs\share\emacs\site-lisp\verilog-mode.el" %.emacsautotmp -f verilog-batch-auto
%!"D:\Git\usr\bin\cat.exe" %.emacsautotmp
if &expandtab
retab
let &tabstop=s:save_tabstop
endif
!"D:\Git\usr\bin\rm.exe" %.emacsautotmp
endfunction
```

## Feature
Two emacs verilog-mode functions are mapped.
- \<Leader>a expands all the verilog-mode autos (similar to C-c C-a in emacs).
- \<Leader>d collapses all the verilog-mode autos (similar to C-c C-d in emacs).

## config
User can define the shortkeys for auto-add and auto-delete. Here is the example.
```vim
let g:VerilogModeAddKey = <Leader>va
let g:VerilogModeDeleteKey = <Leader>vd
let g:VerilogModePath = ~/.elisp/verilog-mode.el
``

83 changes: 0 additions & 83 deletions ftplugin/verilog_emacsauto.vim

This file was deleted.

132 changes: 132 additions & 0 deletions plugin/systemverilog_emacsauto.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
" Vim filetype plugin for using emacs verilog-mode
" Last Change: 2018 August 28
" Origin Author: Seong Kang <seongk@wwcoms.com>
" Author: Harris Zhu <zhuzhzh@163.com>
" License: This file is placed in the public domain.

" comment out these two lines
" if you don't want folding or if you prefer other folding methods
"setlocal foldmethod=expr
"setlocal foldexpr=VerilogEmacsAutoFoldLevel(v:lnum)

if exists("loaded_verilog_emacsauto")
finish
endif
let loaded_verilog_emacsauto = 1

function! s:InitVar(var, value)
if !exists(a:var)
exec 'let '.a:var.'='.string(a:value)
endif
endfunction
" map \a, \d pair to Add and Delete functions, assuming \ is the leader
" alternatively, map C-A, C-D to Add and Delete functions

let s_DefaultPath = expand("$HOME") . "/.elisp/verilog-mode.el"

call s:InitVar('g:VerilogModeAddKey', '<leader>a')
call s:InitVar('g:VerilogModeDeleteKey', '<leader>d')
call s:InitVar('g:VerilogModeFile', s_DefaultPath)
call s:InitVar('g:VerilogModeTrace', 0)

"if !hasmapto('<Plug>VerilogEmacsAutoAdd')
"map <unique> <leader>a <Plug>VerilogEmacsAutoAdd
"endif
try
if g:VerilogModeAddKey != ""
exec 'nnoremap <silent><unique> ' g:VerilogModeAddKey '<Plug>VerilogEmacsAutoAdd'
endif
catch /^Vim\%((\a\+)\)\=:E227/
endtry

"if !hasmapto('<Plug>VerilogEmacsAutoDelete')
" map <unique> <leader>d <Plug>VerilogEmacsAutoDelete
"endif
try
if g:VerilogModeDeleteKey != ""
exec 'nnoremap <silent><unique> ' g:VerilogModeDeleteKey '<Plug>VerilogEmacsAutoDelete'
endif
catch /^Vim\%((\a\+)\)\=:E227/
endtry



noremap <unique> <script> <Plug>VerilogEmacsAutoAdd <SID>Add
noremap <unique> <script> <Plug>VerilogEmacsAutoDelete <SID>Delete
noremap <SID>Add :call <SID>Add()<CR>
noremap <SID>Delete :call <SID>Delete()<CR>
" add menu items for gvim
noremenu <script> Verilog-Mode.AddAuto <SID>Add
noremenu <script> Verilog-Mode.DeleteAuto <SID>Delete

let s:is_win = has('win16') || has('win32') || has('win64')

" Add function
" saves current document to a temporary file
" runs the temporary file through emacs
" replaces current document with the emacs filtered temporary file
" removes temporary file
" also replaces emacs generated tabs with spaces if expandtab is set
" comment out the two if blocks to leave the tabs alone
function s:Add()
if &expandtab
let s:save_tabstop = &tabstop
let &tabstop=8
endif
" a tmp file is need 'cause emacs doesn't support the stdin to stdout flow
" maybe add /tmp to the temporary filename
let l:tmpfile = expand("%:p:h") . "/." . expand("%:p:t")
"echom l:tmpfile
silent! call writefile(getline(1, "$"), fnameescape(l:tmpfile), '')
if g:VerilogModeTrace
exec "silent !emacs -batch --no-site-file -l ". g:VerilogModeFile . " " . shellescape(l:tmpfile, 1) . " -f verilog-batch-auto"
else
exec "silent !emacs -batch --no-site-file -l ". g:VerilogModeFile . " " . shellescape(l:tmpfile, 1) . " -f verilog-batch-auto 2> /dev/null"
endif
let l:newcontent = readfile(fnameescape(l:tmpfile), '')

if &expandtab
retab
let &tabstop=s:save_tabstop
endif
"call deletebufline('.', 1, '$')
let l:i=1
call setline(1, l:newcontent)
exec "silent !rm " . shellescape(l:tmpfile)
w! %
exec 'redraw!'
endfunction

" Delete function
" saves current document to a temporary file
" runs the temporary file through emacs
" replaces current document with the emacs filtered temporary file
" removes temporary file
function s:Delete()
" a tmp file is need 'cause emacs doesn't support the stdin to stdout flow
" maybe add /tmp to the temporary filename
let l:tmpfile = expand("%:p:h") . "/." . expand("%:p:t")
"exec 'wrtie' fnameescape(l:tmpfile)
silent! call writefile(getline(1, "$"), fnameescape(l:tmpfile), '')
if g:VerilogModeTrace
exec "silent !emacs -batch --no-site-file -l " . g:VerilogModeFile . " " . l:tmpfile . " -f verilog-batch-delete-auto"
else
exec "silent !emacs -batch --no-site-file -l " . g:VerilogModeFile . " " . l:tmpfile . " -f verilog-batch-delete-auto 2> /dev/null"
endif
exec "silent %!cat " . shellescape(l:tmpfile)
exec "silent !rm " . shellescape(l:tmpfile)
w! %
exec 'redraw!'
endfunction

" VerilogEmacsAutoFoldLevel function
" only deals with 0 and 1 levels
function VerilogEmacsAutoFoldLevel(l)
if (getline(a:l-1)=~'\/\*A\S*\*\/' && getline(a:l)=~'\/\/ \(Outputs\|Inputs\|Inouts\|Beginning\)')
return 1
endif
if (getline(a:l-1)=~'\(End of automatics\|);\)')
return 0
endif
return '='
endfunction