0

I write Markdown files (*.md) in normal text-mode and again and again use the wrong single-quotation char "´" instead of "`" -- which confuses my markdown processor (note: just the single symbol, without the here depicted double-quotes)

I would like to configure emacs-24 to always highlight this char with a red background. All modes would be ok, but text-mode only is preferred. My active modes are (describe-mode)

Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption Blink-Cursor Column-Number Desktop-Save Diff-Auto-Refine File-Name-Shadow Flyspell Font-Lock Global-Font-Lock Icomplete Line-Number Menu-Bar Mouse-Wheel Shell-Dirtrack Show-Paren Tooltip Transient-Mark

1

Using the following sample answer, please feel free to change the background and foreground colors to whatever you want providing the color exists -- see M-x list-colors-display

NOTE: Many other modes inherit text-mode, and add additional stuff on top of it. For example, the following sample answer works in text-mode, but would also work in latex-mode (which inherits text-mode settings). The easiest solution to avoid inherited settings would be to use a specific mode (other than text-mode) to write your Markdown files and set the font-lock additions for that specific mode. Here is a link to tt-mode which is very helpful to better understand how font-lock works, and you could set up something similar to create your own custom mode for Markdown files. https://github.com/davorg/tt-mode/  I have a feeling, however, that there must already exist special modes for Markdown that you could use and then just change the line of code in the answer to whatever mode you ultimately decide upon -- e.g., http://www.emacswiki.org/emacs/MarkdownMode

(defvar lawlist-super-orange (make-face 'lawlist-super-orange))
(set-face-attribute 'lawlist-super-orange nil :background "white" :foreground "orange" :bold t :underline nil :font "Courier" :height 180)

(defvar lawlist-super-cyan (make-face 'lawlist-super-cyan))
(set-face-attribute 'lawlist-super-cyan nil :background "white" :foreground "cyan" :bold t :underline nil :font "Courier" :height 180)

(add-hook 'text-mode-hook

  (lambda () (font-lock-add-keywords nil (list

    (list (concat "\\(´\\)\\(\\(.\\|\n\\)+?\\)\\(´\\)")
      '(1 lawlist-super-orange t)
      '(2 lawlist-super-cyan t)
      '(4 lawlist-super-orange t))

    (list (concat "lawlist\\|´\\|towi")
      '(0 lawlist-super-orange t)) ))))

Example

  • Thanks for the long explanation. Alas, I don't understand it really -- and it doesn't work. .emacs is loaded without errors, so I seems to have all preconditions fine. But there is one big misunderstanding: I was only talking about a single char, the forward-single-quotation-mark accent-acout. Maybe this simplifies matters? I tried to change the regexp to (list (concat "") '(0 lawlist-super-orange t))`, no luck. – towi Aug 24 '13 at 17:58
  • Without any modifications to the code in this answer: If you type a double quotation mark, is it orange when you are in text mode? And if you type a double quotation and some text and another double quotation, is everything in the middle bright blue? – lawlist Aug 24 '13 at 18:03
  • nope, nothing. No color with any quote char. I put it in .emacs, near the end, and restarted emacs. I also tried it with applying it via marking and eval-region. – towi Aug 24 '13 at 18:05
  • Hmmm ... It works in other modes, like c-mode and latex-mode. Give me a minute to see if I can understand why text-mode doesn't work. If you change the mode to something else (other than text-mode) and set the corresponding mode in the line with (font-lock-add-keywords '... (list, the code in the answer works. – lawlist Aug 24 '13 at 18:15
  • Hrmm... . If i switch on c-mode I hat quote-highlighing -- but only for "quotes", nothing for ` quotes ` or ´ qoutes ´. – towi Aug 24 '13 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.