I'm totally new to the wonderful world of Emacs. I started to use it some weeks ago and i'm find myself to use it more and more... I would like to use it not only as a code editor, but also as a word processor like MS Word, Apple Pages, etc, however, i cant find a practical way to color text, highlight text (like a physical highlighter not like a code editor), and so on. I use M-x highlight-syntax-at-point
and M-x highlight-phrase
but is temporary and anyway, highlights only, e.g. i cant simply make a word or a phrase green. I hope i was clear in my question. Thanks anyway!
2 Answers
If you want to get a well formatted text document, you can use emacs and others packages like LaTeX, ConTeXt, org-mode, or markdown (and pandoc) to get a beautiful and well structured pdf/html/ePub document. Emacs is very efficient for coding any markup language. On the other hand, if you want organizing your notes with syntax highlighting, you can use org-mode or enriched-mode.
To learn several options to work with plain text in emacs, I recommend to read this tutorial http://www.emacs.uniyar.ac.ru/doc/emacs-for-writers.pdf.
It is remarkable that also Elisp files can be saved with the minor mode enriched-mode
enabled.
The formatting information saved by enriched-mode
in the Elisp file works more like an encoding and does not influence the actual Elisp code.
Enriched mode is not appropriate for source files with programming languages that are executed or compiled by external tools.
The following Elisp code works well with the library highlight.el when hlt-use-overlays-flag
is set to non-nil.
If the list of file-local variables contains the variable txt-hlt-overlays
the highlight overlays created by the highlight library are saved in that variable and the variable is updated as file local variable.
Next time the the file is read into a buffer the highlight overlays in txt-hlt-overlays
are reapplied to the buffer.
(require 'highlight)
(defvar-local txt-hlt-overlays nil
"File local variable holding intervals with hlt text props.")
(defun txt-start-hlt-overlays (&optional stop)
"Start saving hlt overlays for the current buffer file.
Stop if STOP is non-nil."
(interactive "P")
(save-excursion
(if stop
(delete-file-local-variable 'txt-hlt-overlays)
(add-file-local-variable 'txt-hlt-overlays nil))))
(defun txt-hlt-overlay-list ()
"Return list of text overlays with non-nil 'hlt-highlight property."
(cl-loop
for ol being the overlays
if (overlay-get ol 'hlt-highlight)
collect (cons (overlay-start ol) (cons (overlay-end ol) (overlay-properties ol)))))
(defun txt-update-hlt-overlays-list ()
"Update file local variable `txt-hlt-overlays'."
(hack-local-variables)
(when (assoc 'txt-hlt-overlays file-local-variables-alist)
(save-excursion
(add-file-local-variable 'txt-hlt-overlays (txt-hlt-overlay-list)))))
(defun txt-apply-hlt-overlays ()
"Apply hlt properties stored in `txt-hlt-overlays'."
(with-silent-modifications
(cl-loop
with ol
for ol-props in txt-hlt-overlays do
(setq ol (make-overlay (nth 0 ol-props) (nth 1 ol-props)))
(cl-loop for ptr on (nthcdr 2 ol-props) by #'cddr do
(overlay-put ol (car ptr) (cadr ptr))))))
(add-hook 'before-save-hook #'txt-update-hlt-overlays-list)
(add-hook 'find-file-hook #'txt-apply-hlt-overlays)
enriched-mode
.