Custom indentation in Emacs Vhdl-mode

H

Hugo

Hello!
I hope some emacs guru can give me a tip on this :)
My organization requires that the following indentation is used in this
particular section of the code:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

Can I customize vhdl-mode to beautify like that to me?
The problem is that those 4 lines all return the same value in
"Syntactic Info" ( = statement), so I have no clue if what I want is
possible.

Any ideas?

Thanks,
Hugo
 
M

Mike Treseler

Hugo said:
Hello!
I hope some emacs guru can give me a tip on this :)
My organization requires that the following indentation is used in this
particular section of the code:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

Can I customize vhdl-mode to beautify like that to me?
yes

Any ideas?

I see that you also posted this to gun.emacs.help.
You will get an answer there.

-- Mike Treseler
 
B

Ben Jones

Mike Treseler said:
I see that you also posted this to gun.emacs.help.
You will get an answer there.

Surely mixing Emacs and firearms is a bad idea? Or did the editor wars just
escalate while I wasn't looking? :)

-Ben-
 
M

Mike Treseler

Ben said:
Surely mixing Emacs and firearms is a bad idea?

Maybe not.
It passed the spell checker :)

-- Mike Treseler

"And I swear that I don't have a gnu."
 
B

Brian Drummond

Hello!
I hope some emacs guru can give me a tip on this :)
My organization requires that the following indentation is used in this
particular section of the code:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

Can I customize vhdl-mode to beautify like that to me?

This is the obvious place for a script to delete the last two lines and
replace them with " use ieee.numeric_std;"

- Brian
 
M

Mike Treseler

Brian said:
This is the obvious place for a script to delete the last two lines and
replace them with " use ieee.numeric_std;"

That's a positive twist for the editor wars.
While a macro to do a complete synopsys2numeric
is intractable, one to simply start on the
right foot by inserting

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

should not be difficult, and might
make for more interesting questions here.

I'll do such an emacs function
and will collect and post
any email contributions I get
in the next week for your favorite editor.

-- Mike Treseler
 
B

Ben Jones

Mike Treseler said:
While a macro to do a complete synopsys2numeric
is intractable, one to simply start on the
right foot by inserting

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

should not be difficult, and might
make for more interesting questions here.

I know that when using CVS, and presumably other source code control
systems, it is possible to create custom scripts that refuse a check-in if
the file does not conform to certain rules. It would be good to have such a
rule for VHDL that would barf when presented with ieee.std_logic_unsigned
and friends.

Cheers,

-Ben-

....as for the editor wars, I am mostly in favour of gnu control. Although
most people in this newsgroup would be quick to defend our right to bear
ARMs...
 
H

Hugo

So, any ideas on how to indent the use's relative to "library ieee" ? I
know it's pretty silly thing...

The only way I know to accomplish that would be a post-beautifier
function that fixes those lines.. but this sounds rather ugly... :)

Tks,
Hugo

Mike Treseler escreveu:
 
M

Mike Treseler

Hugo said:
So, any ideas on how to indent the use's relative to "library ieee" ? I
know it's pretty silly thing...

The only way I know to accomplish that would be a post-beautifier
function that fixes those lines.. but this sounds rather ugly... :)

Since I hijacked your thread, here's an idea.

Yes. If you look at the source for vhdl-beautify-buffer you will
see that it is pretty tightly wound. I would write a
wrapper function called vhdl-align-use that would
call beautify then find the first USE, insert three spaces, etc.
Something like:

(defun align-use () "Indent vhdl use clauses"
(vhdl-beautify-buffer)
(beginning-of-buffer)
;;code to search for "use" lines and insert three spaces goes here.
)
 
H

haws

Ok, thanks! I guess that solution will do!

I thought I'd have to change the syntactic meaning of "use", but
vhdl-mode is kinda complicated (20k lines), so I probably don't want to
mess there anyway :)

Mike Treseler escreveu:
 
M

Mike Treseler

Mike said:
I'll do such an emacs function


(defun vhdl-ieee () "Insert ieee use clauses"
(interactive)
(insert "
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
"))


-- Mike Treseler
 
M

Martin Thompson

Mike Treseler said:
(defun vhdl-ieee () "Insert ieee use clauses"
(interactive)
(insert "
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
"))

And add this:
(define-key vhdl-template-map "\C-pi" 'vhdl-ieee)
to add it to the VHDL-template keymappings, (so you do C-c C-t C-p i
to insert it). Now I need to figure out how to get it onto the
menu...

Cheers,
Martin
 
H

HS

My apprach is a little different... I have a vhdl file template that is
inserted when I run "Insert header", and it already contains ieee
clauses, entity and architecture pairs, etc.

Cheers,
HS
 
M

Mike Treseler

HS said:
My approach is a little different... I have a vhdl file template that is
inserted when I run "Insert header", and it already contains ieee
clauses, entity and architecture pairs, etc.


Thanks to HS and Martin for the vhdl-mode tips.
Looks like emacs wins round one 3 to nil :)

-- Mike Treseler
 
M

Martin Thompson

Martin Thompson said:
And add this:
(define-key vhdl-template-map "\C-pi" 'vhdl-ieee)
to add it to the VHDL-template keymappings, (so you do C-c C-t C-p i
to insert it).

Doh! What's actually required is this (after Mike's bit):

(add-hook 'vhdl-mode-hook
(lambda()
(define-key vhdl-template-map "\C-pi" 'vhdl-template-package-ieee)))

I'm sure a proper elisper would have a better way of doing it...

Cheers,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top