[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Font locking in sh-mode stopped working (Emacs 24)

From: Tassilo Horn
Subject: Font locking in sh-mode stopped working (Emacs 24)
Date: Tue, 11 May 2010 09:15:57 +0200
User-agent: KMail/1.13.3 (Linux/2.6.33-gentoo-r2; KDE/4.4.3; x86_64; ; )

Hi all,

since the last time I've updated my emacs bzr checkout (2010-05-07),
font-locking in sh-mode stopped working.  Everything uses the `default'

This doesn't happen with emacs -Q, but I was able to spot the part of my
customization which triggers that behavior.  The offending code adds
support for outline headings in comments to source code files.  I use
that code for years, and it always worked fine.  And even now, it only
stopped working for sh-mode, but it still works for emacs-lisp, java or

Here's the code:

--8<---------------cut here---------------start------------->8---
(defvar th-outline-minor-mode-font-lock-keywords
  '((eval . (list (concat "^\\(?:" outline-regexp "\\).*")
                  0 '(outline-font-lock-face) t t)))
  "Additional expressions to highlight in Orgstruct Mode and Outline minor mode.
The difference to `outline-font-lock-keywords' is that this will
overwrite other highlighting.")

(defun th-outline-regexp ()
  "Calculate the outline regexp for the current mode."
  (let ((comment-starter (replace-regexp-in-string
                          "[[:space:]]+" "" comment-start)))
    (when (string= comment-starter ";")
      (setq comment-starter ";;"))
    (concat comment-starter "[*]+ ")))

(defun th-outline-minor-mode-init ()
  (setq outline-regexp (th-outline-regexp))

(add-hook 'outline-minor-mode-hook

(defvar th-outline-minor-mode-modes
  '(c-mode emacs-lisp-mode lisp-mode ruby-mode haskell-mode
           lua-mode clojure-mode sh-mode))

(defun th-turn-on-outline-minor-mode ()
  (outline-minor-mode 1))

(dolist (mode th-outline-minor-mode-modes)
  (add-hook (intern (concat (symbol-name mode) "-hook")) 
--8<---------------cut here---------------end--------------->8---

Basically, it calculates the `outline-regexp' for a mode by
concatenating the `comment-starter' with one or more *, and all lines
starting with that should be highlighted with `outline-font-lock-face'.

To reproduce the problem, put the code in *scratch* and eval it.  Then
find some shell script, and you'll see that no highlighting is done.

It is important to also evaluate the three last forms, which put the
outline-minor-mode activation inside the mode-hooks.  If I omit these
lines, open a shell script and then activate `outline-minor-mode'
manually, font-locking works normal...

Am I doing anything wrong?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]