all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Font locking in sh-mode stopped working (Emacs 24)
@ 2010-05-11  7:15 Tassilo Horn
  0 siblings, 0 replies; only message in thread
From: Tassilo Horn @ 2010-05-11  7:15 UTC (permalink / raw)
  To: emacs-devel

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'
face.

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
LaTeX-mode.

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 ()
  (interactive)
  (setq outline-regexp (th-outline-regexp))
  (font-lock-add-keywords
   nil
   th-outline-minor-mode-font-lock-keywords))

(add-hook 'outline-minor-mode-hook
          'th-outline-minor-mode-init)

(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 ()
  (interactive)
  (outline-minor-mode 1))

(dolist (mode th-outline-minor-mode-modes)
  (add-hook (intern (concat (symbol-name mode) "-hook")) 
            'th-turn-on-outline-minor-mode))
--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?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-11  7:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-11  7:15 Font locking in sh-mode stopped working (Emacs 24) Tassilo Horn

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.