Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: syntax highlight for non-code files

Let's us suppose I want to create a file (using emacs) to explain something about programming. For example, a mylib-tutorial.txt.

Is there a way to turn on syntax highlight on specific parts of a file containing code?

For example:

Tutorial
---------
This call behaves as follow:

  void foo(&resource);

This call will provoke a huge stack overflow and all of your 
personal files will be permanent lost (a copy to the police
will be sent, though).

Is there is a way to turn on syntax highlight for the code sample? Org-mode perhaps?

like image 353
Peregring-lk Avatar asked May 01 '26 03:05

Peregring-lk


1 Answers

Enable org-src-fontify-natively:

(eval-after-load "org"
  '(setq org-src-fontify-natively t))

And then use org-mode:

* Tutorial

This call behaves as follows:

#+BEGIN_SRC c
  void foo(&resource);
#+END_SRC

This call will provoke a huge stack overflow and all of your 
personal files will be permanent lost (a copy to the police
will be sent, though).

You can also edit the SRC block in c-mode using org-edit-special, bound to C-c ' by default. Use C-c ' again to close the c-mode buffer and update the Org buffer.

like image 68
Chris Avatar answered May 04 '26 02:05

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!