1

I've got a font lock config that I use to add certain helpful keywords to various modes of my choosing:

(defun my-font-lock-keywords (mode)
  (font-lock-add-keywords mode
              '(("\\<\\(FIXME\\|TODO\\|QUESTION\\|NOTE\\)"
                 1 font-lock-warning-face t))))

(mapc #'my-font-lock-keywords
      '(prog-mode text-mode message-mode latex-mode html-mode emacs-lisp-mode
          texinfo-mode sql-mode cc-mode c-mode clojure-mode lisp-mode
          c++-mode))

Works great except it matches/highlights lowercase versions of FIXME, TODO, QUESTION, and NOTE too. I only want it to match/highlight upper case versions of those "keywords". How do I need to tweak the regexp to do this?

  • Perhaps it has something to do with case-fold-search? See gnu.org/software/emacs/manual/html_node/elisp/… and gnu.org/software/emacs/manual/html_node/elisp/… – lawlist Jul 10 '16 at 6:38
  • Thanks @lawlist for your response. I didn't know about case-fold-search, or perhaps had forgotten about it. Unfortunately, that didn't make the difference in this situation. I thought that would have been it. Good to know anyway for general case-sensitive searching. – Joe Jul 11 '16 at 17:18
  • There is also font-lock-keywords-case-fold-search, but when set to nil, as mine is, it should do case sensitive search. – Joe Jul 11 '16 at 17:26
  • My recollection is that the default behavior is case-sensitive, which is why your example looks very similar to the one in the comments of font-lock.el. Perhaps you could try a minimal user-configuration with just the code in your question and see if it works as expected. If it works as expected with a near zero/empty user-configuration, then it may be time to recursively bisect by commenting stuff out to find out where the deviation from default behavior is occurring. – lawlist Jul 11 '16 at 17:27
1

This should work

(defun my-font-lock-matcher (limit)
  "Search forward for fixme and todos.
LIMIT is the limit of the search."
  (let ((case-fold-search nil))
    (re-search-forward "\\<\\(FIXME\\|TODO\\|QUESTION\\|NOTE\\)"
                       limit 'no-error)))

(defun my-font-lock-keywords (mode)
  (font-lock-add-keywords mode
                          '((my-font-lock-matcher
                             1 font-lock-warning-face t))))

(mapc #'my-font-lock-keywords
      '(prog-mode text-mode message-mode latex-mode html-mode emacs-lisp-mode
                  texinfo-mode sql-mode cc-mode c-mode clojure-mode lisp-mode
                  c++-mode))
  • To the extent that the original poster is experiencing non-default behavior, this answer should probably be taken in that context -- i.e., it is essentially a "band-aid" to restore default behavior for the duration of the function at issue. – lawlist Jul 11 '16 at 21:06

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.