I've been using Emacs org-mode to primarily take lecture notes for university, and I find that it is remarkably useful and I can usually type everything up fairly quickly.
Recently, I've been wanting to use different font colours to make my notes easier for me to follow. I understand that I can type in different font colours by using dot points (Control + Enter
), but I'd like to change the font colour without having to use dot points. For example, if I'm writing a paragraph of text and need to draw attention to a specific sentence within that paragraph, I would prefer to change the font colour of that sentence to do so.
Because I'd be changing font colour quite regularly, the ideal solution would let me change the font colour very quickly in 1 or 2 key presses without having to mouse click through context menus or write any lines of code everytime I want to do so.
After doing research, I have stumbled across this article which pretty much describes what I want to do:
https://shallowsky.com/blog/linux/editors/emacs-rich-text-editing.html
However, I have so far struggled to get it working with my setup. The article contains a piece of code (I've attached the code below) which it says to add to the .emacs file, after which it says to switch to Enriched Mode (both of these I have performed).
The issue is that when I select text in emacs, and attempt to press Control + c
and then r
, nothing happens (no errors or anything).
If I then exit out of Enriched mode, I immediately get the error Key sequence C-c r starts with non-prefix key C-c
.
If I try key presses Control + c
and then r
again in normal org mode, I get the error: C-c r is undefined
.
In terms of troubleshooting, I have used C-x C-s
to save the file then C-x C-v RET
to reload the file and still nothing. I've also tried saving it as both .org
file and .txt
file to see if that made any difference and no such luck.
I am aware of this question Colors with enriched-mode however, this isn't exactly what I'm after. The solution there involves having to write a bunch of code every time I want to colour a piece of text <x-color><param>red</param></x-color>
whereas I would prefer a key binding which can change the font colour quickly.
I'm using Mituharu's Emacs version (aka Railwaycat Homebrew port) on mac OSx
I wouldn't mind a solution in either org mode or enriched mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Text colors/styles. You can use this in conjunction with enriched-mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; rich-style will affect the style of either the selected region,
;; or the current line if no region is selected.
;; style may be an atom indicating a rich-style face,
;; e.g. 'italic or 'bold, using
;; (put-text-property START END PROPERTY VALUE &optional OBJECT)
;; or a color string, e.g. "red", using
;; (facemenu-set-foreground COLOR &optional START END)
;; or nil, in which case style will be removed.
(defun rich-style (style)
(let* ((start (if (use-region-p)
(region-beginning) (line-beginning-position)))
(end (if (use-region-p)
(region-end) (line-end-position))))
(cond
((null style) (set-text-properties start end nil))
((stringp style) (facemenu-set-foreground style start end))
(t (add-text-properties start end (list 'face style)))
)))
(defun enriched-mode-keys ()
(define-key enriched-mode-map "\C-ci"
(lambda () (interactive) (rich-style 'italic)))
(define-key enriched-mode-map "\C-cB"
(lambda () (interactive) (rich-style 'bold)))
(define-key enriched-mode-map "\C-cu"
(lambda () (interactive) (rich-style 'underline)))
(define-key enriched-mode-map "\C-cr"
(lambda () (interactive) (rich-style "red")))
;; Repeat for any other colors you want from rgb.txt
(define-key enriched-mode-map (kbd "C-c ")
(lambda () (interactive) (rich-style nil)))
)
(add-hook 'enriched-mode-hook 'enriched-mode-keys)
org-mode
mark up for such things, i.e./.../
for italic,*...*
for bold etc. You could then change the fontification to add colour to these elements.