mode with Java syntax highlighting?

I would like to use Emac's org mode for taking notes of java snippets. I would like the java snippets to be syntax highlighted.

I tried running Org-mode in minor mode and Java-mode in major mode, but I found this lacks a lot of Org-Mode features (eg links). I would prefer to run Org-mode in major mode and have some minor mode to do java syntax highlihgting for when it finds java syntax.

I would rather avoid the #+begin_src business as my file would be full of those.

Is this possible?

[Edit] in was thinking along the lines of soft syntax highlighting for none headings and non org-items . Ie general paragraph body?


The only mechanism of which I'm aware that supports syntax-highlighted code blocks in Org-mode is the source code block feature you have already mentioned.

Setting org-src-fontify-natively to t should enable syntax highlighting for such blocks:

(setf org-src-fontify-natively t)

Code blocks should look something like this:

* Pretty sweet Org heading

  This is an org-mode file, which is cool for lots of reasons, e.g.

  - it's Emacs, and
  - it supports syntax-highlighted blocks
    - (note that this requires the variable ~org-src-fontify-natively~
      to be set to ~t~)

#+BEGIN_SRC java
  public class HelloWorld {
      public static void main(String[] args) {
          System.out.println("Hello, World");
      }
  }
#+END_SRC

A few tips:

  • The quickest way to start a new code block is to type <s and then hit Tab. This expands to

    #+BEGIN_SRC |
    
    #+END_SRC
    

    with the cursor represented by | , so you can just type java and start editing.

  • With point inside such a block, org-edit-special , bound to Cc ' by default, will open the code block up in a separate buffer with the appropriate major mode active. You can use the full power of that mode, then type Cc ' again to update the embedded snippet.

  • 链接地址: http://www.djcxy.com/p/30644.html

    上一篇: 复制图片中的链接

    下一篇: Java语法突出显示的模式?