1

I am having a problem in cperl-mode described in this question. Basically inserting a newline at the start of a line in here doc in cperl-mode is breaking the syntax highlighting. One of the answers suggested using font-lock-extend-region-functions to extend the font lock region to include all of the here doc. I have done that with the code below and verified it with highlight-refontification. However even though the region is extended, when I insert a newline, the region splits and the syntax highlighting still breaks. My function is shown below

(defun my/cperl-font-lock-extend-region-here ()
  (save-excursion
    (goto-char font-lock-beg)
    (if (re-search-backward "=<<\s*['\"]?[0-9a-zA-Z_]+['\"]?\s*;" nil t)
        (if (string-match "=<<\s*['\"]?\\([0-9a-zA-Z_]+\\)['\"]?\s*;" (thing-at-point 'line t))
            (let ((here-tag (concat "^" (match-string 1 (thing-at-point 'line t)) "$")))
              (beginning-of-line)
              (let ((here-start (point)))
                (goto-char font-lock-end)
                (if (re-search-forward here-tag nil t)
                    (progn
                      (end-of-line)
                      (if (< font-lock-end (point))
                          (setq font-lock-end (point)))))
                (if (> font-lock-beg here-start)
                    (setq font-lock-beg here-start))))))))

My question is, does any smart person know an approach to prevent syntax highlighting from breaking in cperl-mode here docs?

Your Answer

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

Browse other questions tagged or ask your own question.