0

I am working on a project whereby I need to embed Python within a Verilog file. The Python isn't really intended for execution in the normal sense as it will be read by a secondary tool. The Python will be written blocks that have some fixed demarcation (such as #+BEGIN_SRC, in org-babel).

module name ();

#+BEGIN_SRC python
def my_function ():
    ...
#+END_SRC

always @(posedge clk)
    ...
endmodule

Within Emacs this causes havoc, although Python-mode and Verilog-mode work fine, when combining both in the same file things quickly break-down as one would expect. Indentation is hopelessly broken as is syntax-highlighting. I understand this is a very weird thing to do, and I understand that there will almost certainly never been any real need to do this under normal circumstances, however for this particular case it is necessary.

My question: is there anyway within Emacs to specify multiple major modes within the same file. For example, is there some way that I can write a file using Verilog-mode as my major mode, but use Python-mode within the predefined blocks that are then ignored in the reset of the file.

2
  • You are correct, however in this case it is not important that I obey the Verilog syntax because the tool I am creating shall strip such constructs from the final generated Verilog. Commented Apr 23, 2015 at 20:30
  • @StephenHenry, I think the suggestion was that if you do use valid Verilog syntax, Emacs won't be confused anymore. Of course, you won't get any kind of Python-specific functionality for those blocks... Commented Apr 23, 2015 at 20:31

1 Answer 1

1

There are a number of possibilities listed here:

http://emacswiki.org/emacs/MultipleModes

I've used multi-mode with latex and haskell, and it works OK.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Using your suggestion I found polymode seem appears to fit my needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.